[FFmpeg-devel] [PATCH] [RFC] fix 'may be used uninitialized' warnings

Måns Rullgård mans
Mon Feb 2 22:59:49 CET 2009


Aurelien Jacobs <aurel at gnuage.org> writes:

> Diego Biurrun wrote:
>
>> Here is a patch to fix all but one 'may be used initialized' warning
>> in FFmpeg.  Regression tests pass, so this cannot have broken things
>> too badly, but some of it may nonetheless be suspicious.
>> 
>> Please review, I will commit individual hunks as they get approved,
>> not before.
>> 
>> [...]
>> 
>> Index: libavcodec/vp56.c
>> ===================================================================
>> --- libavcodec/vp56.c	(revision 16938)
>> +++ libavcodec/vp56.c	(working copy)
>> @@ -500,7 +500,7 @@
>>      VP56Context *s = avctx->priv_data;
>>      AVFrame *const p = s->framep[VP56_FRAME_CURRENT];
>>      int remaining_buf_size = buf_size;
>> -    int is_alpha, alpha_offset;
>> +    int is_alpha, alpha_offset = 0;
>>  
>>      if (s->has_alpha) {
>>          alpha_offset = bytestream_get_be24(&buf);
>
> Well know false positive.
>
> I did propose a patch some times ago to avoid such warnings without
> adding useless code, but it didn't exactly get a warm welcome.
> It was about adding a macro looking like this (only for compilers
> supporting it):
>
> #define DECLARE_UNINITIALIZED(x)  x = x
>
> int is_alpha, DECLARE_UNINITIALIZED(alpha_offset);

That's IMO worse.  Such code has undefined behaviour according the
standard whereas the original does not (no uninitialised value is
actually used).

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list