diff mbox series

[FFmpeg-devel,2/2] avcodec/bitstream: Stop allocating one VLCcode more than needed

Message ID 20201024130300.45644-2-andreas.rheinhardt@gmail.com
State Accepted
Commit 81d4b8fb3cdc234d2961b23890aa02d4d29e8842
Headers show
Series [FFmpeg-devel,1/2] avcodec/bitstream: Check code length before truncating to uint8_t
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 Oct. 24, 2020, 1:03 p.m. UTC
Allocating one temporary entry more than needed was made necessary by
the COPY loop below writing an element before having checked that it
should be written at all. But given that this behaviour changed, the
need for overallocating is gone.

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

Patch

diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
index ffa352b28b..39749c6092 100644
--- a/libavcodec/bitstream.c
+++ b/libavcodec/bitstream.c
@@ -281,7 +281,7 @@  int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes,
     vlc = vlc_arg;
     vlc->bits = nb_bits;
     if (flags & INIT_VLC_USE_NEW_STATIC) {
-        av_assert0(nb_codes + 1 <= FF_ARRAY_ELEMS(localbuf));
+        av_assert0(nb_codes <= FF_ARRAY_ELEMS(localbuf));
         localvlc = *vlc_arg;
         vlc = &localvlc;
         vlc->table_size = 0;
@@ -290,8 +290,8 @@  int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes,
         vlc->table_allocated = 0;
         vlc->table_size      = 0;
     }
-    if (nb_codes + 1 > FF_ARRAY_ELEMS(localbuf)) {
-        buf = av_malloc_array((nb_codes + 1), sizeof(VLCcode));
+    if (nb_codes > FF_ARRAY_ELEMS(localbuf)) {
+        buf = av_malloc_array(nb_codes, sizeof(VLCcode));
         if (!buf)
             return AVERROR(ENOMEM);
     } else