[FFmpeg-devel] [PATCH] avcodec/bitstream: use av_assert0 in GET_DATA

Marvin Scholz epirat07 at gmail.com
Wed Dec 9 00:40:41 EET 2020


For builds with asserts disabled, if the default case would ever be
reached it could lead to uninitialized use of variables as v is never
assigned to anything.

This caused the following clang warning:

  libavcodec/bitstream.c:374:5: warning: variable 'len' is used
  uninitialized whenever switch default is taken
        [-Wsometimes-uninitialized]
      COPY(len && len <= nb_bits);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  libavcodec/bitstream.c:343:9: note: expanded from macro 'COPY'
          GET_DATA(len, bits, i, bits_wrap, bits_size);
  […]

To prevent the uninitialized use, use av_assert0 which aborts when
assertions are disabled.
---
 libavcodec/bitstream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
index 7570fb2204..875e9302f3 100644
--- a/libavcodec/bitstream.c
+++ b/libavcodec/bitstream.c
@@ -107,7 +107,7 @@ void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
         v = *(const uint32_t *)ptr;                         \
         break;                                              \
     default:                                                \
-        av_assert1(0);                                      \
+        av_assert0(0);                                      \
     }                                                       \
 }
 
-- 
2.24.3 (Apple Git-128)



More information about the ffmpeg-devel mailing list