]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/smacker.c
avcodec/smacker: Don't zero-initialize unnecessarily
[ffmpeg] / libavcodec / smacker.c
index 07fa8887d8612f6263c17502e6fd60691f0d8ada..c249ce7514a8d8253952289599a60d4e374bd063 100644 (file)
@@ -121,7 +121,7 @@ static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t pref
         r = smacker_decode_tree(gb, hc, prefix, length);
         if(r)
             return r;
-        return smacker_decode_tree(gb, hc, prefix | (1 << (length - 1)), length);
+        return smacker_decode_tree(gb, hc, prefix | (1U << (length - 1)), length);
     }
 }
 
@@ -197,14 +197,15 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int
     for (int i = 0; i < 2; i++) {
         h[i].length  = 256;
         h[i].current = 0;
-        h[i].bits    = av_mallocz(256 * sizeof(h[i].bits[0]));
-        h[i].lengths = av_mallocz(256 * sizeof(h[i].lengths[0]));
-        h[i].values  = av_mallocz(256 * sizeof(h[i].values[0]));
+        h[i].bits    = av_malloc(256 * sizeof(h[i].bits[0]));
+        h[i].lengths = av_malloc(256 * sizeof(h[i].lengths[0]));
+        h[i].values  = av_malloc(256 * sizeof(h[i].values[0]));
         if (!h[i].bits || !h[i].lengths || !h[i].values) {
             err = AVERROR(ENOMEM);
             goto error;
         }
         if (!get_bits1(gb)) {
+            h[i].values[0] = 0;
             av_log(smk->avctx, AV_LOG_ERROR, "Skipping %s bytes tree\n",
                    i ? "high" : "low");
             continue;
@@ -214,7 +215,7 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int
             goto error;
         skip_bits1(gb);
         if (h[i].current > 1) {
-            err = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
+            err = init_vlc(&vlc[i], SMKTREE_BITS, h[i].current,
                            INIT_VLC_DEFAULT_SIZES(h[i].lengths),
                            INIT_VLC_DEFAULT_SIZES(h[i].bits),
                            INIT_VLC_LE);
@@ -242,7 +243,7 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int
 
     huff.length = (size + 3) >> 2;
     huff.current = 0;
-    huff.values = av_mallocz_array(huff.length + 3, sizeof(huff.values[0]));
+    huff.values = av_malloc_array(huff.length + 3, sizeof(huff.values[0]));
     if (!huff.values) {
         err = AVERROR(ENOMEM);
         goto error;
@@ -645,26 +646,23 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data,
     for(i = 0; i < (1 << (bits + stereo)); i++) {
         h[i].length = 256;
         h[i].current = 0;
-        h[i].bits = av_mallocz(256 * 4);
-        h[i].lengths = av_mallocz(256 * sizeof(int));
-        h[i].values = av_mallocz(256 * sizeof(int));
+        h[i].bits    = av_malloc(256 * sizeof(h[i].bits));
+        h[i].lengths = av_malloc(256 * sizeof(h[i].lengths));
+        h[i].values  = av_malloc(256 * sizeof(h[i].values));
         if (!h[i].bits || !h[i].lengths || !h[i].values) {
             ret = AVERROR(ENOMEM);
             goto error;
         }
         skip_bits1(&gb);
-        if (smacker_decode_tree(&gb, &h[i], 0, 0) < 0) {
-            ret = AVERROR_INVALIDDATA;
+        if ((ret = smacker_decode_tree(&gb, &h[i], 0, 0)) < 0)
             goto error;
-        }
         skip_bits1(&gb);
         if(h[i].current > 1) {
-            res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
+            ret = init_vlc(&vlc[i], SMKTREE_BITS, h[i].current,
                     h[i].lengths, sizeof(int), sizeof(int),
                     h[i].bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
-            if(res < 0) {
+            if (ret < 0) {
                 av_log(avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
-                ret = AVERROR_INVALIDDATA;
                 goto error;
             }
         }