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

Aurelien Jacobs aurel
Mon Feb 2 23:24:29 CET 2009


M?ns Rullg?rd wrote:

> 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).

That's why I clearly stated "only for compilers supporting it".
DECLARE_UNINITIALIZED should obviously be a no-op for all compilers
which are not explicitly documented to support this.
Maybe Michael made this clearer in his suggestion...

Aurel




More information about the ffmpeg-devel mailing list