[flac-dev] [PATCH] cpu.c: initialize a variable

lvqcl lvqcl.mail at gmail.com
Mon Oct 12 08:38:18 PDT 2015


Erik de Castro Lopo wrote:

>> Some debugging tools don't like if a code uses unitialized variables.
>> The code in cpu.c uses the value of fxsr.buff[50], so it makes sense
>> to explicitely initialize it (because fxsave can fail to do it).
>
> Your change:
>
> 		fxsr.buff[50] = 0;
>
> only changes one element in that 128 work buffer. Why explicitly initialize
> onky the 50th element and not all of them?

The C code that follows:

     ...
     old_val = fxsr.buff[50];
     fxsr.buff[50] ^= 0x0013c0de;
     ...
     fxsr.buff[50] = old_val;
     ...
     new_val = fxsr.buff[50];
     fxsr.buff[50] = old_val;
     ...

uses only fxsr.buff[50], so IMHO it's enough to initialize only the value
of this element.


> My approach would be:
>
>      memset (fxsr.buff, 0, sizeof (fxsr.buff));
>
> What do you think?

It won't hurt but probably superfluous.


More information about the flac-dev mailing list