summaryrefslogtreecommitdiff
path: root/src/lib/openmj2
diff options
context:
space:
mode:
authorStefan Weil <sw@weilnetz.de>2018-10-31 20:44:30 +0100
committerEven Rouault <even.rouault@mines-paris.org>2018-10-31 20:44:30 +0100
commit948332e6ed17565100d1df5f6fdbf66865218e36 (patch)
tree8e38306366e69eef4da8827372d00cf2280ee55c /src/lib/openmj2
parente52909f4c7896c5efff3340d707c12d0df55d3f9 (diff)
Fix some potential overflow issues (#1161)
* Fix some potential overflow issues Put sizeof to the beginning of the multiplication to enforce that size_t instead of smaller integer types is used for the calculation. This fixes warnings from LGTM: Multiplication result may overflow 'unsigned int' before it is converted to 'unsigned long'. It also allows removing some type casts. Signed-off-by: Stefan Weil <sw@weilnetz.de> * Fix code indentation Signed-off-by: Stefan Weil <sw@weilnetz.de>
Diffstat (limited to 'src/lib/openmj2')
-rw-r--r--src/lib/openmj2/j2k.c4
-rw-r--r--src/lib/openmj2/jp2.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/src/lib/openmj2/j2k.c b/src/lib/openmj2/j2k.c
index 85f7b40e..daf13f80 100644
--- a/src/lib/openmj2/j2k.c
+++ b/src/lib/openmj2/j2k.c
@@ -331,7 +331,7 @@ static int j2k_calculate_tp(opj_cp_t *cp, int img_numcomp, opj_image_t *image,
OPJ_ARG_NOT_USED(img_numcomp);
- j2k->cur_totnum_tp = (int *) opj_malloc(cp->tw * cp->th * sizeof(int));
+ j2k->cur_totnum_tp = (int *) opj_malloc(sizeof(int) * cp->tw * cp->th);
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
int cur_totnum_tp = 0;
opj_tcp_t *tcp = &cp->tcps[tileno];
@@ -611,7 +611,7 @@ static void j2k_read_siz(opj_j2k_t *j2k)
opj_event_msg(j2k->cinfo, EVT_ERROR, "Out of memory\n");
return;
}
- cp->tileno = (int*) opj_malloc(cp->tw * cp->th * sizeof(int));
+ cp->tileno = (int*) opj_malloc(sizeof(int) * cp->tw * cp->th);
if (cp->tileno == NULL) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Out of memory\n");
return;
diff --git a/src/lib/openmj2/jp2.c b/src/lib/openmj2/jp2.c
index d2ca41f0..acf64b9a 100644
--- a/src/lib/openmj2/jp2.c
+++ b/src/lib/openmj2/jp2.c
@@ -393,7 +393,7 @@ static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image,
}
/* Palette mapping: */
new_comps[pcol].data = (int*)
- opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(int));
+ opj_malloc(sizeof(int) * old_comps[cmp].w * old_comps[cmp].h);
new_comps[pcol].prec = channel_size[i];
new_comps[pcol].sgnd = channel_sign[i];
}
@@ -461,7 +461,7 @@ static opj_bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio,
nr_channels = (unsigned short)cio_read(cio, 1);/* NPC */
entries = (unsigned int*)
- opj_malloc(nr_channels * nr_entries * sizeof(unsigned int));
+ opj_malloc(sizeof(unsigned int) * nr_channels * nr_entries);
channel_size = (unsigned char*)opj_malloc(nr_channels);
channel_sign = (unsigned char*)opj_malloc(nr_channels);