[vlc-commits] [Git][videolan/vlc][master] bitmapinfoheader: fix uninitialized variable warning

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Jan 10 17:30:38 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
ec735292 by Alexandre Janniaux at 2024-01-10T16:57:50+00:00
bitmapinfoheader: fix uninitialized variable warning

After commit 050c31bfafbd631e9967229ff29caeddd62afe7c, 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 47af51ec5838c721f62affd649530838d238eb2d 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

- - - - -


1 changed file:

- modules/demux/avi/bitmapinfoheader.h


Changes:

=====================================
modules/demux/avi/bitmapinfoheader.h
=====================================
@@ -23,6 +23,8 @@
 #include <vlc_common.h>
 #include <vlc_es.h>
 #include <vlc_codecs.h>
+
+#include <assert.h>
 #include <limits.h>
 
 /* biCompression / Others are FourCC */
@@ -320,8 +322,9 @@ static inline int CreateBitmapInfoHeader( const es_format_t *fmt,
     p_bih->biClrUsed = 0;
     if( biCompression == BI_BITFIELDS )
     {
-        uint32_t i_rmask = 0,i_gmask,i_bmask, i_amask;
-        for( size_t i=0; i<ARRAY_SIZE(bitmap_rgb_masks); i++ )
+        uint32_t i_rmask, i_gmask, i_bmask, i_amask;
+        size_t i=0;
+        for( ; i<ARRAY_SIZE(bitmap_rgb_masks); i++ )
         {
             if ( bitmap_rgb_masks[i].codec == fmt->i_codec )
             {
@@ -332,6 +335,9 @@ static inline int CreateBitmapInfoHeader( const es_format_t *fmt,
                 break;
             }
         }
+        if (i == ARRAY_SIZE(bitmap_rgb_masks))
+            vlc_assert_unreachable();
+
         SetDWLE( &p_bmiColors[0], i_rmask );
         SetDWLE( &p_bmiColors[4], i_gmask );
         SetDWLE( &p_bmiColors[8], i_bmask );



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/ec73529217532efe51ffa08d96cf472104718da9

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/ec73529217532efe51ffa08d96cf472104718da9
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list