This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/2] Add constructor and destructor to thread_info


Pedro Alves <palves@redhat.com> writes:

>>>  - struct target_waitstatus pending_follow;
>>>  + struct target_waitstatus pending_follow {TARGET_WAITKIND_SPURIOUS};
>>>
>> 
>> This will only initialize the first member of union
>> target_waitstatus.value to zero, so some bits of
>> target_waitstatus.value.related_pid is not initialized.
>
> Ah, blah, unions.  Well, the result is that the remaining fields of
> the struct end up list->value->zero-initialized.  Zero-initialization
> for unions means the first member is zero-initialized, and padding
> is initialized to zero.  So I think the end result is the
> same anyway.

It is different from
"memset (&this->pending_follow, 0, sizeof (this->pending_follow))".  The
first member "integer" is zero-initialized, but it is not the largest
member, so part of "related_pid" is not zero-initialized.

  |<------------------ union----------------->|
  |<------- related_pid ------->|<- padding ->|
  |<- integer ->|
  |      0      |<uninitialized>|     0       |

-- 
Yao (齐尧)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]