Blame SOURCES/openjpeg2_coverity.patch

da4962
diff --git a/src/bin/jp2/convertpng.c b/src/bin/jp2/convertpng.c
0591ff
index 00f596e..af3f91e 100644
da4962
--- a/src/bin/jp2/convertpng.c
da4962
+++ b/src/bin/jp2/convertpng.c
da4962
@@ -75,10 +75,10 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
da4962
     png_uint_32  width, height = 0U;
da4962
     int color_type;
da4962
     FILE *reader = NULL;
da4962
-    OPJ_BYTE** rows = NULL;
da4962
-    OPJ_INT32* row32s = NULL;
da4962
+    OPJ_BYTE** volatile rows = NULL;
da4962
+    OPJ_INT32* volatile row32s = NULL;
da4962
     /* j2k: */
da4962
-    opj_image_t *image = NULL;
da4962
+    opj_image_t* volatile image = NULL;
da4962
     opj_image_cmptparm_t cmptparm[4];
da4962
     OPJ_UINT32 nr_comp;
da4962
     OPJ_BYTE sigbuf[8];
da4962
diff --git a/src/bin/jp2/converttif.c b/src/bin/jp2/converttif.c
0591ff
index 9d1037a..8d5002a 100644
da4962
--- a/src/bin/jp2/converttif.c
da4962
+++ b/src/bin/jp2/converttif.c
0591ff
@@ -720,7 +720,7 @@ int imagetotif(opj_image_t * image, const char *outfile)
da4962
         TIFFClose(tif);
da4962
         return 1;
da4962
     }
da4962
-    rowStride = (int64_t)((width * numcomps * bps + 7U) / 8U);
da4962
+    rowStride = ((int64_t)width * numcomps * bps + 7U) / 8U;
da4962
     if (rowStride != strip_size) {
da4962
         fprintf(stderr, "Invalid TIFF strip size\n");
da4962
         TIFFClose(tif);
0591ff
@@ -1283,8 +1283,6 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
da4962
     TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &tiSpp);
da4962
     TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &tiPhoto);
da4962
     TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &tiPC);
da4962
-    w = (int)tiWidth;
da4962
-    h = (int)tiHeight;
da4962
 
da4962
     if (tiSpp == 0 || tiSpp > 4) { /* should be 1 ... 4 */
da4962
         fprintf(stderr, "tiftoimage: Bad value for samples per pixel == %d.\n"
0591ff
@@ -1451,7 +1449,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
da4962
         return NULL;
da4962
     }
da4962
 
da4962
-    rowStride = (int64_t)((tiWidth * tiSpp * tiBps + 7U) / 8U);
da4962
+    rowStride = ((int64_t)tiWidth * tiSpp * tiBps + 7U) / 8U;
da4962
     buffer32s = (OPJ_INT32 *)malloc(sizeof(OPJ_INT32) * tiWidth * tiSpp);
da4962
     if (buffer32s == NULL) {
da4962
         _TIFFfree(buf);
34f489
diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c
34f489
index 8e343ab..c13d229 100644
34f489
--- a/src/lib/openjp2/j2k.c
34f489
+++ b/src/lib/openjp2/j2k.c
34f489
@@ -7075,7 +7075,7 @@ static OPJ_BOOL opj_j2k_is_imf_compliant(opj_cparameters_t *parameters,
34f489
     /* Validate sublevel */
34f489
     assert(sizeof(tabMaxSubLevelFromMainLevel) ==
34f489
            (OPJ_IMF_MAINLEVEL_MAX + 1) * sizeof(tabMaxSubLevelFromMainLevel[0]));
34f489
-    if (sublevel > tabMaxSubLevelFromMainLevel[mainlevel]) {
34f489
+    if (mainlevel <= OPJ_IMF_MAINLEVEL_MAX && sublevel > tabMaxSubLevelFromMainLevel[mainlevel]) {
34f489
         opj_event_msg(p_manager, EVT_WARNING,
34f489
                       "IMF profile require sublevel <= %d for mainlevel = %d.\n"
34f489
                       "-> %d is thus not compliant\n"
0591ff
diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c
0591ff
index 1481e16..d46bfb4 100644
0591ff
--- a/src/lib/openjp2/t2.c
0591ff
+++ b/src/lib/openjp2/t2.c
0591ff
@@ -821,6 +821,7 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno,
0591ff
             opj_event_msg(p_manager, EVT_ERROR,
0591ff
                           "opj_t2_encode_packet(): accessing precno=%u >= %u\n",
0591ff
                           precno, res->pw * res->ph);
0591ff
+            opj_bio_destroy(bio);
0591ff
             return OPJ_FALSE;
0591ff
         }
0591ff