Line
Link Here
|
0 |
-- src/libjasper/base/jas_cm.c |
0 |
++ src/libjasper/base/jas_cm.c |
Lines 704-711
Link Here
|
704 |
{ |
704 |
{ |
705 |
jas_cmpxform_t **p; |
705 |
jas_cmpxform_t **p; |
706 |
assert(n >= pxformseq->numpxforms); |
706 |
assert(n >= pxformseq->numpxforms); |
707 |
p = (!pxformseq->pxforms) ? jas_malloc(n * sizeof(jas_cmpxform_t *)) : |
707 |
p = jas_realloc2(pxformseq->pxforms, n, sizeof(jas_cmpxform_t *)); |
708 |
jas_realloc(pxformseq->pxforms, n * sizeof(jas_cmpxform_t *)); |
|
|
709 |
if (!p) { |
708 |
if (!p) { |
710 |
return -1; |
709 |
return -1; |
711 |
} |
710 |
} |
Lines 889-901
Link Here
|
889 |
jas_cmshapmatlut_cleanup(lut); |
888 |
jas_cmshapmatlut_cleanup(lut); |
890 |
if (curv->numents == 0) { |
889 |
if (curv->numents == 0) { |
891 |
lut->size = 2; |
890 |
lut->size = 2; |
892 |
if (!(lut->data = jas_malloc(lut->size * sizeof(jas_cmreal_t)))) |
891 |
if (!(lut->data = jas_alloc2(lut->size, sizeof(jas_cmreal_t)))) |
893 |
goto error; |
892 |
goto error; |
894 |
lut->data[0] = 0.0; |
893 |
lut->data[0] = 0.0; |
895 |
lut->data[1] = 1.0; |
894 |
lut->data[1] = 1.0; |
896 |
} else if (curv->numents == 1) { |
895 |
} else if (curv->numents == 1) { |
897 |
lut->size = 256; |
896 |
lut->size = 256; |
898 |
if (!(lut->data = jas_malloc(lut->size * sizeof(jas_cmreal_t)))) |
897 |
if (!(lut->data = jas_alloc2(lut->size, sizeof(jas_cmreal_t)))) |
899 |
goto error; |
898 |
goto error; |
900 |
gamma = curv->ents[0] / 256.0; |
899 |
gamma = curv->ents[0] / 256.0; |
901 |
for (i = 0; i < lut->size; ++i) { |
900 |
for (i = 0; i < lut->size; ++i) { |
Lines 903-909
Link Here
|
903 |
} |
902 |
} |
904 |
} else { |
903 |
} else { |
905 |
lut->size = curv->numents; |
904 |
lut->size = curv->numents; |
906 |
if (!(lut->data = jas_malloc(lut->size * sizeof(jas_cmreal_t)))) |
905 |
if (!(lut->data = jas_alloc2(lut->size, sizeof(jas_cmreal_t)))) |
907 |
goto error; |
906 |
goto error; |
908 |
for (i = 0; i < lut->size; ++i) { |
907 |
for (i = 0; i < lut->size; ++i) { |
909 |
lut->data[i] = curv->ents[i] / 65535.0; |
908 |
lut->data[i] = curv->ents[i] / 65535.0; |
Lines 953-959
Link Here
|
953 |
return -1; |
952 |
return -1; |
954 |
} |
953 |
} |
955 |
} |
954 |
} |
956 |
if (!(invlut->data = jas_malloc(n * sizeof(jas_cmreal_t)))) |
955 |
if (!(invlut->data = jas_alloc2(n, sizeof(jas_cmreal_t)))) |
957 |
return -1; |
956 |
return -1; |
958 |
invlut->size = n; |
957 |
invlut->size = n; |
959 |
for (i = 0; i < invlut->size; ++i) { |
958 |
for (i = 0; i < invlut->size; ++i) { |
960 |
-- src/libjasper/base/jas_icc.c |
959 |
++ src/libjasper/base/jas_icc.c |
Lines 373-379
Link Here
|
373 |
jas_icctagtab_t *tagtab; |
373 |
jas_icctagtab_t *tagtab; |
374 |
|
374 |
|
375 |
tagtab = &prof->tagtab; |
375 |
tagtab = &prof->tagtab; |
376 |
if (!(tagtab->ents = jas_malloc(prof->attrtab->numattrs * |
376 |
if (!(tagtab->ents = jas_alloc2(prof->attrtab->numattrs, |
377 |
sizeof(jas_icctagtabent_t)))) |
377 |
sizeof(jas_icctagtabent_t)))) |
378 |
goto error; |
378 |
goto error; |
379 |
tagtab->numents = prof->attrtab->numattrs; |
379 |
tagtab->numents = prof->attrtab->numattrs; |
Lines 522-528
Link Here
|
522 |
} |
522 |
} |
523 |
if (jas_iccgetuint32(in, &tagtab->numents)) |
523 |
if (jas_iccgetuint32(in, &tagtab->numents)) |
524 |
goto error; |
524 |
goto error; |
525 |
if (!(tagtab->ents = jas_malloc(tagtab->numents * |
525 |
if (!(tagtab->ents = jas_alloc2(tagtab->numents, |
526 |
sizeof(jas_icctagtabent_t)))) |
526 |
sizeof(jas_icctagtabent_t)))) |
527 |
goto error; |
527 |
goto error; |
528 |
tagtabent = tagtab->ents; |
528 |
tagtabent = tagtab->ents; |
Lines 743-750
Link Here
|
743 |
{ |
743 |
{ |
744 |
jas_iccattr_t *newattrs; |
744 |
jas_iccattr_t *newattrs; |
745 |
assert(maxents >= tab->numattrs); |
745 |
assert(maxents >= tab->numattrs); |
746 |
newattrs = tab->attrs ? jas_realloc(tab->attrs, maxents * |
746 |
newattrs = jas_realloc2(tab->attrs, maxents, sizeof(jas_iccattr_t)); |
747 |
sizeof(jas_iccattr_t)) : jas_malloc(maxents * sizeof(jas_iccattr_t)); |
|
|
748 |
if (!newattrs) |
747 |
if (!newattrs) |
749 |
return -1; |
748 |
return -1; |
750 |
tab->attrs = newattrs; |
749 |
tab->attrs = newattrs; |
Lines 999-1005
Link Here
|
999 |
|
998 |
|
1000 |
if (jas_iccgetuint32(in, &curv->numents)) |
999 |
if (jas_iccgetuint32(in, &curv->numents)) |
1001 |
goto error; |
1000 |
goto error; |
1002 |
if (!(curv->ents = jas_malloc(curv->numents * sizeof(jas_iccuint16_t)))) |
1001 |
if (!(curv->ents = jas_alloc2(curv->numents, sizeof(jas_iccuint16_t)))) |
1003 |
goto error; |
1002 |
goto error; |
1004 |
for (i = 0; i < curv->numents; ++i) { |
1003 |
for (i = 0; i < curv->numents; ++i) { |
1005 |
if (jas_iccgetuint16(in, &curv->ents[i])) |
1004 |
if (jas_iccgetuint16(in, &curv->ents[i])) |
Lines 1100-1106
Link Here
|
1100 |
if (jas_iccgetuint32(in, &txtdesc->uclangcode) || |
1099 |
if (jas_iccgetuint32(in, &txtdesc->uclangcode) || |
1101 |
jas_iccgetuint32(in, &txtdesc->uclen)) |
1100 |
jas_iccgetuint32(in, &txtdesc->uclen)) |
1102 |
goto error; |
1101 |
goto error; |
1103 |
if (!(txtdesc->ucdata = jas_malloc(txtdesc->uclen * 2))) |
1102 |
if (!(txtdesc->ucdata = jas_alloc2(txtdesc->uclen, 2))) |
1104 |
goto error; |
1103 |
goto error; |
1105 |
if (jas_stream_read(in, txtdesc->ucdata, txtdesc->uclen * 2) != |
1104 |
if (jas_stream_read(in, txtdesc->ucdata, txtdesc->uclen * 2) != |
1106 |
JAS_CAST(int, txtdesc->uclen * 2)) |
1105 |
JAS_CAST(int, txtdesc->uclen * 2)) |
Lines 1292-1308
Link Here
|
1292 |
jas_iccgetuint16(in, &lut8->numouttabents)) |
1291 |
jas_iccgetuint16(in, &lut8->numouttabents)) |
1293 |
goto error; |
1292 |
goto error; |
1294 |
clutsize = jas_iccpowi(lut8->clutlen, lut8->numinchans) * lut8->numoutchans; |
1293 |
clutsize = jas_iccpowi(lut8->clutlen, lut8->numinchans) * lut8->numoutchans; |
1295 |
if (!(lut8->clut = jas_malloc(clutsize * sizeof(jas_iccuint8_t))) || |
1294 |
if (!(lut8->clut = jas_alloc2(clutsize, sizeof(jas_iccuint8_t))) || |
1296 |
!(lut8->intabsbuf = jas_malloc(lut8->numinchans * |
1295 |
!(lut8->intabsbuf = jas_alloc3(lut8->numinchans, |
1297 |
lut8->numintabents * sizeof(jas_iccuint8_t))) || |
1296 |
lut8->numintabents, sizeof(jas_iccuint8_t))) || |
1298 |
!(lut8->intabs = jas_malloc(lut8->numinchans * |
1297 |
!(lut8->intabs = jas_alloc2(lut8->numinchans, |
1299 |
sizeof(jas_iccuint8_t *)))) |
1298 |
sizeof(jas_iccuint8_t *)))) |
1300 |
goto error; |
1299 |
goto error; |
1301 |
for (i = 0; i < lut8->numinchans; ++i) |
1300 |
for (i = 0; i < lut8->numinchans; ++i) |
1302 |
lut8->intabs[i] = &lut8->intabsbuf[i * lut8->numintabents]; |
1301 |
lut8->intabs[i] = &lut8->intabsbuf[i * lut8->numintabents]; |
1303 |
if (!(lut8->outtabsbuf = jas_malloc(lut8->numoutchans * |
1302 |
if (!(lut8->outtabsbuf = jas_alloc3(lut8->numoutchans, |
1304 |
lut8->numouttabents * sizeof(jas_iccuint8_t))) || |
1303 |
lut8->numouttabents, sizeof(jas_iccuint8_t))) || |
1305 |
!(lut8->outtabs = jas_malloc(lut8->numoutchans * |
1304 |
!(lut8->outtabs = jas_alloc2(lut8->numoutchans, |
1306 |
sizeof(jas_iccuint8_t *)))) |
1305 |
sizeof(jas_iccuint8_t *)))) |
1307 |
goto error; |
1306 |
goto error; |
1308 |
for (i = 0; i < lut8->numoutchans; ++i) |
1307 |
for (i = 0; i < lut8->numoutchans; ++i) |
Lines 1461-1477
Link Here
|
1461 |
jas_iccgetuint16(in, &lut16->numouttabents)) |
1460 |
jas_iccgetuint16(in, &lut16->numouttabents)) |
1462 |
goto error; |
1461 |
goto error; |
1463 |
clutsize = jas_iccpowi(lut16->clutlen, lut16->numinchans) * lut16->numoutchans; |
1462 |
clutsize = jas_iccpowi(lut16->clutlen, lut16->numinchans) * lut16->numoutchans; |
1464 |
if (!(lut16->clut = jas_malloc(clutsize * sizeof(jas_iccuint16_t))) || |
1463 |
if (!(lut16->clut = jas_alloc2(clutsize, sizeof(jas_iccuint16_t))) || |
1465 |
!(lut16->intabsbuf = jas_malloc(lut16->numinchans * |
1464 |
!(lut16->intabsbuf = jas_malloc(lut16->numinchans * |
1466 |
lut16->numintabents * sizeof(jas_iccuint16_t))) || |
1465 |
lut16->numintabents * sizeof(jas_iccuint16_t))) || |
1467 |
!(lut16->intabs = jas_malloc(lut16->numinchans * |
1466 |
!(lut16->intabs = jas_alloc2(lut16->numinchans, |
1468 |
sizeof(jas_iccuint16_t *)))) |
1467 |
sizeof(jas_iccuint16_t *)))) |
1469 |
goto error; |
1468 |
goto error; |
1470 |
for (i = 0; i < lut16->numinchans; ++i) |
1469 |
for (i = 0; i < lut16->numinchans; ++i) |
1471 |
lut16->intabs[i] = &lut16->intabsbuf[i * lut16->numintabents]; |
1470 |
lut16->intabs[i] = &lut16->intabsbuf[i * lut16->numintabents]; |
1472 |
if (!(lut16->outtabsbuf = jas_malloc(lut16->numoutchans * |
1471 |
if (!(lut16->outtabsbuf = jas_alloc3(lut16->numoutchans, |
1473 |
lut16->numouttabents * sizeof(jas_iccuint16_t))) || |
1472 |
lut16->numouttabents, sizeof(jas_iccuint16_t))) || |
1474 |
!(lut16->outtabs = jas_malloc(lut16->numoutchans * |
1473 |
!(lut16->outtabs = jas_alloc2(lut16->numoutchans, |
1475 |
sizeof(jas_iccuint16_t *)))) |
1474 |
sizeof(jas_iccuint16_t *)))) |
1476 |
goto error; |
1475 |
goto error; |
1477 |
for (i = 0; i < lut16->numoutchans; ++i) |
1476 |
for (i = 0; i < lut16->numoutchans; ++i) |
1478 |
-- src/libjasper/base/jas_image.c |
1477 |
++ src/libjasper/base/jas_image.c |
Lines 142-148
Link Here
|
142 |
image->inmem_ = true; |
142 |
image->inmem_ = true; |
143 |
|
143 |
|
144 |
/* Allocate memory for the per-component information. */ |
144 |
/* Allocate memory for the per-component information. */ |
145 |
if (!(image->cmpts_ = jas_malloc(image->maxcmpts_ * |
145 |
if (!(image->cmpts_ = jas_alloc2(image->maxcmpts_, |
146 |
sizeof(jas_image_cmpt_t *)))) { |
146 |
sizeof(jas_image_cmpt_t *)))) { |
147 |
jas_image_destroy(image); |
147 |
jas_image_destroy(image); |
148 |
return 0; |
148 |
return 0; |
Lines 774-781
Link Here
|
774 |
jas_image_cmpt_t **newcmpts; |
774 |
jas_image_cmpt_t **newcmpts; |
775 |
int cmptno; |
775 |
int cmptno; |
776 |
|
776 |
|
777 |
newcmpts = (!image->cmpts_) ? jas_malloc(maxcmpts * sizeof(jas_image_cmpt_t *)) : |
777 |
newcmpts = jas_realloc2(image->cmpts_, maxcmpts, sizeof(jas_image_cmpt_t *)); |
778 |
jas_realloc(image->cmpts_, maxcmpts * sizeof(jas_image_cmpt_t *)); |
|
|
779 |
if (!newcmpts) { |
778 |
if (!newcmpts) { |
780 |
return -1; |
779 |
return -1; |
781 |
} |
780 |
} |
782 |
-- src/libjasper/base/jas_malloc.c |
781 |
++ src/libjasper/base/jas_malloc.c |
Lines 76-81
Link Here
|
76 |
|
76 |
|
77 |
/* We need the prototype for memset. */ |
77 |
/* We need the prototype for memset. */ |
78 |
#include <string.h> |
78 |
#include <string.h> |
|
|
79 |
#include <limits.h> |
80 |
#include <errno.h> |
81 |
#include <stdint.h> |
79 |
|
82 |
|
80 |
#include "jasper/jas_malloc.h" |
83 |
#include "jasper/jas_malloc.h" |
81 |
|
84 |
|
Lines 113-130
Link Here
|
113 |
|
116 |
|
114 |
void *jas_realloc(void *ptr, size_t size) |
117 |
void *jas_realloc(void *ptr, size_t size) |
115 |
{ |
118 |
{ |
116 |
return realloc(ptr, size); |
119 |
return ptr ? realloc(ptr, size) : malloc(size); |
117 |
} |
120 |
} |
118 |
|
121 |
|
119 |
void *jas_calloc(size_t nmemb, size_t size) |
122 |
void *jas_realloc2(void *ptr, size_t nmemb, size_t size) |
|
|
123 |
{ |
124 |
if (!ptr) |
125 |
return jas_alloc2(nmemb, size); |
126 |
if (nmemb && SIZE_MAX / nmemb < size) { |
127 |
errno = ENOMEM; |
128 |
return NULL; |
129 |
} |
130 |
return jas_realloc(ptr, nmemb * size); |
131 |
|
132 |
} |
133 |
|
134 |
void *jas_alloc2(size_t nmemb, size_t size) |
135 |
{ |
136 |
if (nmemb && SIZE_MAX / nmemb < size) { |
137 |
errno = ENOMEM; |
138 |
return NULL; |
139 |
} |
140 |
|
141 |
return jas_malloc(nmemb * size); |
142 |
} |
143 |
|
144 |
void *jas_alloc3(size_t a, size_t b, size_t c) |
120 |
{ |
145 |
{ |
121 |
void *ptr; |
|
|
122 |
size_t n; |
146 |
size_t n; |
123 |
n = nmemb * size; |
147 |
|
124 |
if (!(ptr = jas_malloc(n * sizeof(char)))) { |
148 |
if (a && SIZE_MAX / a < b) { |
125 |
return 0; |
149 |
errno = ENOMEM; |
|
|
150 |
return NULL; |
126 |
} |
151 |
} |
127 |
memset(ptr, 0, n); |
152 |
|
|
|
153 |
return jas_alloc2(a*b, c); |
154 |
} |
155 |
|
156 |
void *jas_calloc(size_t nmemb, size_t size) |
157 |
{ |
158 |
void *ptr; |
159 |
|
160 |
ptr = jas_alloc2(nmemb, size); |
161 |
if (ptr) |
162 |
memset(ptr, 0, nmemb*size); |
128 |
return ptr; |
163 |
return ptr; |
129 |
} |
164 |
} |
130 |
|
165 |
|
131 |
-- src/libjasper/base/jas_seq.c |
166 |
++ src/libjasper/base/jas_seq.c |
Lines 114-120
Link Here
|
114 |
matrix->datasize_ = numrows * numcols; |
114 |
matrix->datasize_ = numrows * numcols; |
115 |
|
115 |
|
116 |
if (matrix->maxrows_ > 0) { |
116 |
if (matrix->maxrows_ > 0) { |
117 |
if (!(matrix->rows_ = jas_malloc(matrix->maxrows_ * |
117 |
if (!(matrix->rows_ = jas_alloc2(matrix->maxrows_, |
118 |
sizeof(jas_seqent_t *)))) { |
118 |
sizeof(jas_seqent_t *)))) { |
119 |
jas_matrix_destroy(matrix); |
119 |
jas_matrix_destroy(matrix); |
120 |
return 0; |
120 |
return 0; |
Lines 122-128
Link Here
|
122 |
} |
122 |
} |
123 |
|
123 |
|
124 |
if (matrix->datasize_ > 0) { |
124 |
if (matrix->datasize_ > 0) { |
125 |
if (!(matrix->data_ = jas_malloc(matrix->datasize_ * |
125 |
if (!(matrix->data_ = jas_alloc2(matrix->datasize_, |
126 |
sizeof(jas_seqent_t)))) { |
126 |
sizeof(jas_seqent_t)))) { |
127 |
jas_matrix_destroy(matrix); |
127 |
jas_matrix_destroy(matrix); |
128 |
return 0; |
128 |
return 0; |
Lines 220-226
Link Here
|
220 |
mat0->numrows_ = r1 - r0 + 1; |
220 |
mat0->numrows_ = r1 - r0 + 1; |
221 |
mat0->numcols_ = c1 - c0 + 1; |
221 |
mat0->numcols_ = c1 - c0 + 1; |
222 |
mat0->maxrows_ = mat0->numrows_; |
222 |
mat0->maxrows_ = mat0->numrows_; |
223 |
mat0->rows_ = jas_malloc(mat0->maxrows_ * sizeof(jas_seqent_t *)); |
223 |
mat0->rows_ = jas_alloc2(mat0->maxrows_, sizeof(jas_seqent_t *)); |
224 |
for (i = 0; i < mat0->numrows_; ++i) { |
224 |
for (i = 0; i < mat0->numrows_; ++i) { |
225 |
mat0->rows_[i] = mat1->rows_[r0 + i] + c0; |
225 |
mat0->rows_[i] = mat1->rows_[r0 + i] + c0; |
226 |
} |
226 |
} |
Lines 432-438
Link Here
|
432 |
for (i = 0; i < jas_matrix_numrows(matrix); ++i) { |
432 |
for (i = 0; i < jas_matrix_numrows(matrix); ++i) { |
433 |
for (j = 0; j < jas_matrix_numcols(matrix); ++j) { |
433 |
for (j = 0; j < jas_matrix_numcols(matrix); ++j) { |
434 |
x = jas_matrix_get(matrix, i, j); |
434 |
x = jas_matrix_get(matrix, i, j); |
435 |
sprintf(sbuf, "%s%4ld", (strlen(buf) > 0) ? " " : "", |
435 |
snprintf(sbuf, sizeof sbuf, |
|
|
436 |
"%s%4ld", (strlen(buf) > 0) ? " " : "", |
436 |
JAS_CAST(long, x)); |
437 |
JAS_CAST(long, x)); |
437 |
n = strlen(buf); |
438 |
n = strlen(buf); |
438 |
if (n + strlen(sbuf) > MAXLINELEN) { |
439 |
if (n + strlen(sbuf) > MAXLINELEN) { |
439 |
-- src/libjasper/base/jas_stream.c |
440 |
++ src/libjasper/base/jas_stream.c |
Lines 212-218
Link Here
|
212 |
if (buf) { |
212 |
if (buf) { |
213 |
obj->buf_ = (unsigned char *) buf; |
213 |
obj->buf_ = (unsigned char *) buf; |
214 |
} else { |
214 |
} else { |
215 |
obj->buf_ = jas_malloc(obj->bufsize_ * sizeof(char)); |
215 |
obj->buf_ = jas_malloc(obj->bufsize_); |
216 |
obj->myalloc_ = 1; |
216 |
obj->myalloc_ = 1; |
217 |
} |
217 |
} |
218 |
if (!obj->buf_) { |
218 |
if (!obj->buf_) { |
Lines 361-388
Link Here
|
361 |
} |
361 |
} |
362 |
obj->fd = -1; |
362 |
obj->fd = -1; |
363 |
obj->flags = 0; |
363 |
obj->flags = 0; |
364 |
obj->pathname[0] = '\0'; |
|
|
365 |
stream->obj_ = obj; |
364 |
stream->obj_ = obj; |
366 |
|
365 |
|
367 |
/* Choose a file name. */ |
366 |
/* Choose a file name. */ |
368 |
tmpnam(obj->pathname); |
367 |
snprintf(obj->pathname, L_tmpnam, "%stmp.XXXXXXXXXX", P_tmpdir); |
369 |
|
368 |
|
370 |
/* Open the underlying file. */ |
369 |
/* Open the underlying file. */ |
371 |
if ((obj->fd = open(obj->pathname, O_CREAT | O_EXCL | O_RDWR | O_TRUNC | O_BINARY, |
370 |
if ((obj->fd = mkstemp(obj->pathname)) < 0) { |
372 |
JAS_STREAM_PERMS)) < 0) { |
|
|
373 |
jas_stream_destroy(stream); |
371 |
jas_stream_destroy(stream); |
374 |
return 0; |
372 |
return 0; |
375 |
} |
373 |
} |
376 |
|
374 |
|
377 |
/* Unlink the file so that it will disappear if the program |
375 |
/* Unlink the file so that it will disappear if the program |
378 |
terminates abnormally. */ |
376 |
terminates abnormally. */ |
379 |
/* Under UNIX, one can unlink an open file and continue to do I/O |
|
|
380 |
on it. Not all operating systems support this functionality, however. |
381 |
For example, under Microsoft Windows the unlink operation will fail, |
382 |
since the file is open. */ |
383 |
if (unlink(obj->pathname)) { |
377 |
if (unlink(obj->pathname)) { |
384 |
/* We will try unlinking the file again after it is closed. */ |
378 |
jas_stream_destroy(stream); |
385 |
obj->flags |= JAS_STREAM_FILEOBJ_DELONCLOSE; |
379 |
return 0; |
386 |
} |
380 |
} |
387 |
|
381 |
|
388 |
/* Use full buffering. */ |
382 |
/* Use full buffering. */ |
Lines 553-559
Link Here
|
553 |
int ret; |
547 |
int ret; |
554 |
|
548 |
|
555 |
va_start(ap, fmt); |
549 |
va_start(ap, fmt); |
556 |
ret = vsprintf(buf, fmt, ap); |
550 |
ret = vsnprintf(buf, sizeof buf, fmt, ap); |
557 |
jas_stream_puts(stream, buf); |
551 |
jas_stream_puts(stream, buf); |
558 |
va_end(ap); |
552 |
va_end(ap); |
559 |
return ret; |
553 |
return ret; |
Lines 992-998
Link Here
|
992 |
unsigned char *buf; |
986 |
unsigned char *buf; |
993 |
|
987 |
|
994 |
assert(m->buf_); |
988 |
assert(m->buf_); |
995 |
if (!(buf = jas_realloc(m->buf_, bufsize * sizeof(unsigned char)))) { |
989 |
if (!(buf = jas_realloc(m->buf_, bufsize))) { |
996 |
return -1; |
990 |
return -1; |
997 |
} |
991 |
} |
998 |
m->buf_ = buf; |
992 |
m->buf_ = buf; |
999 |
-- src/libjasper/bmp/bmp_dec.c |
993 |
++ src/libjasper/bmp/bmp_dec.c |
Lines 283-289
Link Here
|
283 |
} |
283 |
} |
284 |
|
284 |
|
285 |
if (info->numcolors > 0) { |
285 |
if (info->numcolors > 0) { |
286 |
if (!(info->palents = jas_malloc(info->numcolors * |
286 |
if (!(info->palents = jas_alloc2(info->numcolors, |
287 |
sizeof(bmp_palent_t)))) { |
287 |
sizeof(bmp_palent_t)))) { |
288 |
bmp_info_destroy(info); |
288 |
bmp_info_destroy(info); |
289 |
return 0; |
289 |
return 0; |
290 |
-- src/libjasper/include/jasper/jas_malloc.h |
290 |
++ src/libjasper/include/jasper/jas_malloc.h |
Lines 95-100
Link Here
|
95 |
#define jas_free MEMFREE |
95 |
#define jas_free MEMFREE |
96 |
#define jas_realloc MEMREALLOC |
96 |
#define jas_realloc MEMREALLOC |
97 |
#define jas_calloc MEMCALLOC |
97 |
#define jas_calloc MEMCALLOC |
|
|
98 |
#define jas_alloc2(a, b) MEMALLOC((a)*(b)) |
99 |
#define jas_alloc3(a, b, c) MEMALLOC((a)*(b)*(c)) |
100 |
#define jas_realloc2(p, a, b) MEMREALLOC((p), (a)*(b)) |
98 |
#endif |
101 |
#endif |
99 |
|
102 |
|
100 |
/******************************************************************************\ |
103 |
/******************************************************************************\ |
Lines 115-120
Link Here
|
115 |
/* Allocate a block of memory and initialize the contents to zero. */ |
118 |
/* Allocate a block of memory and initialize the contents to zero. */ |
116 |
void *jas_calloc(size_t nmemb, size_t size); |
119 |
void *jas_calloc(size_t nmemb, size_t size); |
117 |
|
120 |
|
|
|
121 |
/* size-checked double allocation .*/ |
122 |
void *jas_alloc2(size_t, size_t); |
123 |
|
124 |
void *jas_alloc3(size_t, size_t, size_t); |
125 |
|
126 |
void *jas_realloc2(void *, size_t, size_t); |
118 |
#endif |
127 |
#endif |
119 |
|
128 |
|
120 |
#ifdef __cplusplus |
129 |
#ifdef __cplusplus |
121 |
-- src/libjasper/jp2/jp2_cod.c |
130 |
++ src/libjasper/jp2/jp2_cod.c |
Lines 795-805
Link Here
|
795 |
jp2_cmap_t *cmap = &box->data.cmap; |
795 |
jp2_cmap_t *cmap = &box->data.cmap; |
796 |
unsigned int i; |
796 |
unsigned int i; |
797 |
jp2_cmapent_t *ent; |
797 |
jp2_cmapent_t *ent; |
798 |
fprintf(out, "numchans = %d\n", (int) cmap->numchans); |
798 |
if (jas_getdbglevel() >= 1) { |
|
|
799 |
fprintf(out, "numchans = %d\n", (int) cmap->numchans); |
800 |
} |
799 |
for (i = 0; i < cmap->numchans; ++i) { |
801 |
for (i = 0; i < cmap->numchans; ++i) { |
800 |
ent = &cmap->ents[i]; |
802 |
ent = &cmap->ents[i]; |
801 |
fprintf(out, "cmptno=%d; map=%d; pcol=%d\n", |
803 |
if (jas_getdbglevel() >= 1) { |
802 |
(int) ent->cmptno, (int) ent->map, (int) ent->pcol); |
804 |
fprintf(out, "cmptno=%d; map=%d; pcol=%d\n", |
|
|
805 |
(int) ent->cmptno, (int) ent->map, (int) ent->pcol); |
806 |
} |
803 |
} |
807 |
} |
804 |
} |
808 |
} |
805 |
|
809 |
|
806 |
-- src/libjasper/jp2/jp2_dec.c |
810 |
++ src/libjasper/jp2/jp2_dec.c |
Lines 293-299
Link Here
|
293 |
dec->colr->data.colr.iccplen); |
293 |
dec->colr->data.colr.iccplen); |
294 |
assert(iccprof); |
294 |
assert(iccprof); |
295 |
jas_iccprof_gethdr(iccprof, &icchdr); |
295 |
jas_iccprof_gethdr(iccprof, &icchdr); |
296 |
jas_eprintf("ICC Profile CS %08x\n", icchdr.colorspc); |
296 |
if (jas_getdbglevel() >= 1) { |
|
|
297 |
jas_eprintf("ICC Profile CS %08x\n", icchdr.colorspc); |
298 |
} |
297 |
jas_image_setclrspc(dec->image, fromiccpcs(icchdr.colorspc)); |
299 |
jas_image_setclrspc(dec->image, fromiccpcs(icchdr.colorspc)); |
298 |
dec->image->cmprof_ = jas_cmprof_createfromiccprof(iccprof); |
300 |
dec->image->cmprof_ = jas_cmprof_createfromiccprof(iccprof); |
299 |
assert(dec->image->cmprof_); |
301 |
assert(dec->image->cmprof_); |
300 |
-- src/libjasper/jp2/jp2_enc.c |
302 |
++ src/libjasper/jp2/jp2_enc.c |
Lines 191-197
Link Here
|
191 |
} |
191 |
} |
192 |
bpcc = &box->data.bpcc; |
192 |
bpcc = &box->data.bpcc; |
193 |
bpcc->numcmpts = jas_image_numcmpts(image); |
193 |
bpcc->numcmpts = jas_image_numcmpts(image); |
194 |
if (!(bpcc->bpcs = jas_malloc(bpcc->numcmpts * |
194 |
if (!(bpcc->bpcs = jas_alloc2(bpcc->numcmpts, |
195 |
sizeof(uint_fast8_t)))) { |
195 |
sizeof(uint_fast8_t)))) { |
196 |
goto error; |
196 |
goto error; |
197 |
} |
197 |
} |
Lines 285-291
Link Here
|
285 |
} |
285 |
} |
286 |
cdef = &box->data.cdef; |
286 |
cdef = &box->data.cdef; |
287 |
cdef->numchans = jas_image_numcmpts(image); |
287 |
cdef->numchans = jas_image_numcmpts(image); |
288 |
cdef->ents = jas_malloc(cdef->numchans * sizeof(jp2_cdefchan_t)); |
288 |
cdef->ents = jas_alloc2(cdef->numchans, sizeof(jp2_cdefchan_t)); |
289 |
for (i = 0; i < jas_image_numcmpts(image); ++i) { |
289 |
for (i = 0; i < jas_image_numcmpts(image); ++i) { |
290 |
cdefchanent = &cdef->ents[i]; |
290 |
cdefchanent = &cdef->ents[i]; |
291 |
cdefchanent->channo = i; |
291 |
cdefchanent->channo = i; |
Lines 343-349
Link Here
|
343 |
/* Output the JPEG-2000 code stream. */ |
343 |
/* Output the JPEG-2000 code stream. */ |
344 |
|
344 |
|
345 |
overhead = jas_stream_getrwcount(out); |
345 |
overhead = jas_stream_getrwcount(out); |
346 |
sprintf(buf, "%s\n_jp2overhead=%lu\n", (optstr ? optstr : ""), |
346 |
snprintf(buf, sizeof buf, "%s\n_jp2overhead=%lu\n", |
|
|
347 |
(optstr ? optstr : ""), |
347 |
(unsigned long) overhead); |
348 |
(unsigned long) overhead); |
348 |
|
349 |
|
349 |
if (jpc_encode(image, out, buf)) { |
350 |
if (jpc_encode(image, out, buf)) { |
350 |
-- src/libjasper/jpc/jpc_cs.c |
351 |
++ src/libjasper/jpc/jpc_cs.c |
Lines 502-508
Link Here
|
502 |
!siz->tileheight || !siz->numcomps) { |
502 |
!siz->tileheight || !siz->numcomps) { |
503 |
return -1; |
503 |
return -1; |
504 |
} |
504 |
} |
505 |
if (!(siz->comps = jas_malloc(siz->numcomps * sizeof(jpc_sizcomp_t)))) { |
505 |
if (!(siz->comps = jas_alloc2(siz->numcomps, sizeof(jpc_sizcomp_t)))) { |
506 |
return -1; |
506 |
return -1; |
507 |
} |
507 |
} |
508 |
for (i = 0; i < siz->numcomps; ++i) { |
508 |
for (i = 0; i < siz->numcomps; ++i) { |
Lines 986-992
Link Here
|
986 |
jpc_qcx_destroycompparms(compparms); |
986 |
jpc_qcx_destroycompparms(compparms); |
987 |
return -1; |
987 |
return -1; |
988 |
} else if (compparms->numstepsizes > 0) { |
988 |
} else if (compparms->numstepsizes > 0) { |
989 |
compparms->stepsizes = jas_malloc(compparms->numstepsizes * |
989 |
compparms->stepsizes = jas_alloc2(compparms->numstepsizes, |
990 |
sizeof(uint_fast16_t)); |
990 |
sizeof(uint_fast16_t)); |
991 |
assert(compparms->stepsizes); |
991 |
assert(compparms->stepsizes); |
992 |
for (i = 0; i < compparms->numstepsizes; ++i) { |
992 |
for (i = 0; i < compparms->numstepsizes; ++i) { |
Lines 1094-1100
Link Here
|
1094 |
|
1094 |
|
1095 |
ppm->len = ms->len - 1; |
1095 |
ppm->len = ms->len - 1; |
1096 |
if (ppm->len > 0) { |
1096 |
if (ppm->len > 0) { |
1097 |
if (!(ppm->data = jas_malloc(ppm->len * sizeof(unsigned char)))) { |
1097 |
if (!(ppm->data = jas_malloc(ppm->len))) { |
1098 |
goto error; |
1098 |
goto error; |
1099 |
} |
1099 |
} |
1100 |
if (JAS_CAST(uint, jas_stream_read(in, ppm->data, ppm->len)) != ppm->len) { |
1100 |
if (JAS_CAST(uint, jas_stream_read(in, ppm->data, ppm->len)) != ppm->len) { |
Lines 1163-1169
Link Here
|
1163 |
} |
1163 |
} |
1164 |
ppt->len = ms->len - 1; |
1164 |
ppt->len = ms->len - 1; |
1165 |
if (ppt->len > 0) { |
1165 |
if (ppt->len > 0) { |
1166 |
if (!(ppt->data = jas_malloc(ppt->len * sizeof(unsigned char)))) { |
1166 |
if (!(ppt->data = jas_malloc(ppt->len))) { |
1167 |
goto error; |
1167 |
goto error; |
1168 |
} |
1168 |
} |
1169 |
if (jas_stream_read(in, (char *) ppt->data, ppt->len) != JAS_CAST(int, ppt->len)) { |
1169 |
if (jas_stream_read(in, (char *) ppt->data, ppt->len) != JAS_CAST(int, ppt->len)) { |
Lines 1226-1232
Link Here
|
1226 |
uint_fast8_t tmp; |
1226 |
uint_fast8_t tmp; |
1227 |
poc->numpchgs = (cstate->numcomps > 256) ? (ms->len / 9) : |
1227 |
poc->numpchgs = (cstate->numcomps > 256) ? (ms->len / 9) : |
1228 |
(ms->len / 7); |
1228 |
(ms->len / 7); |
1229 |
if (!(poc->pchgs = jas_malloc(poc->numpchgs * sizeof(jpc_pocpchg_t)))) { |
1229 |
if (!(poc->pchgs = jas_alloc2(poc->numpchgs, sizeof(jpc_pocpchg_t)))) { |
1230 |
goto error; |
1230 |
goto error; |
1231 |
} |
1231 |
} |
1232 |
for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; ++pchgno, |
1232 |
for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; ++pchgno, |
Lines 1331-1337
Link Here
|
1331 |
jpc_crgcomp_t *comp; |
1331 |
jpc_crgcomp_t *comp; |
1332 |
uint_fast16_t compno; |
1332 |
uint_fast16_t compno; |
1333 |
crg->numcomps = cstate->numcomps; |
1333 |
crg->numcomps = cstate->numcomps; |
1334 |
if (!(crg->comps = jas_malloc(cstate->numcomps * sizeof(uint_fast16_t)))) { |
1334 |
if (!(crg->comps = jas_alloc2(cstate->numcomps, sizeof(uint_fast16_t)))) { |
1335 |
return -1; |
1335 |
return -1; |
1336 |
} |
1336 |
} |
1337 |
for (compno = 0, comp = crg->comps; compno < cstate->numcomps; |
1337 |
for (compno = 0, comp = crg->comps; compno < cstate->numcomps; |
Lines 1470-1476
Link Here
|
1470 |
cstate = 0; |
1470 |
cstate = 0; |
1471 |
|
1471 |
|
1472 |
if (ms->len > 0) { |
1472 |
if (ms->len > 0) { |
1473 |
if (!(unk->data = jas_malloc(ms->len * sizeof(unsigned char)))) { |
1473 |
if (!(unk->data = jas_malloc(ms->len))) { |
1474 |
return -1; |
1474 |
return -1; |
1475 |
} |
1475 |
} |
1476 |
if (jas_stream_read(in, (char *) unk->data, ms->len) != JAS_CAST(int, ms->len)) { |
1476 |
if (jas_stream_read(in, (char *) unk->data, ms->len) != JAS_CAST(int, ms->len)) { |
1477 |
-- src/libjasper/jpc/jpc_dec.c |
1477 |
++ src/libjasper/jpc/jpc_dec.c |
Lines 1466-1472
Link Here
|
1466 |
dec = 0; |
1466 |
dec = 0; |
1467 |
|
1467 |
|
1468 |
jas_eprintf("warning: ignoring unknown marker segment\n"); |
1468 |
jas_eprintf("warning: ignoring unknown marker segment\n"); |
1469 |
jpc_ms_dump(ms, stderr); |
1469 |
if (jas_getdbglevel() >= 1) { |
|
|
1470 |
jpc_ms_dump(ms, stderr); |
1471 |
} |
1470 |
return 0; |
1472 |
return 0; |
1471 |
} |
1473 |
} |
1472 |
|
1474 |
|
1473 |
-- src/libjasper/jpc/jpc_enc.c |
1475 |
++ src/libjasper/jpc/jpc_enc.c |
Lines 403-409
Link Here
|
403 |
vsteplcm *= jas_image_cmptvstep(image, cmptno); |
403 |
vsteplcm *= jas_image_cmptvstep(image, cmptno); |
404 |
} |
404 |
} |
405 |
|
405 |
|
406 |
if (!(cp->ccps = jas_malloc(cp->numcmpts * sizeof(jpc_enc_ccp_t)))) { |
406 |
if (!(cp->ccps = jas_alloc2(cp->numcmpts, sizeof(jpc_enc_ccp_t)))) { |
407 |
goto error; |
407 |
goto error; |
408 |
} |
408 |
} |
409 |
for (cmptno = 0, ccp = cp->ccps; cmptno < JAS_CAST(int, cp->numcmpts); ++cmptno, |
409 |
for (cmptno = 0, ccp = cp->ccps; cmptno < JAS_CAST(int, cp->numcmpts); ++cmptno, |
Lines 656-662
Link Here
|
656 |
|
656 |
|
657 |
if (ilyrrates && numilyrrates > 0) { |
657 |
if (ilyrrates && numilyrrates > 0) { |
658 |
tcp->numlyrs = numilyrrates + 1; |
658 |
tcp->numlyrs = numilyrrates + 1; |
659 |
if (!(tcp->ilyrrates = jas_malloc((tcp->numlyrs - 1) * |
659 |
if (!(tcp->ilyrrates = jas_alloc2((tcp->numlyrs - 1), |
660 |
sizeof(jpc_fix_t)))) { |
660 |
sizeof(jpc_fix_t)))) { |
661 |
goto error; |
661 |
goto error; |
662 |
} |
662 |
} |
Lines 940-946
Link Here
|
940 |
siz->tilewidth = cp->tilewidth; |
940 |
siz->tilewidth = cp->tilewidth; |
941 |
siz->tileheight = cp->tileheight; |
941 |
siz->tileheight = cp->tileheight; |
942 |
siz->numcomps = cp->numcmpts; |
942 |
siz->numcomps = cp->numcmpts; |
943 |
siz->comps = jas_malloc(siz->numcomps * sizeof(jpc_sizcomp_t)); |
943 |
siz->comps = jas_alloc2(siz->numcomps, sizeof(jpc_sizcomp_t)); |
944 |
assert(siz->comps); |
944 |
assert(siz->comps); |
945 |
for (i = 0; i < JAS_CAST(int, cp->numcmpts); ++i) { |
945 |
for (i = 0; i < JAS_CAST(int, cp->numcmpts); ++i) { |
946 |
siz->comps[i].prec = cp->ccps[i].prec; |
946 |
siz->comps[i].prec = cp->ccps[i].prec; |
Lines 958-964
Link Here
|
958 |
if (!(enc->mrk = jpc_ms_create(JPC_MS_COM))) { |
958 |
if (!(enc->mrk = jpc_ms_create(JPC_MS_COM))) { |
959 |
return -1; |
959 |
return -1; |
960 |
} |
960 |
} |
961 |
sprintf(buf, "Creator: JasPer Version %s", jas_getversion()); |
961 |
snprintf(buf, sizeof buf, "Creator: JasPer Version %s", |
|
|
962 |
jas_getversion()); |
962 |
com = &enc->mrk->parms.com; |
963 |
com = &enc->mrk->parms.com; |
963 |
com->len = strlen(buf); |
964 |
com->len = strlen(buf); |
964 |
com->regid = JPC_COM_LATIN; |
965 |
com->regid = JPC_COM_LATIN; |
Lines 977-983
Link Here
|
977 |
return -1; |
978 |
return -1; |
978 |
} |
979 |
} |
979 |
crg = &enc->mrk->parms.crg; |
980 |
crg = &enc->mrk->parms.crg; |
980 |
crg->comps = jas_malloc(crg->numcomps * sizeof(jpc_crgcomp_t)); |
981 |
crg->comps = jas_alloc2(crg->numcomps, sizeof(jpc_crgcomp_t)); |
981 |
if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { |
982 |
if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { |
982 |
jas_eprintf("cannot write CRG marker\n"); |
983 |
jas_eprintf("cannot write CRG marker\n"); |
983 |
return -1; |
984 |
return -1; |
Lines 1955-1961
Link Here
|
1955 |
tile->mctid = cp->tcp.mctid; |
1956 |
tile->mctid = cp->tcp.mctid; |
1956 |
|
1957 |
|
1957 |
tile->numlyrs = cp->tcp.numlyrs; |
1958 |
tile->numlyrs = cp->tcp.numlyrs; |
1958 |
if (!(tile->lyrsizes = jas_malloc(tile->numlyrs * |
1959 |
if (!(tile->lyrsizes = jas_alloc2(tile->numlyrs, |
1959 |
sizeof(uint_fast32_t)))) { |
1960 |
sizeof(uint_fast32_t)))) { |
1960 |
goto error; |
1961 |
goto error; |
1961 |
} |
1962 |
} |
Lines 1964-1970
Link Here
|
1964 |
} |
1965 |
} |
1965 |
|
1966 |
|
1966 |
/* Allocate an array for the per-tile-component information. */ |
1967 |
/* Allocate an array for the per-tile-component information. */ |
1967 |
if (!(tile->tcmpts = jas_malloc(cp->numcmpts * sizeof(jpc_enc_tcmpt_t)))) { |
1968 |
if (!(tile->tcmpts = jas_alloc2(cp->numcmpts, sizeof(jpc_enc_tcmpt_t)))) { |
1968 |
goto error; |
1969 |
goto error; |
1969 |
} |
1970 |
} |
1970 |
/* Initialize a few members critical for error recovery. */ |
1971 |
/* Initialize a few members critical for error recovery. */ |
Lines 2110-2116
Link Here
|
2110 |
jas_seq2d_ystart(tcmpt->data), jas_seq2d_xend(tcmpt->data), |
2111 |
jas_seq2d_ystart(tcmpt->data), jas_seq2d_xend(tcmpt->data), |
2111 |
jas_seq2d_yend(tcmpt->data), bandinfos); |
2112 |
jas_seq2d_yend(tcmpt->data), bandinfos); |
2112 |
|
2113 |
|
2113 |
if (!(tcmpt->rlvls = jas_malloc(tcmpt->numrlvls * sizeof(jpc_enc_rlvl_t)))) { |
2114 |
if (!(tcmpt->rlvls = jas_alloc2(tcmpt->numrlvls, sizeof(jpc_enc_rlvl_t)))) { |
2114 |
goto error; |
2115 |
goto error; |
2115 |
} |
2116 |
} |
2116 |
for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls; |
2117 |
for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls; |
Lines 2213-2219
Link Here
|
2213 |
rlvl->numvprcs = JPC_FLOORDIVPOW2(brprcbry - tlprctly, rlvl->prcheightexpn); |
2214 |
rlvl->numvprcs = JPC_FLOORDIVPOW2(brprcbry - tlprctly, rlvl->prcheightexpn); |
2214 |
rlvl->numprcs = rlvl->numhprcs * rlvl->numvprcs; |
2215 |
rlvl->numprcs = rlvl->numhprcs * rlvl->numvprcs; |
2215 |
|
2216 |
|
2216 |
if (!(rlvl->bands = jas_malloc(rlvl->numbands * sizeof(jpc_enc_band_t)))) { |
2217 |
if (!(rlvl->bands = jas_alloc2(rlvl->numbands, sizeof(jpc_enc_band_t)))) { |
2217 |
goto error; |
2218 |
goto error; |
2218 |
} |
2219 |
} |
2219 |
for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; |
2220 |
for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; |
Lines 2290-2296
Link Here
|
2290 |
band->synweight = bandinfo->synenergywt; |
2291 |
band->synweight = bandinfo->synenergywt; |
2291 |
|
2292 |
|
2292 |
if (band->data) { |
2293 |
if (band->data) { |
2293 |
if (!(band->prcs = jas_malloc(rlvl->numprcs * sizeof(jpc_enc_prc_t)))) { |
2294 |
if (!(band->prcs = jas_alloc2(rlvl->numprcs, sizeof(jpc_enc_prc_t)))) { |
2294 |
goto error; |
2295 |
goto error; |
2295 |
} |
2296 |
} |
2296 |
for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs; ++prcno, |
2297 |
for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs; ++prcno, |
Lines 2422-2428
Link Here
|
2422 |
goto error; |
2423 |
goto error; |
2423 |
} |
2424 |
} |
2424 |
|
2425 |
|
2425 |
if (!(prc->cblks = jas_malloc(prc->numcblks * sizeof(jpc_enc_cblk_t)))) { |
2426 |
if (!(prc->cblks = jas_alloc2(prc->numcblks, sizeof(jpc_enc_cblk_t)))) { |
2426 |
goto error; |
2427 |
goto error; |
2427 |
} |
2428 |
} |
2428 |
for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; |
2429 |
for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; |
2429 |
-- src/libjasper/jpc/jpc_mqdec.c |
2430 |
++ src/libjasper/jpc/jpc_mqdec.c |
Lines 118-124
Link Here
|
118 |
mqdec->in = in; |
118 |
mqdec->in = in; |
119 |
mqdec->maxctxs = maxctxs; |
119 |
mqdec->maxctxs = maxctxs; |
120 |
/* Allocate memory for the per-context state information. */ |
120 |
/* Allocate memory for the per-context state information. */ |
121 |
if (!(mqdec->ctxs = jas_malloc(mqdec->maxctxs * sizeof(jpc_mqstate_t *)))) { |
121 |
if (!(mqdec->ctxs = jas_alloc2(mqdec->maxctxs, sizeof(jpc_mqstate_t *)))) { |
122 |
goto error; |
122 |
goto error; |
123 |
} |
123 |
} |
124 |
/* Set the current context to the first context. */ |
124 |
/* Set the current context to the first context. */ |
125 |
-- src/libjasper/jpc/jpc_mqenc.c |
125 |
++ src/libjasper/jpc/jpc_mqenc.c |
Lines 197-203
Link Here
|
197 |
mqenc->maxctxs = maxctxs; |
197 |
mqenc->maxctxs = maxctxs; |
198 |
|
198 |
|
199 |
/* Allocate memory for the per-context state information. */ |
199 |
/* Allocate memory for the per-context state information. */ |
200 |
if (!(mqenc->ctxs = jas_malloc(mqenc->maxctxs * sizeof(jpc_mqstate_t *)))) { |
200 |
if (!(mqenc->ctxs = jas_alloc2(mqenc->maxctxs, sizeof(jpc_mqstate_t *)))) { |
201 |
goto error; |
201 |
goto error; |
202 |
} |
202 |
} |
203 |
|
203 |
|
204 |
-- src/libjasper/jpc/jpc_qmfb.c |
204 |
++ src/libjasper/jpc/jpc_qmfb.c |
Lines 321-327
Link Here
|
321 |
#if !defined(HAVE_VLA) |
321 |
#if !defined(HAVE_VLA) |
322 |
/* Get a buffer. */ |
322 |
/* Get a buffer. */ |
323 |
if (bufsize > QMFB_SPLITBUFSIZE) { |
323 |
if (bufsize > QMFB_SPLITBUFSIZE) { |
324 |
if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { |
324 |
if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) { |
325 |
/* We have no choice but to commit suicide in this case. */ |
325 |
/* We have no choice but to commit suicide in this case. */ |
326 |
abort(); |
326 |
abort(); |
327 |
} |
327 |
} |
Lines 389-395
Link Here
|
389 |
#if !defined(HAVE_VLA) |
389 |
#if !defined(HAVE_VLA) |
390 |
/* Get a buffer. */ |
390 |
/* Get a buffer. */ |
391 |
if (bufsize > QMFB_SPLITBUFSIZE) { |
391 |
if (bufsize > QMFB_SPLITBUFSIZE) { |
392 |
if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { |
392 |
if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) { |
393 |
/* We have no choice but to commit suicide in this case. */ |
393 |
/* We have no choice but to commit suicide in this case. */ |
394 |
abort(); |
394 |
abort(); |
395 |
} |
395 |
} |
Lines 460-466
Link Here
|
460 |
#if !defined(HAVE_VLA) |
460 |
#if !defined(HAVE_VLA) |
461 |
/* Get a buffer. */ |
461 |
/* Get a buffer. */ |
462 |
if (bufsize > QMFB_SPLITBUFSIZE) { |
462 |
if (bufsize > QMFB_SPLITBUFSIZE) { |
463 |
if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { |
463 |
if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) { |
464 |
/* We have no choice but to commit suicide in this case. */ |
464 |
/* We have no choice but to commit suicide in this case. */ |
465 |
abort(); |
465 |
abort(); |
466 |
} |
466 |
} |
Lines 549-555
Link Here
|
549 |
#if !defined(HAVE_VLA) |
549 |
#if !defined(HAVE_VLA) |
550 |
/* Get a buffer. */ |
550 |
/* Get a buffer. */ |
551 |
if (bufsize > QMFB_SPLITBUFSIZE) { |
551 |
if (bufsize > QMFB_SPLITBUFSIZE) { |
552 |
if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { |
552 |
if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) { |
553 |
/* We have no choice but to commit suicide in this case. */ |
553 |
/* We have no choice but to commit suicide in this case. */ |
554 |
abort(); |
554 |
abort(); |
555 |
} |
555 |
} |
Lines 633-639
Link Here
|
633 |
#if !defined(HAVE_VLA) |
633 |
#if !defined(HAVE_VLA) |
634 |
/* Allocate memory for the join buffer from the heap. */ |
634 |
/* Allocate memory for the join buffer from the heap. */ |
635 |
if (bufsize > QMFB_JOINBUFSIZE) { |
635 |
if (bufsize > QMFB_JOINBUFSIZE) { |
636 |
if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { |
636 |
if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) { |
637 |
/* We have no choice but to commit suicide. */ |
637 |
/* We have no choice but to commit suicide. */ |
638 |
abort(); |
638 |
abort(); |
639 |
} |
639 |
} |
Lines 698-704
Link Here
|
698 |
#if !defined(HAVE_VLA) |
698 |
#if !defined(HAVE_VLA) |
699 |
/* Allocate memory for the join buffer from the heap. */ |
699 |
/* Allocate memory for the join buffer from the heap. */ |
700 |
if (bufsize > QMFB_JOINBUFSIZE) { |
700 |
if (bufsize > QMFB_JOINBUFSIZE) { |
701 |
if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { |
701 |
if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) { |
702 |
/* We have no choice but to commit suicide. */ |
702 |
/* We have no choice but to commit suicide. */ |
703 |
abort(); |
703 |
abort(); |
704 |
} |
704 |
} |
Lines 766-772
Link Here
|
766 |
#if !defined(HAVE_VLA) |
766 |
#if !defined(HAVE_VLA) |
767 |
/* Allocate memory for the join buffer from the heap. */ |
767 |
/* Allocate memory for the join buffer from the heap. */ |
768 |
if (bufsize > QMFB_JOINBUFSIZE) { |
768 |
if (bufsize > QMFB_JOINBUFSIZE) { |
769 |
if (!(buf = jas_malloc(bufsize * JPC_QMFB_COLGRPSIZE * sizeof(jpc_fix_t)))) { |
769 |
if (!(buf = jas_alloc2(bufsize, JPC_QMFB_COLGRPSIZE * sizeof(jpc_fix_t)))) { |
770 |
/* We have no choice but to commit suicide. */ |
770 |
/* We have no choice but to commit suicide. */ |
771 |
abort(); |
771 |
abort(); |
772 |
} |
772 |
} |
Lines 852-858
Link Here
|
852 |
#if !defined(HAVE_VLA) |
852 |
#if !defined(HAVE_VLA) |
853 |
/* Allocate memory for the join buffer from the heap. */ |
853 |
/* Allocate memory for the join buffer from the heap. */ |
854 |
if (bufsize > QMFB_JOINBUFSIZE) { |
854 |
if (bufsize > QMFB_JOINBUFSIZE) { |
855 |
if (!(buf = jas_malloc(bufsize * numcols * sizeof(jpc_fix_t)))) { |
855 |
if (!(buf = jas_alloc3(bufsize, numcols, sizeof(jpc_fix_t)))) { |
856 |
/* We have no choice but to commit suicide. */ |
856 |
/* We have no choice but to commit suicide. */ |
857 |
abort(); |
857 |
abort(); |
858 |
} |
858 |
} |
859 |
-- src/libjasper/jpc/jpc_t1enc.c |
859 |
++ src/libjasper/jpc/jpc_t1enc.c |
Lines 219-225
Link Here
|
219 |
|
219 |
|
220 |
cblk->numpasses = (cblk->numbps > 0) ? (3 * cblk->numbps - 2) : 0; |
220 |
cblk->numpasses = (cblk->numbps > 0) ? (3 * cblk->numbps - 2) : 0; |
221 |
if (cblk->numpasses > 0) { |
221 |
if (cblk->numpasses > 0) { |
222 |
cblk->passes = jas_malloc(cblk->numpasses * sizeof(jpc_enc_pass_t)); |
222 |
cblk->passes = jas_alloc2(cblk->numpasses, sizeof(jpc_enc_pass_t)); |
223 |
assert(cblk->passes); |
223 |
assert(cblk->passes); |
224 |
} else { |
224 |
} else { |
225 |
cblk->passes = 0; |
225 |
cblk->passes = 0; |
226 |
-- src/libjasper/jpc/jpc_t2cod.c |
226 |
++ src/libjasper/jpc/jpc_t2cod.c |
Lines 573-579
Link Here
|
573 |
} |
573 |
} |
574 |
if (pchglist->numpchgs >= pchglist->maxpchgs) { |
574 |
if (pchglist->numpchgs >= pchglist->maxpchgs) { |
575 |
newmaxpchgs = pchglist->maxpchgs + 128; |
575 |
newmaxpchgs = pchglist->maxpchgs + 128; |
576 |
if (!(newpchgs = jas_realloc(pchglist->pchgs, newmaxpchgs * sizeof(jpc_pchg_t *)))) { |
576 |
if (!(newpchgs = jas_realloc2(pchglist->pchgs, newmaxpchgs, sizeof(jpc_pchg_t *)))) { |
577 |
return -1; |
577 |
return -1; |
578 |
} |
578 |
} |
579 |
pchglist->maxpchgs = newmaxpchgs; |
579 |
pchglist->maxpchgs = newmaxpchgs; |
580 |
-- src/libjasper/jpc/jpc_t2dec.c |
580 |
++ src/libjasper/jpc/jpc_t2dec.c |
Lines 478-484
Link Here
|
478 |
return 0; |
478 |
return 0; |
479 |
} |
479 |
} |
480 |
pi->numcomps = dec->numcomps; |
480 |
pi->numcomps = dec->numcomps; |
481 |
if (!(pi->picomps = jas_malloc(pi->numcomps * sizeof(jpc_picomp_t)))) { |
481 |
if (!(pi->picomps = jas_alloc2(pi->numcomps, sizeof(jpc_picomp_t)))) { |
482 |
jpc_pi_destroy(pi); |
482 |
jpc_pi_destroy(pi); |
483 |
return 0; |
483 |
return 0; |
484 |
} |
484 |
} |
Lines 490-496
Link Here
|
490 |
for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps; |
490 |
for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps; |
491 |
compno < pi->numcomps; ++compno, ++tcomp, ++picomp) { |
491 |
compno < pi->numcomps; ++compno, ++tcomp, ++picomp) { |
492 |
picomp->numrlvls = tcomp->numrlvls; |
492 |
picomp->numrlvls = tcomp->numrlvls; |
493 |
if (!(picomp->pirlvls = jas_malloc(picomp->numrlvls * |
493 |
if (!(picomp->pirlvls = jas_alloc2(picomp->numrlvls, |
494 |
sizeof(jpc_pirlvl_t)))) { |
494 |
sizeof(jpc_pirlvl_t)))) { |
495 |
jpc_pi_destroy(pi); |
495 |
jpc_pi_destroy(pi); |
496 |
return 0; |
496 |
return 0; |
Lines 503-509
Link Here
|
503 |
rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) { |
503 |
rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) { |
504 |
/* XXX sizeof(long) should be sizeof different type */ |
504 |
/* XXX sizeof(long) should be sizeof different type */ |
505 |
pirlvl->numprcs = rlvl->numprcs; |
505 |
pirlvl->numprcs = rlvl->numprcs; |
506 |
if (!(pirlvl->prclyrnos = jas_malloc(pirlvl->numprcs * |
506 |
if (!(pirlvl->prclyrnos = jas_alloc2(pirlvl->numprcs, |
507 |
sizeof(long)))) { |
507 |
sizeof(long)))) { |
508 |
jpc_pi_destroy(pi); |
508 |
jpc_pi_destroy(pi); |
509 |
return 0; |
509 |
return 0; |
510 |
-- src/libjasper/jpc/jpc_t2enc.c |
510 |
++ src/libjasper/jpc/jpc_t2enc.c |
Lines 565-571
Link Here
|
565 |
} |
565 |
} |
566 |
pi->pktno = -1; |
566 |
pi->pktno = -1; |
567 |
pi->numcomps = cp->numcmpts; |
567 |
pi->numcomps = cp->numcmpts; |
568 |
if (!(pi->picomps = jas_malloc(pi->numcomps * sizeof(jpc_picomp_t)))) { |
568 |
if (!(pi->picomps = jas_alloc2(pi->numcomps, sizeof(jpc_picomp_t)))) { |
569 |
jpc_pi_destroy(pi); |
569 |
jpc_pi_destroy(pi); |
570 |
return 0; |
570 |
return 0; |
571 |
} |
571 |
} |
Lines 577-583
Link Here
|
577 |
for (compno = 0, tcomp = tile->tcmpts, picomp = pi->picomps; |
577 |
for (compno = 0, tcomp = tile->tcmpts, picomp = pi->picomps; |
578 |
compno < pi->numcomps; ++compno, ++tcomp, ++picomp) { |
578 |
compno < pi->numcomps; ++compno, ++tcomp, ++picomp) { |
579 |
picomp->numrlvls = tcomp->numrlvls; |
579 |
picomp->numrlvls = tcomp->numrlvls; |
580 |
if (!(picomp->pirlvls = jas_malloc(picomp->numrlvls * |
580 |
if (!(picomp->pirlvls = jas_alloc2(picomp->numrlvls, |
581 |
sizeof(jpc_pirlvl_t)))) { |
581 |
sizeof(jpc_pirlvl_t)))) { |
582 |
jpc_pi_destroy(pi); |
582 |
jpc_pi_destroy(pi); |
583 |
return 0; |
583 |
return 0; |
Lines 591-597
Link Here
|
591 |
/* XXX sizeof(long) should be sizeof different type */ |
591 |
/* XXX sizeof(long) should be sizeof different type */ |
592 |
pirlvl->numprcs = rlvl->numprcs; |
592 |
pirlvl->numprcs = rlvl->numprcs; |
593 |
if (rlvl->numprcs) { |
593 |
if (rlvl->numprcs) { |
594 |
if (!(pirlvl->prclyrnos = jas_malloc(pirlvl->numprcs * |
594 |
if (!(pirlvl->prclyrnos = jas_alloc2(pirlvl->numprcs, |
595 |
sizeof(long)))) { |
595 |
sizeof(long)))) { |
596 |
jpc_pi_destroy(pi); |
596 |
jpc_pi_destroy(pi); |
597 |
return 0; |
597 |
return 0; |
598 |
-- src/libjasper/jpc/jpc_tagtree.c |
598 |
++ src/libjasper/jpc/jpc_tagtree.c |
Lines 125-131
Link Here
|
125 |
++numlvls; |
125 |
++numlvls; |
126 |
} while (n > 1); |
126 |
} while (n > 1); |
127 |
|
127 |
|
128 |
if (!(tree->nodes_ = jas_malloc(tree->numnodes_ * sizeof(jpc_tagtreenode_t)))) { |
128 |
if (!(tree->nodes_ = jas_alloc2(tree->numnodes_, sizeof(jpc_tagtreenode_t)))) { |
129 |
return 0; |
129 |
return 0; |
130 |
} |
130 |
} |
131 |
|
131 |
|
132 |
-- src/libjasper/jpc/jpc_util.c |
132 |
++ src/libjasper/jpc/jpc_util.c |
Lines 109-115
Link Here
|
109 |
} |
109 |
} |
110 |
|
110 |
|
111 |
if (n) { |
111 |
if (n) { |
112 |
if (!(vs = jas_malloc(n * sizeof(double)))) { |
112 |
if (!(vs = jas_alloc2(n, sizeof(double)))) { |
113 |
return -1; |
113 |
return -1; |
114 |
} |
114 |
} |
115 |
|
115 |
|
116 |
-- src/libjasper/mif/mif_cod.c |
116 |
++ src/libjasper/mif/mif_cod.c |
Lines 438-445
Link Here
|
438 |
int cmptno; |
438 |
int cmptno; |
439 |
mif_cmpt_t **newcmpts; |
439 |
mif_cmpt_t **newcmpts; |
440 |
assert(maxcmpts >= hdr->numcmpts); |
440 |
assert(maxcmpts >= hdr->numcmpts); |
441 |
newcmpts = (!hdr->cmpts) ? jas_malloc(maxcmpts * sizeof(mif_cmpt_t *)) : |
441 |
newcmpts = jas_realloc2(hdr->cmpts, maxcmpts, sizeof(mif_cmpt_t *)); |
442 |
jas_realloc(hdr->cmpts, maxcmpts * sizeof(mif_cmpt_t *)); |
|
|
443 |
if (!newcmpts) { |
442 |
if (!newcmpts) { |
444 |
return -1; |
443 |
return -1; |
445 |
} |
444 |
} |
446 |
-- src/libjasper/pnm/pnm_enc.c |
445 |
++ src/libjasper/pnm/pnm_enc.c |
Lines 374-380
Link Here
|
374 |
} |
374 |
} |
375 |
} |
375 |
} |
376 |
} else { |
376 |
} else { |
377 |
n = sprintf(buf, "%s%ld", ((!(!x && !cmptno)) ? " " : ""), |
377 |
n = snprintf(buf, sizeof buf, "%s%ld", ((!(!x && !cmptno)) ? " " : ""), |
378 |
(long) v); |
378 |
(long) v); |
379 |
if (linelen > 0 && linelen + n > PNM_MAXLINELEN) { |
379 |
if (linelen > 0 && linelen + n > PNM_MAXLINELEN) { |
380 |
jas_stream_printf(out, "\n"); |
380 |
jas_stream_printf(out, "\n"); |