[PATCH] qmicli, wds: fix uninitialized values in --wds-start-network

Aleksander Morgado aleksander at aleksander.es
Tue Mar 21 19:28:22 UTC 2017


On Tue, Mar 21, 2017 at 7:07 PM, Dan Williams <dcbw at redhat.com> wrote:
>> The 'ip-type' support in --wds-start-network was introduced in commit
>> 81c21379, and that patch lacked a proper initialization of the
>> 'ip_type' field (e.g. as QMI_WDS_IP_FAMILY_UNSPECIFIED) inside the
>> 'props' struct.
>>
>> A follow up commit, 4c678418, tried to fix that by assuming the
>> 'ip_type' field was initialized to 0 instead of
>> QMI_WDS_IP_FAMILY_UNSPECIFIED, which wasn't the case either, as the
>> 'props' struct isn't static and therefore requires explicit
>> initialization of its members.
>
> Can't we do:
>
>     StartNetworkProperties props = { 0 };
>
>     ...
>
>     props.auth    = QMI_WDS_AUTHENTICATION_NONE;
>     props.ip_type = QMI_WDS_IP_FAMILY_UNSPECIFIED;
>
> IIRC that'll zero it out at the compiler level and we don't need the
> memset.

Yeah, that works too. And actually...

"If there are fewer initializers in a brace-enclosed list than there
are elements or members of an aggregate, or fewer characters in a
string literal used to initialize an array of known size than there
are elements in the array, the remainder of the aggregate shall be
initialized implicitly the same as objects that have static storage
duration."

Does this mean that doing this will initialize all the remaining
members to zero? (i.e. same as objects that have static storage
duration)

props = {
  .auth    = QMI_WDS_AUTHENTICATION_NONE,
  .ip_type = QMI_WDS_IP_FAMILY_UNSPECIFIED;
};

If so the original fix was kind of correct as the variable would have
been initialized to zero, although I think a better approach would
have been to initialize the enums to valid enums, right?

-- 
Aleksander
https://aleksander.es


More information about the libqmi-devel mailing list