Skip to content

bitmapinfoheader: fix uninitialized variable warning

After commit 050c31bf, rmask was used as a sentinel value to initialize the default value of masks.

The check on rmask was removed because the value assigned in that case in commit 47af51ec because the RGB mask was always assigned to 0.

But now, there's nothing guaranteeing that the value are correctly initialized since nothing guarantees that any format will be found. Since BI_BITFIELDS indicate that a mask is required, we can throw an error if the fourcc chroma has no mask defined instead. To ensure that it is correctly signaled in the code for the user and compiler, we also use the iteration variable instead of a sentinel.

Fix the following warnings:

In file included from vlc/modules/demux/avi/avi.c:50:
vlc/modules/demux/avi/bitmapinfoheader.h:324:26: warning: variable 'i_gmask' is used uninitialized whenever 'for' loop exits because its condition is false [-Wsometimes-uninitialized]
        for( size_t i=0; i<ARRAY_SIZE(bitmap_rgb_masks); i++ )
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vlc/modules/demux/avi/bitmapinfoheader.h:336:35: note: uninitialized use occurs here
        SetDWLE( &p_bmiColors[4], i_gmask );
                                  ^~~~~~~
vlc/modules/demux/avi/bitmapinfoheader.h:324:26: note: remove the condition if it is always true
        for( size_t i=0; i<ARRAY_SIZE(bitmap_rgb_masks); i++ )
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vlc/modules/demux/avi/bitmapinfoheader.h:323:37: note: initialize the variable 'i_gmask' to silence this warning
        uint32_t i_rmask = 0,i_gmask,i_bmask, i_amask;
                                    ^
                                     = 0
vlc/modules/demux/avi/bitmapinfoheader.h:324:26: warning: variable 'i_bmask' is used uninitialized whenever 'for' loop exits because its condition is false [-Wsometimes-uninitialized]
        for( size_t i=0; i<ARRAY_SIZE(bitmap_rgb_masks); i++ )
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vlc/modules/demux/avi/bitmapinfoheader.h:337:35: note: uninitialized use occurs here
        SetDWLE( &p_bmiColors[8], i_bmask );
                                  ^~~~~~~
vlc/modules/demux/avi/bitmapinfoheader.h:324:26: note: remove the condition if it is always true
        for( size_t i=0; i<ARRAY_SIZE(bitmap_rgb_masks); i++ )
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vlc/modules/demux/avi/bitmapinfoheader.h:323:45: note: initialize the variable 'i_bmask' to silence this warning
        uint32_t i_rmask = 0,i_gmask,i_bmask, i_amask;
                                            ^
                                             = 0

Merge request reports

Loading