diff mbox series

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

Message ID 20201208224041.73947-1-epirat07@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel] avcodec/bitstream: use av_assert0 in GET_DATA | expand

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

Marvin Scholz Dec. 8, 2020, 10:40 p.m. UTC
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(-)

Comments

Paul B Mahol Dec. 9, 2020, 10:24 a.m. UTC | #1
LGTM

On Tue, Dec 8, 2020 at 11:41 PM Marvin Scholz <epirat07@gmail.com> wrote:

> 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)
>
> _______________________________________________
> 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..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);                                      \
     }                                                       \
 }