]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/bitstream: Stop allocating one VLCcode more than needed
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sat, 24 Oct 2020 12:23:38 +0000 (14:23 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Wed, 28 Oct 2020 10:28:24 +0000 (11:28 +0100)
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

index 2a796e0a3eb97a119c5f6018b498b95d1e2439ec..a908c1098042cf5cd3f04d30a8d99f8bfc70c72d 100644 (file)
@@ -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