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

Stefan Berger stefanb at linux.vnet.ibm.com
Mon Sep 11 19:40:45 CEST 2017


On 08/29/2017 02:45 PM, Kevin O'Connor wrote:
> On Thu, Aug 10, 2017 at 08:52:06PM +0200, Paul Menzel wrote:
>> Dear SeaBIOS folks,
>>
>>
>> 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.
>
> -Kevin
>
>
> --- 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>





More information about the SeaBIOS mailing list