diff mbox series

[FFmpeg-devel] avcodec/bitstream: Rewrite code to avoid triggering compiler warning

Message ID 20201208231147.1572362-1-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel] avcodec/bitstream: Rewrite code to avoid triggering compiler warning
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Dec. 8, 2020, 11:11 p.m. UTC
Clang infers from the existence of a default case that said case can be
taken. In case of libavcodec/bitstream.c said default case consisted of
an av_assert1 that evaluates to nothing in case of the ordinary assert
level. In this case (that doesn't happen) a variable wouldn't be
initialized, so Clang emitted Wsometimes-uninitialized warnings.
This solves this by checking the assert condition outside of the switch
and removing the default case.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/bitstream.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Paul B Mahol Dec. 9, 2020, 10:25 a.m. UTC | #1
probably fine

On Wed, Dec 9, 2020 at 12:17 AM Andreas Rheinhardt <
andreas.rheinhardt@gmail.com> wrote:

> Clang infers from the existence of a default case that said case can be
> taken. In case of libavcodec/bitstream.c said default case consisted of
> an av_assert1 that evaluates to nothing in case of the ordinary assert
> level. In this case (that doesn't happen) a variable wouldn't be
> initialized, so Clang emitted Wsometimes-uninitialized warnings.
> This solves this by checking the assert condition outside of the switch
> and removing the default case.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/bitstream.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
> index 7570fb2204..9966323a9b 100644
> --- a/libavcodec/bitstream.c
> +++ b/libavcodec/bitstream.c
> @@ -96,6 +96,7 @@ void ff_copy_bits(PutBitContext *pb, const uint8_t *src,
> int length)
>  #define GET_DATA(v, table, i, wrap, size)                   \
>  {                                                           \
>      const uint8_t *ptr = (const uint8_t *)table + i * wrap; \
> +    av_assert1(size == 1 || size == 2 || size == 4);        \
>      switch(size) {                                          \
>      case 1:                                                 \
>          v = *(const uint8_t *)ptr;                          \
> @@ -106,8 +107,6 @@ void ff_copy_bits(PutBitContext *pb, const uint8_t
> *src, int length)
>      case 4:                                                 \
>          v = *(const uint32_t *)ptr;                         \
>          break;                                              \
> -    default:                                                \
> -        av_assert1(0);                                      \
>      }                                                       \
>  }
>
> --
> 2.25.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
index 7570fb2204..9966323a9b 100644
--- a/libavcodec/bitstream.c
+++ b/libavcodec/bitstream.c
@@ -96,6 +96,7 @@  void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
 #define GET_DATA(v, table, i, wrap, size)                   \
 {                                                           \
     const uint8_t *ptr = (const uint8_t *)table + i * wrap; \
+    av_assert1(size == 1 || size == 2 || size == 4);        \
     switch(size) {                                          \
     case 1:                                                 \
         v = *(const uint8_t *)ptr;                          \
@@ -106,8 +107,6 @@  void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
     case 4:                                                 \
         v = *(const uint32_t *)ptr;                         \
         break;                                              \
-    default:                                                \
-        av_assert1(0);                                      \
     }                                                       \
 }