[FFmpeg-devel] [PATCH] work around some 'may be used uninitialized warnings'

Aurelien Jacobs aurel
Thu Mar 5 00:43:02 CET 2009


Benoit Fouet wrote:

> Hi,
> 
> On 03/03/2009 02:28 PM, Diego Biurrun wrote:
> > Here is a patch to work around the 'may be used uninitialized warnings'
> > in libavformat, please review.  I will commit individual parts if OKed,
> > not before.
> >
> > A bunch of these warnings seem to be legitimate.  I initialized these
> > variables to 0, but probably somebody should have a closer look at the
> > code.
> >
> >   
> 
> Index: libavformat/mpeg.c
> ===================================================================
> --- libavformat/mpeg.c	(revision 17759)
> +++ libavformat/mpeg.c	(working copy)
> @@ -413,7 +413,7 @@
>      enum CodecID codec_id = CODEC_ID_NONE;
>      enum CodecType type;
>      int64_t pts, dts, dummy_pos; //dummy_pos is needed for the index building to work
> -    uint8_t dvdaudio_substream_type;
> +    uint8_t av_uninit(dvdaudio_substream_type);
>  
>   redo:
>      len = mpegps_read_pes_header(s, &dummy_pos, &startcode, &pts, &dts);

dvdaudio_substream_type indeed can't be used uninitialized, so this
hunk looks OK.

> > Index: libavformat/rmdec.c
> > ===================================================================
> > --- libavformat/rmdec.c    (revision 17759)
> > +++ libavformat/rmdec.c    (working copy)
> > @@ -482,7 +482,7 @@
> >                                     RMDemuxContext *rm, RMStream *vst,
> >                                     AVPacket *pkt, int len)
> >  {
> > -    int hdr, seq, pic_num, len2, pos;
> > +    int hdr, seq=0, pic_num=0, len2=0, av_uninit(pos);
> >      int type;
> > 
> >      hdr = get_byte(pb); len--;
> >
> 
> from what I read, they should all be av_uninit, no initialization is
> needed, as type can only be 0, 1, 2 or 3.

That's right. Anyway, gcc-4.3 is able to detect this and don't generate
warning here, so no change needed.

> > Index: libavformat/utils.c
> > ===================================================================
> > --- libavformat/utils.c    (revision 17759)
> > +++ libavformat/utils.c    (working copy)
> > @@ -1289,7 +1289,7 @@
> > 
> >  int av_seek_frame_binary(AVFormatContext *s, int stream_index,
> int64_t target_ts, int flags){
> >      AVInputFormat *avif= s->iformat;
> > -    int64_t pos_min, pos_max, pos, pos_limit;
> > +    int64_t pos_min=0, pos_max=0, pos, pos_limit;
> >      int64_t ts_min, ts_max, ts;
> >      int index;
> >      AVStream *st;
> >
> 
> I had a look at this one once, and it appears that they are not used
> uninitialized, if you know how av_gen_search() works

That's right. pos_min and pos_max can't be used uninitialized with
current code, so initializing them to 0 is not OK.

Aurel




More information about the ffmpeg-devel mailing list