[FFmpeg-devel] [PATCH] [RFC] fix 'may be used uninitialized' warnings
Michael Niedermayer
michaelni
Mon Feb 2 12:49:43 CET 2009
On Mon, Feb 02, 2009 at 11:43:16AM +0100, 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.
>
> Diego
> Index: libavcodec/lpc.c
> ===================================================================
> --- libavcodec/lpc.c (revision 16938)
> +++ libavcodec/lpc.c (working copy)
> @@ -118,7 +118,7 @@
> ref[i] = fabs(lpc[i][i]);
> }else{
> LLSModel m[2];
> - double var[MAX_LPC_ORDER+1], weight;
> + double var[MAX_LPC_ORDER+1], weight = 0;
>
> for(pass=0; pass<use_lpc-1; pass++){
> av_init_lls(&m[pass&1], max_order);
the next line is weight=0;
and use_lpc<1 makes no sense in lpc code i guess
so this warning is a false positive and some kind of check for use_lpc
being within the valid range might be a good idea. An assert() should do
as this is internal API
> Index: libavcodec/motion_est.c
> ===================================================================
> --- libavcodec/motion_est.c (revision 16938)
> +++ libavcodec/motion_est.c (working copy)
> @@ -536,7 +536,7 @@
> const int size= 1;
> const int h=8;
> int block;
> - int P[10][2];
> + int P[10][2] = {0, 0};
> int dmin_sum=0, mx4_sum=0, my4_sum=0;
> int same=1;
> const int stride= c->stride;
> @@ -686,7 +686,7 @@
> const int size=0;
> const int h=8;
> int block;
> - int P[10][2];
> + int P[10][2] = {0, 0};
> uint8_t * const mv_penalty= c->current_mv_penalty;
> int same=1;
> const int stride= 2*s->linesize;
P[10][2] occurs 6 times, why is gcc complaining just about these 2
?
besides this code is somewhat speed relevant so setting them to 0
just to silence a warning isnt such a good idea
> Index: libavcodec/h263.c
> ===================================================================
> --- libavcodec/h263.c (revision 16938)
> +++ libavcodec/h263.c (working copy)
> @@ -4730,7 +4730,7 @@
> int n, int coded, int intra, int rvlc)
> {
> int level, i, last, run;
> - int dc_pred_dir;
> + int dc_pred_dir = 0;
> RLTable * rl;
> RL_VLC_ELEM * rl_vlc;
> const uint8_t * scan_table;
mpeg4_decode_block() is speed relevant as well so again the code is not ok
also it would help me review if you could add -p to the switches so that the
function names are vissble
> Index: libavcodec/msmpeg4.c
> ===================================================================
> --- libavcodec/msmpeg4.c (revision 16938)
> +++ libavcodec/msmpeg4.c (working copy)
> @@ -774,7 +774,7 @@
> static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
> {
> int sign, code;
> - int pred, extquant;
> + int pred, extquant = 0;
> int extrabits = 0;
>
> if(s->msmpeg4_version==1){
> @@ -1609,7 +1609,7 @@
> int n, int coded, const uint8_t *scan_table)
> {
> int level, i, last, run, run_diff;
> - int dc_pred_dir;
> + int dc_pred_dir = 0;
> RLTable *rl;
> RL_VLC_ELEM *rl_vlc;
> int qmul, qadd;
same (speed relevant)
> Index: libavcodec/vp56.c
[...]
> Index: libavcodec/flacdec.c
[...]
not maintained by me
[...]
> Index: libavcodec/eatgv.c
> ===================================================================
> --- libavcodec/eatgv.c (revision 16938)
> +++ libavcodec/eatgv.c (working copy)
> @@ -63,7 +63,7 @@
> */
> static int unpack(const uint8_t *src, const uint8_t *src_end, unsigned char *dst, int width, int height) {
> unsigned char *dst_end = dst + width*height;
> - int size,size1,size2,offset,run;
> + int size, size1, size2, offset = 0, run;
> unsigned char *dst_start = dst;
>
> if (src[0] & 0x01)
very obviously false positive, it can never be read without prior init
> Index: libavcodec/bfi.c
> ===================================================================
> --- libavcodec/bfi.c (revision 16938)
> +++ libavcodec/bfi.c (working copy)
> @@ -94,7 +95,7 @@
>
> while (dst != frame_end) {
> static const uint8_t lentab[4]={0,2,0,1};
> - unsigned int byte = *buf++, offset;
> + unsigned int byte = *buf++, offset = 0;
> unsigned int code = byte >> 6;
> unsigned int length = byte & ~0xC0;
obviously false positive
>
> Index: libavcodec/qtrleenc.c
> ===================================================================
> --- libavcodec/qtrleenc.c (revision 16938)
> +++ libavcodec/qtrleenc.c (working copy)
> @@ -110,13 +110,13 @@
> signed char rlecode;
>
> /* We will use it to compute the best bulk copy sequence */
> - unsigned int bulkcount;
> + unsigned int bulkcount = 0;
> /* This will be the number of pixels equal to the preivous frame one's
> * starting from the ith pixel */
> unsigned int skipcount;
likely false positive
> /* This will be the number of consecutive equal pixels in the current
> * frame, starting from the ith one also */
> - unsigned int repeatcount;
> + unsigned int repeatcount = 0;
>
> /* The cost of the three different possibilities */
> int total_bulk_cost;
false positive
> Index: libavcodec/bmp.c
> ===================================================================
> --- libavcodec/bmp.c (revision 16938)
> +++ libavcodec/bmp.c (working copy)
> @@ -46,7 +46,7 @@
> BiCompression comp;
> unsigned int ihsize;
> int i, j, n, linesize;
> - uint32_t rgb[3];
> + uint32_t rgb[3] = {0, 0, 0};
> uint8_t *ptr;
> int dsize;
> const uint8_t *buf0 = buf;
false positive
> Index: libavcodec/msrledec.c
> ===================================================================
> --- libavcodec/msrledec.c (revision 16938)
> +++ libavcodec/msrledec.c (working copy)
> @@ -135,8 +135,8 @@
> uint8_t *output, *output_end;
> const uint8_t* src = data;
> int p1, p2, line=avctx->height, pos=0, i;
> - uint16_t pix16;
> - uint32_t pix32;
> + uint16_t pix16 = 0;
> + uint32_t pix32 = 0;
>
> output = pic->data[0] + (avctx->height - 1) * pic->linesize[0];
> output_end = pic->data[0] + (avctx->height) * pic->linesize[0];
> @@ -196,7 +196,7 @@
> }
> pos += p2;
> } else { //Run of pixels
> - uint8_t pix[3]; //original pixel
> + uint8_t pix[3] = {0, 0, 0}; //original pixel
> switch(depth){
> case 8: pix[0] = *src++;
> break;
false positive
> Index: libavcodec/huffyuv.c
> ===================================================================
> --- libavcodec/huffyuv.c (revision 16938)
> +++ libavcodec/huffyuv.c (working copy)
> @@ -1004,7 +1004,7 @@
> if(s->bitstream_bpp<24){
> int y, cy;
> int lefty, leftu, leftv;
> - int lefttopy, lefttopu, lefttopv;
> + int lefttopy, lefttopu = 0, lefttopv = 0;
>
> if(s->yuy2){
> p->data[0][3]= get_bits(&s->gb, 8);
same
> Index: libavformat/electronicarts.c
> ===================================================================
> --- libavformat/electronicarts.c (revision 16938)
> +++ libavformat/electronicarts.c (working copy)
> @@ -439,7 +439,7 @@
> int packet_read = 0;
> unsigned int chunk_type, chunk_size;
> int key = 0;
> - int num_samples;
> + int num_samples = 0;
>
> while (!packet_read) {
> chunk_type = get_le32(pb);
s.
> Index: libavformat/matroskadec.c
not maintained by me (not that all the others i reviewd where)
[...]
> Index: libavformat/utils.c
> ===================================================================
> --- libavformat/utils.c (revision 16938)
> +++ libavformat/utils.c (working copy)
> @@ -1265,7 +1265,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;
this too looks like a false positive, though i must say it isnt exactly pretty
but then setting these to 0 isnt making it prettier
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090202/c7cf8409/attachment.pgp>
More information about the ffmpeg-devel
mailing list