[SeaBIOS] GCC 7.1 warning in `tcgbios.c`: `'hleo.eventnumber' may be used uninitialized in this function`

Paul Menzel pmenzel at molgen.mpg.de
Thu Oct 12 13:08:45 CEST 2017


Dear Kevin,


On 09/14/17 21:45, Kevin O'Connor wrote:
> On Mon, Sep 11, 2017 at 01:40:45PM -0400, Stefan Berger wrote:
>> On 08/29/2017 02:45 PM, Kevin O'Connor wrote:
>>> On Thu, Aug 10, 2017 at 08:52:06PM +0200, Paul Menzel wrote:

>>>> GCC 7.1 warns about a maybe uninitialized struct member.
>>>>
>>>> ```
>>>> src/tcgbios.c: In function 'tpm_interrupt_handler32':
>>>> src/tcgbios.c:1232:30: warning: 'hleo.eventnumber' may be used uninitialized
>>>> in this function [-Wmaybe-uninitialized]
>>>>        hleeo->eventnumber = hleo.eventnumber;
>>>>                             ~~~~^~~~~~~~~~~~
>>>>     Compiling whole program out/ccode32flat.o
>>>> In file included from out/ccode32flat.o.tmp.c:52:0:
>>>> ./src/tcgbios.c: In function 'tpm_interrupt_handler32':
>>>> ./src/tcgbios.c:1232:30: warning: 'hleo.eventnumber' may be used
>>>> uninitialized in this function [-Wmaybe-uninitialized]
>>>>        hleeo->eventnumber = hleo.eventnumber;
>>>>                             ~~~~^~~~~~~~~~~~
>>>> ```
>>>>
>>>> It looks valid, as in the beginning the struct hleo is only declared.
>>>>
>>>> ```
>>>> 1189     struct hleo hleo;
>>>> ```
>>>>
>>> Agreed - the warning does look valid.  I think the patch below should
>>> fix it.

>>> --- a/src/tcgbios.c
>>> +++ b/src/tcgbios.c
>>> @@ -1186,7 +1186,6 @@ hash_log_extend_event_int(const struct hleei_short *hleei_s,
>>>                              struct hleeo *hleeo)
>>>    {
>>>        u32 rc = 0;
>>> -    struct hleo hleo;
>>>        struct hleei_long *hleei_l = (struct hleei_long *)hleei_s;
>>>        const void *logdataptr;
>>>        u32 logdatalen;
>>> @@ -1229,7 +1228,7 @@ hash_log_extend_event_int(const struct hleei_short *hleei_s,
>>>
>>>        hleeo->opblength = sizeof(struct hleeo);
>>>        hleeo->reserved  = 0;
>>> -    hleeo->eventnumber = hleo.eventnumber;
>>> +    hleeo->eventnumber = tpm_state.entry_count;
>>>        memcpy(hleeo->digest, pcpes->digest, sizeof(hleeo->digest));
>>>
>>>    err_exit:
>>>
>>
>> Review-by: Stefan Berger <stefanb at linux.vnet.ibm.com>

Review*ed*.

> Thanks - I committed this patch.

Could you please cherry-pick that commit 
1ef72ab2f89ae61dcdb3f01323bd0a7dc978c2b9 to the stable branch 
*origin/1.10-stable*?


Kind regards,

Paul



More information about the SeaBIOS mailing list