jpeg2000: Fix compute precedence error in lut_gain index
[ffmpeg.git] / libavcodec / jpeg2000.c
index 705399ab0c110716e3c086b25e30c3c012f89546..b1236993ac207d2d267ab3b48c83b6b2811e0932 100644 (file)
@@ -115,7 +115,6 @@ static int getsigctxno(int flag, int bandno)
             return 2;
         if (d == 1)
             return 1;
-        return 0;
     } else {
         if (d >= 3)
             return 8;
@@ -135,7 +134,6 @@ static int getsigctxno(int flag, int bandno)
             return 2;
         if (h + v == 1)
             return 1;
-        return 0;
     }
     return 0;
 }
@@ -206,6 +204,11 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
     int reslevelno, bandno, gbandno = 0, ret, i, j;
     uint32_t csize = 1;
 
+    if (!codsty->nreslevels2decode) {
+        av_log(avctx, AV_LOG_ERROR, "nreslevels2decode uninitialized\n");
+        return AVERROR_INVALIDDATA;
+    }
+
     if (ret = ff_jpeg2000_dwt_init(&comp->dwt, comp->coord,
                                    codsty->nreslevels2decode - 1,
                                    codsty->transform))
@@ -282,7 +285,7 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
             case JPEG2000_QSTY_NONE:
                 /* TODO: to verify. No quantization in this case */
                 numbps = cbps +
-                         lut_gain[codsty->transform][bandno + reslevelno > 0];
+                         lut_gain[codsty->transform][bandno + (reslevelno > 0)];
                 band->stepsize = (float)SHL(2048 + qntsty->mant[gbandno],
                                             2 + numbps - qntsty->expn[gbandno]);
                 break;
@@ -413,9 +416,9 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
                 if (!prec->zerobits)
                     return AVERROR(ENOMEM);
 
-                prec->cblk = av_malloc_array(prec->nb_codeblocks_width *
-                                             prec->nb_codeblocks_height,
-                                             sizeof(*prec->cblk));
+                prec->cblk = av_mallocz_array(prec->nb_codeblocks_width *
+                                              prec->nb_codeblocks_height,
+                                              sizeof(*prec->cblk));
                 if (!prec->cblk)
                     return AVERROR(ENOMEM);
                 for (cblkno = 0; cblkno < prec->nb_codeblocks_width * prec->nb_codeblocks_height; cblkno++) {