Blame SOURCES/openjpeg2_coverity.patch

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