Contents of /trunk/libjasper/patches/libjasper-1.900.1-fixes-20081208.patch
Parent Directory | Revision Log
Revision 831 -
(show annotations)
(download)
Mon Jun 8 18:08:46 2009 UTC (15 years, 3 months ago) by niro
File size: 42347 byte(s)
Mon Jun 8 18:08:46 2009 UTC (15 years, 3 months ago) by niro
File size: 42347 byte(s)
patches for jasper
1 | diff -Naur jasper-1.900.1/acaux/install-sh jasper.fixed/acaux/install-sh |
2 | --- jasper-1.900.1/acaux/install-sh 2007-01-19 22:43:08.000000000 +0100 |
3 | +++ jasper.fixed/acaux/install-sh 2008-12-08 21:02:03.000000000 +0100 |
4 | @@ -192,7 +192,7 @@ |
5 | |
6 | if [ x"$dir_arg" != x ] |
7 | then |
8 | - $doit $instcmd $dst && |
9 | + { test -d $dst || $doit $instcmd $dst; } && |
10 | |
11 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi && |
12 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi && |
13 | diff -Naur jasper-1.900.1/acaux/ltmain.sh jasper.fixed/acaux/ltmain.sh |
14 | --- jasper-1.900.1/acaux/ltmain.sh 2007-01-19 22:54:42.000000000 +0100 |
15 | +++ jasper.fixed/acaux/ltmain.sh 2008-12-08 21:02:03.000000000 +0100 |
16 | @@ -57,6 +57,13 @@ |
17 | else |
18 | case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac |
19 | fi |
20 | +# Same for EGREP, and just to be sure, do LTCC as well |
21 | +if test "x$EGREP" = x ; then |
22 | + EGREP=egrep |
23 | +fi |
24 | +if test "x$LTCC" = x ; then |
25 | + LTCC=${CC-gcc} |
26 | +fi |
27 | |
28 | # Check that we have a working $echo. |
29 | if test "X$1" = X--no-reexec; then |
30 | @@ -5649,9 +5656,53 @@ |
31 | $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 |
32 | exit $EXIT_FAILURE |
33 | fi |
34 | - newdependency_libs="$newdependency_libs $libdir/$name" |
35 | + if test "x$EGREP" = x ; then |
36 | + EGREP=egrep |
37 | + fi |
38 | + # We do not want portage's install root ($D) present. Check only for |
39 | + # this if the .la is being installed. |
40 | + if test "$installed" = yes && test "$D"; then |
41 | + eval mynewdependency_lib=`echo "$libdir/$name" |sed -e "s:$D:/:g" -e 's:/\+:/:g'` |
42 | + else |
43 | + mynewdependency_lib="$libdir/$name" |
44 | + fi |
45 | + # Do not add duplicates |
46 | + if test "$mynewdependency_lib"; then |
47 | + my_little_ninja_foo_1=`echo $newdependency_libs |$EGREP -e "$mynewdependency_lib"` |
48 | + if test -z "$my_little_ninja_foo_1"; then |
49 | + newdependency_libs="$newdependency_libs $mynewdependency_lib" |
50 | + fi |
51 | + fi |
52 | + ;; |
53 | + *) |
54 | + if test "$installed" = yes; then |
55 | + # Rather use S=WORKDIR if our version of portage supports it. |
56 | + # This is because some ebuild (gcc) do not use $S as buildroot. |
57 | + if test "$PWORKDIR"; then |
58 | + S="$PWORKDIR" |
59 | + fi |
60 | + # We do not want portage's build root ($S) present. |
61 | + my_little_ninja_foo_2=`echo $deplib |$EGREP -e "$S"` |
62 | + # We do not want portage's install root ($D) present. |
63 | + my_little_ninja_foo_3=`echo $deplib |$EGREP -e "$D"` |
64 | + if test -n "$my_little_ninja_foo_2" && test "$S"; then |
65 | + mynewdependency_lib="" |
66 | + elif test -n "$my_little_ninja_foo_3" && test "$D"; then |
67 | + eval mynewdependency_lib=`echo "$deplib" |sed -e "s:$D:/:g" -e 's:/\+:/:g'` |
68 | + else |
69 | + mynewdependency_lib="$deplib" |
70 | + fi |
71 | + else |
72 | + mynewdependency_lib="$deplib" |
73 | + fi |
74 | + # Do not add duplicates |
75 | + if test "$mynewdependency_lib"; then |
76 | + my_little_ninja_foo_4=`echo $newdependency_libs |$EGREP -e "$mynewdependency_lib"` |
77 | + if test -z "$my_little_ninja_foo_4"; then |
78 | + newdependency_libs="$newdependency_libs $mynewdependency_lib" |
79 | + fi |
80 | + fi |
81 | ;; |
82 | - *) newdependency_libs="$newdependency_libs $deplib" ;; |
83 | esac |
84 | done |
85 | dependency_libs="$newdependency_libs" |
86 | @@ -5703,6 +5754,10 @@ |
87 | case $host,$output,$installed,$module,$dlname in |
88 | *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;; |
89 | esac |
90 | + # Do not add duplicates |
91 | + if test "$installed" = yes && test "$D"; then |
92 | + install_libdir=`echo "$install_libdir" |sed -e "s:$D:/:g" -e 's:/\+:/:g'` |
93 | + fi |
94 | $echo > $output "\ |
95 | # $outputname - a libtool library file |
96 | # Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP |
97 | diff -Naur jasper-1.900.1/src/libjasper/base/jas_cm.c jasper.fixed/src/libjasper/base/jas_cm.c |
98 | --- jasper-1.900.1/src/libjasper/base/jas_cm.c 2007-01-19 22:43:05.000000000 +0100 |
99 | +++ jasper.fixed/src/libjasper/base/jas_cm.c 2008-12-08 21:02:03.000000000 +0100 |
100 | @@ -704,8 +704,7 @@ |
101 | { |
102 | jas_cmpxform_t **p; |
103 | assert(n >= pxformseq->numpxforms); |
104 | - p = (!pxformseq->pxforms) ? jas_malloc(n * sizeof(jas_cmpxform_t *)) : |
105 | - jas_realloc(pxformseq->pxforms, n * sizeof(jas_cmpxform_t *)); |
106 | + p = jas_realloc2(pxformseq->pxforms, n, sizeof(jas_cmpxform_t *)); |
107 | if (!p) { |
108 | return -1; |
109 | } |
110 | @@ -889,13 +888,13 @@ |
111 | jas_cmshapmatlut_cleanup(lut); |
112 | if (curv->numents == 0) { |
113 | lut->size = 2; |
114 | - if (!(lut->data = jas_malloc(lut->size * sizeof(jas_cmreal_t)))) |
115 | + if (!(lut->data = jas_alloc2(lut->size, sizeof(jas_cmreal_t)))) |
116 | goto error; |
117 | lut->data[0] = 0.0; |
118 | lut->data[1] = 1.0; |
119 | } else if (curv->numents == 1) { |
120 | lut->size = 256; |
121 | - if (!(lut->data = jas_malloc(lut->size * sizeof(jas_cmreal_t)))) |
122 | + if (!(lut->data = jas_alloc2(lut->size, sizeof(jas_cmreal_t)))) |
123 | goto error; |
124 | gamma = curv->ents[0] / 256.0; |
125 | for (i = 0; i < lut->size; ++i) { |
126 | @@ -903,7 +902,7 @@ |
127 | } |
128 | } else { |
129 | lut->size = curv->numents; |
130 | - if (!(lut->data = jas_malloc(lut->size * sizeof(jas_cmreal_t)))) |
131 | + if (!(lut->data = jas_alloc2(lut->size, sizeof(jas_cmreal_t)))) |
132 | goto error; |
133 | for (i = 0; i < lut->size; ++i) { |
134 | lut->data[i] = curv->ents[i] / 65535.0; |
135 | @@ -953,7 +952,7 @@ |
136 | return -1; |
137 | } |
138 | } |
139 | - if (!(invlut->data = jas_malloc(n * sizeof(jas_cmreal_t)))) |
140 | + if (!(invlut->data = jas_alloc2(n, sizeof(jas_cmreal_t)))) |
141 | return -1; |
142 | invlut->size = n; |
143 | for (i = 0; i < invlut->size; ++i) { |
144 | diff -Naur jasper-1.900.1/src/libjasper/base/jas_icc.c jasper.fixed/src/libjasper/base/jas_icc.c |
145 | --- jasper-1.900.1/src/libjasper/base/jas_icc.c 2007-01-19 22:43:05.000000000 +0100 |
146 | +++ jasper.fixed/src/libjasper/base/jas_icc.c 2008-12-08 21:13:55.000000000 +0100 |
147 | @@ -373,7 +373,7 @@ |
148 | jas_icctagtab_t *tagtab; |
149 | |
150 | tagtab = &prof->tagtab; |
151 | - if (!(tagtab->ents = jas_malloc(prof->attrtab->numattrs * |
152 | + if (!(tagtab->ents = jas_alloc2(prof->attrtab->numattrs, |
153 | sizeof(jas_icctagtabent_t)))) |
154 | goto error; |
155 | tagtab->numents = prof->attrtab->numattrs; |
156 | @@ -522,7 +522,7 @@ |
157 | } |
158 | if (jas_iccgetuint32(in, &tagtab->numents)) |
159 | goto error; |
160 | - if (!(tagtab->ents = jas_malloc(tagtab->numents * |
161 | + if (!(tagtab->ents = jas_alloc2(tagtab->numents, |
162 | sizeof(jas_icctagtabent_t)))) |
163 | goto error; |
164 | tagtabent = tagtab->ents; |
165 | @@ -743,8 +743,7 @@ |
166 | { |
167 | jas_iccattr_t *newattrs; |
168 | assert(maxents >= tab->numattrs); |
169 | - newattrs = tab->attrs ? jas_realloc(tab->attrs, maxents * |
170 | - sizeof(jas_iccattr_t)) : jas_malloc(maxents * sizeof(jas_iccattr_t)); |
171 | + newattrs = jas_realloc2(tab->attrs, maxents, sizeof(jas_iccattr_t)); |
172 | if (!newattrs) |
173 | return -1; |
174 | tab->attrs = newattrs; |
175 | @@ -999,7 +998,7 @@ |
176 | |
177 | if (jas_iccgetuint32(in, &curv->numents)) |
178 | goto error; |
179 | - if (!(curv->ents = jas_malloc(curv->numents * sizeof(jas_iccuint16_t)))) |
180 | + if (!(curv->ents = jas_alloc2(curv->numents, sizeof(jas_iccuint16_t)))) |
181 | goto error; |
182 | for (i = 0; i < curv->numents; ++i) { |
183 | if (jas_iccgetuint16(in, &curv->ents[i])) |
184 | @@ -1100,7 +1099,7 @@ |
185 | if (jas_iccgetuint32(in, &txtdesc->uclangcode) || |
186 | jas_iccgetuint32(in, &txtdesc->uclen)) |
187 | goto error; |
188 | - if (!(txtdesc->ucdata = jas_malloc(txtdesc->uclen * 2))) |
189 | + if (!(txtdesc->ucdata = jas_alloc2(txtdesc->uclen, 2))) |
190 | goto error; |
191 | if (jas_stream_read(in, txtdesc->ucdata, txtdesc->uclen * 2) != |
192 | JAS_CAST(int, txtdesc->uclen * 2)) |
193 | @@ -1292,17 +1291,17 @@ |
194 | jas_iccgetuint16(in, &lut8->numouttabents)) |
195 | goto error; |
196 | clutsize = jas_iccpowi(lut8->clutlen, lut8->numinchans) * lut8->numoutchans; |
197 | - if (!(lut8->clut = jas_malloc(clutsize * sizeof(jas_iccuint8_t))) || |
198 | - !(lut8->intabsbuf = jas_malloc(lut8->numinchans * |
199 | - lut8->numintabents * sizeof(jas_iccuint8_t))) || |
200 | - !(lut8->intabs = jas_malloc(lut8->numinchans * |
201 | + if (!(lut8->clut = jas_alloc2(clutsize, sizeof(jas_iccuint8_t))) || |
202 | + !(lut8->intabsbuf = jas_alloc3(lut8->numinchans, |
203 | + lut8->numintabents, sizeof(jas_iccuint8_t))) || |
204 | + !(lut8->intabs = jas_alloc2(lut8->numinchans, |
205 | sizeof(jas_iccuint8_t *)))) |
206 | goto error; |
207 | for (i = 0; i < lut8->numinchans; ++i) |
208 | lut8->intabs[i] = &lut8->intabsbuf[i * lut8->numintabents]; |
209 | - if (!(lut8->outtabsbuf = jas_malloc(lut8->numoutchans * |
210 | - lut8->numouttabents * sizeof(jas_iccuint8_t))) || |
211 | - !(lut8->outtabs = jas_malloc(lut8->numoutchans * |
212 | + if (!(lut8->outtabsbuf = jas_alloc3(lut8->numoutchans, |
213 | + lut8->numouttabents, sizeof(jas_iccuint8_t))) || |
214 | + !(lut8->outtabs = jas_alloc2(lut8->numoutchans, |
215 | sizeof(jas_iccuint8_t *)))) |
216 | goto error; |
217 | for (i = 0; i < lut8->numoutchans; ++i) |
218 | @@ -1461,17 +1460,17 @@ |
219 | jas_iccgetuint16(in, &lut16->numouttabents)) |
220 | goto error; |
221 | clutsize = jas_iccpowi(lut16->clutlen, lut16->numinchans) * lut16->numoutchans; |
222 | - if (!(lut16->clut = jas_malloc(clutsize * sizeof(jas_iccuint16_t))) || |
223 | - !(lut16->intabsbuf = jas_malloc(lut16->numinchans * |
224 | - lut16->numintabents * sizeof(jas_iccuint16_t))) || |
225 | - !(lut16->intabs = jas_malloc(lut16->numinchans * |
226 | + if (!(lut16->clut = jas_alloc2(clutsize, sizeof(jas_iccuint16_t))) || |
227 | + !(lut16->intabsbuf = jas_alloc3(lut16->numinchans, |
228 | + lut16->numintabents, sizeof(jas_iccuint16_t))) || |
229 | + !(lut16->intabs = jas_alloc2(lut16->numinchans, |
230 | sizeof(jas_iccuint16_t *)))) |
231 | goto error; |
232 | for (i = 0; i < lut16->numinchans; ++i) |
233 | lut16->intabs[i] = &lut16->intabsbuf[i * lut16->numintabents]; |
234 | - if (!(lut16->outtabsbuf = jas_malloc(lut16->numoutchans * |
235 | - lut16->numouttabents * sizeof(jas_iccuint16_t))) || |
236 | - !(lut16->outtabs = jas_malloc(lut16->numoutchans * |
237 | + if (!(lut16->outtabsbuf = jas_alloc3(lut16->numoutchans, |
238 | + lut16->numouttabents, sizeof(jas_iccuint16_t))) || |
239 | + !(lut16->outtabs = jas_alloc2(lut16->numoutchans, |
240 | sizeof(jas_iccuint16_t *)))) |
241 | goto error; |
242 | for (i = 0; i < lut16->numoutchans; ++i) |
243 | diff -Naur jasper-1.900.1/src/libjasper/base/jas_image.c jasper.fixed/src/libjasper/base/jas_image.c |
244 | --- jasper-1.900.1/src/libjasper/base/jas_image.c 2007-01-19 22:43:05.000000000 +0100 |
245 | +++ jasper.fixed/src/libjasper/base/jas_image.c 2008-12-08 21:02:03.000000000 +0100 |
246 | @@ -142,7 +142,7 @@ |
247 | image->inmem_ = true; |
248 | |
249 | /* Allocate memory for the per-component information. */ |
250 | - if (!(image->cmpts_ = jas_malloc(image->maxcmpts_ * |
251 | + if (!(image->cmpts_ = jas_alloc2(image->maxcmpts_, |
252 | sizeof(jas_image_cmpt_t *)))) { |
253 | jas_image_destroy(image); |
254 | return 0; |
255 | @@ -774,8 +774,7 @@ |
256 | jas_image_cmpt_t **newcmpts; |
257 | int cmptno; |
258 | |
259 | - newcmpts = (!image->cmpts_) ? jas_malloc(maxcmpts * sizeof(jas_image_cmpt_t *)) : |
260 | - jas_realloc(image->cmpts_, maxcmpts * sizeof(jas_image_cmpt_t *)); |
261 | + newcmpts = jas_realloc2(image->cmpts_, maxcmpts, sizeof(jas_image_cmpt_t *)); |
262 | if (!newcmpts) { |
263 | return -1; |
264 | } |
265 | diff -Naur jasper-1.900.1/src/libjasper/base/jas_malloc.c jasper.fixed/src/libjasper/base/jas_malloc.c |
266 | --- jasper-1.900.1/src/libjasper/base/jas_malloc.c 2007-01-19 22:43:05.000000000 +0100 |
267 | +++ jasper.fixed/src/libjasper/base/jas_malloc.c 2008-12-08 21:02:03.000000000 +0100 |
268 | @@ -76,6 +76,9 @@ |
269 | |
270 | /* We need the prototype for memset. */ |
271 | #include <string.h> |
272 | +#include <limits.h> |
273 | +#include <errno.h> |
274 | +#include <stdint.h> |
275 | |
276 | #include "jasper/jas_malloc.h" |
277 | |
278 | @@ -113,18 +116,50 @@ |
279 | |
280 | void *jas_realloc(void *ptr, size_t size) |
281 | { |
282 | - return realloc(ptr, size); |
283 | + return ptr ? realloc(ptr, size) : malloc(size); |
284 | } |
285 | |
286 | -void *jas_calloc(size_t nmemb, size_t size) |
287 | +void *jas_realloc2(void *ptr, size_t nmemb, size_t size) |
288 | +{ |
289 | + if (!ptr) |
290 | + return jas_alloc2(nmemb, size); |
291 | + if (nmemb && SIZE_MAX / nmemb < size) { |
292 | + errno = ENOMEM; |
293 | + return NULL; |
294 | + } |
295 | + return jas_realloc(ptr, nmemb * size); |
296 | + |
297 | +} |
298 | + |
299 | +void *jas_alloc2(size_t nmemb, size_t size) |
300 | +{ |
301 | + if (nmemb && SIZE_MAX / nmemb < size) { |
302 | + errno = ENOMEM; |
303 | + return NULL; |
304 | + } |
305 | + |
306 | + return jas_malloc(nmemb * size); |
307 | +} |
308 | + |
309 | +void *jas_alloc3(size_t a, size_t b, size_t c) |
310 | { |
311 | - void *ptr; |
312 | size_t n; |
313 | - n = nmemb * size; |
314 | - if (!(ptr = jas_malloc(n * sizeof(char)))) { |
315 | - return 0; |
316 | + |
317 | + if (a && SIZE_MAX / a < b) { |
318 | + errno = ENOMEM; |
319 | + return NULL; |
320 | } |
321 | - memset(ptr, 0, n); |
322 | + |
323 | + return jas_alloc2(a*b, c); |
324 | +} |
325 | + |
326 | +void *jas_calloc(size_t nmemb, size_t size) |
327 | +{ |
328 | + void *ptr; |
329 | + |
330 | + ptr = jas_alloc2(nmemb, size); |
331 | + if (ptr) |
332 | + memset(ptr, 0, nmemb*size); |
333 | return ptr; |
334 | } |
335 | |
336 | diff -Naur jasper-1.900.1/src/libjasper/base/jas_seq.c jasper.fixed/src/libjasper/base/jas_seq.c |
337 | --- jasper-1.900.1/src/libjasper/base/jas_seq.c 2007-01-19 22:43:05.000000000 +0100 |
338 | +++ jasper.fixed/src/libjasper/base/jas_seq.c 2008-12-08 21:02:03.000000000 +0100 |
339 | @@ -114,7 +114,7 @@ |
340 | matrix->datasize_ = numrows * numcols; |
341 | |
342 | if (matrix->maxrows_ > 0) { |
343 | - if (!(matrix->rows_ = jas_malloc(matrix->maxrows_ * |
344 | + if (!(matrix->rows_ = jas_alloc2(matrix->maxrows_, |
345 | sizeof(jas_seqent_t *)))) { |
346 | jas_matrix_destroy(matrix); |
347 | return 0; |
348 | @@ -122,7 +122,7 @@ |
349 | } |
350 | |
351 | if (matrix->datasize_ > 0) { |
352 | - if (!(matrix->data_ = jas_malloc(matrix->datasize_ * |
353 | + if (!(matrix->data_ = jas_alloc2(matrix->datasize_, |
354 | sizeof(jas_seqent_t)))) { |
355 | jas_matrix_destroy(matrix); |
356 | return 0; |
357 | @@ -220,7 +220,7 @@ |
358 | mat0->numrows_ = r1 - r0 + 1; |
359 | mat0->numcols_ = c1 - c0 + 1; |
360 | mat0->maxrows_ = mat0->numrows_; |
361 | - mat0->rows_ = jas_malloc(mat0->maxrows_ * sizeof(jas_seqent_t *)); |
362 | + mat0->rows_ = jas_alloc2(mat0->maxrows_, sizeof(jas_seqent_t *)); |
363 | for (i = 0; i < mat0->numrows_; ++i) { |
364 | mat0->rows_[i] = mat1->rows_[r0 + i] + c0; |
365 | } |
366 | @@ -432,7 +432,8 @@ |
367 | for (i = 0; i < jas_matrix_numrows(matrix); ++i) { |
368 | for (j = 0; j < jas_matrix_numcols(matrix); ++j) { |
369 | x = jas_matrix_get(matrix, i, j); |
370 | - sprintf(sbuf, "%s%4ld", (strlen(buf) > 0) ? " " : "", |
371 | + snprintf(sbuf, sizeof sbuf, |
372 | + "%s%4ld", (strlen(buf) > 0) ? " " : "", |
373 | JAS_CAST(long, x)); |
374 | n = strlen(buf); |
375 | if (n + strlen(sbuf) > MAXLINELEN) { |
376 | diff -Naur jasper-1.900.1/src/libjasper/base/jas_stream.c jasper.fixed/src/libjasper/base/jas_stream.c |
377 | --- jasper-1.900.1/src/libjasper/base/jas_stream.c 2007-01-19 22:43:05.000000000 +0100 |
378 | +++ jasper.fixed/src/libjasper/base/jas_stream.c 2008-12-08 21:15:38.000000000 +0100 |
379 | @@ -212,7 +212,7 @@ |
380 | if (buf) { |
381 | obj->buf_ = (unsigned char *) buf; |
382 | } else { |
383 | - obj->buf_ = jas_malloc(obj->bufsize_ * sizeof(char)); |
384 | + obj->buf_ = jas_malloc(obj->bufsize_); |
385 | obj->myalloc_ = 1; |
386 | } |
387 | if (!obj->buf_) { |
388 | @@ -361,28 +361,22 @@ |
389 | } |
390 | obj->fd = -1; |
391 | obj->flags = 0; |
392 | - obj->pathname[0] = '\0'; |
393 | stream->obj_ = obj; |
394 | |
395 | /* Choose a file name. */ |
396 | - tmpnam(obj->pathname); |
397 | + snprintf(obj->pathname, L_tmpnam, "%s/tmp.XXXXXXXXXX", P_tmpdir); |
398 | |
399 | /* Open the underlying file. */ |
400 | - if ((obj->fd = open(obj->pathname, O_CREAT | O_EXCL | O_RDWR | O_TRUNC | O_BINARY, |
401 | - JAS_STREAM_PERMS)) < 0) { |
402 | + if ((obj->fd = mkstemp(obj->pathname)) < 0) { |
403 | jas_stream_destroy(stream); |
404 | return 0; |
405 | } |
406 | |
407 | /* Unlink the file so that it will disappear if the program |
408 | terminates abnormally. */ |
409 | - /* Under UNIX, one can unlink an open file and continue to do I/O |
410 | - on it. Not all operating systems support this functionality, however. |
411 | - For example, under Microsoft Windows the unlink operation will fail, |
412 | - since the file is open. */ |
413 | if (unlink(obj->pathname)) { |
414 | - /* We will try unlinking the file again after it is closed. */ |
415 | - obj->flags |= JAS_STREAM_FILEOBJ_DELONCLOSE; |
416 | + jas_stream_destroy(stream); |
417 | + return 0; |
418 | } |
419 | |
420 | /* Use full buffering. */ |
421 | @@ -553,7 +547,7 @@ |
422 | int ret; |
423 | |
424 | va_start(ap, fmt); |
425 | - ret = vsprintf(buf, fmt, ap); |
426 | + ret = vsnprintf(buf, sizeof buf, fmt, ap); |
427 | jas_stream_puts(stream, buf); |
428 | va_end(ap); |
429 | return ret; |
430 | @@ -992,7 +986,7 @@ |
431 | unsigned char *buf; |
432 | |
433 | assert(m->buf_); |
434 | - if (!(buf = jas_realloc(m->buf_, bufsize * sizeof(unsigned char)))) { |
435 | + if (!(buf = jas_realloc(m->buf_, bufsize))) { |
436 | return -1; |
437 | } |
438 | m->buf_ = buf; |
439 | diff -Naur jasper-1.900.1/src/libjasper/bmp/bmp_dec.c jasper.fixed/src/libjasper/bmp/bmp_dec.c |
440 | --- jasper-1.900.1/src/libjasper/bmp/bmp_dec.c 2007-01-19 22:43:07.000000000 +0100 |
441 | +++ jasper.fixed/src/libjasper/bmp/bmp_dec.c 2008-12-08 21:02:03.000000000 +0100 |
442 | @@ -283,7 +283,7 @@ |
443 | } |
444 | |
445 | if (info->numcolors > 0) { |
446 | - if (!(info->palents = jas_malloc(info->numcolors * |
447 | + if (!(info->palents = jas_alloc2(info->numcolors, |
448 | sizeof(bmp_palent_t)))) { |
449 | bmp_info_destroy(info); |
450 | return 0; |
451 | diff -Naur jasper-1.900.1/src/libjasper/include/jasper/jas_malloc.h jasper.fixed/src/libjasper/include/jasper/jas_malloc.h |
452 | --- jasper-1.900.1/src/libjasper/include/jasper/jas_malloc.h 2007-01-19 22:43:04.000000000 +0100 |
453 | +++ jasper.fixed/src/libjasper/include/jasper/jas_malloc.h 2008-12-08 21:02:03.000000000 +0100 |
454 | @@ -95,6 +95,9 @@ |
455 | #define jas_free MEMFREE |
456 | #define jas_realloc MEMREALLOC |
457 | #define jas_calloc MEMCALLOC |
458 | +#define jas_alloc2(a, b) MEMALLOC((a)*(b)) |
459 | +#define jas_alloc3(a, b, c) MEMALLOC((a)*(b)*(c)) |
460 | +#define jas_realloc2(p, a, b) MEMREALLOC((p), (a)*(b)) |
461 | #endif |
462 | |
463 | /******************************************************************************\ |
464 | @@ -115,6 +118,12 @@ |
465 | /* Allocate a block of memory and initialize the contents to zero. */ |
466 | void *jas_calloc(size_t nmemb, size_t size); |
467 | |
468 | +/* size-checked double allocation .*/ |
469 | +void *jas_alloc2(size_t, size_t); |
470 | + |
471 | +void *jas_alloc3(size_t, size_t, size_t); |
472 | + |
473 | +void *jas_realloc2(void *, size_t, size_t); |
474 | #endif |
475 | |
476 | #ifdef __cplusplus |
477 | diff -Naur jasper-1.900.1/src/libjasper/jp2/jp2_cod.c jasper.fixed/src/libjasper/jp2/jp2_cod.c |
478 | --- jasper-1.900.1/src/libjasper/jp2/jp2_cod.c 2007-01-19 22:43:05.000000000 +0100 |
479 | +++ jasper.fixed/src/libjasper/jp2/jp2_cod.c 2008-12-08 21:13:55.000000000 +0100 |
480 | @@ -372,7 +372,7 @@ |
481 | jp2_bpcc_t *bpcc = &box->data.bpcc; |
482 | unsigned int i; |
483 | bpcc->numcmpts = box->datalen; |
484 | - if (!(bpcc->bpcs = jas_malloc(bpcc->numcmpts * sizeof(uint_fast8_t)))) { |
485 | + if (!(bpcc->bpcs = jas_alloc2(bpcc->numcmpts, sizeof(uint_fast8_t)))) { |
486 | return -1; |
487 | } |
488 | for (i = 0; i < bpcc->numcmpts; ++i) { |
489 | @@ -416,7 +416,7 @@ |
490 | break; |
491 | case JP2_COLR_ICC: |
492 | colr->iccplen = box->datalen - 3; |
493 | - if (!(colr->iccp = jas_malloc(colr->iccplen * sizeof(uint_fast8_t)))) { |
494 | + if (!(colr->iccp = jas_alloc2(colr->iccplen, sizeof(uint_fast8_t)))) { |
495 | return -1; |
496 | } |
497 | if (jas_stream_read(in, colr->iccp, colr->iccplen) != colr->iccplen) { |
498 | @@ -453,7 +453,7 @@ |
499 | if (jp2_getuint16(in, &cdef->numchans)) { |
500 | return -1; |
501 | } |
502 | - if (!(cdef->ents = jas_malloc(cdef->numchans * sizeof(jp2_cdefchan_t)))) { |
503 | + if (!(cdef->ents = jas_alloc2(cdef->numchans, sizeof(jp2_cdefchan_t)))) { |
504 | return -1; |
505 | } |
506 | for (channo = 0; channo < cdef->numchans; ++channo) { |
507 | @@ -766,7 +766,7 @@ |
508 | unsigned int i; |
509 | |
510 | cmap->numchans = (box->datalen) / 4; |
511 | - if (!(cmap->ents = jas_malloc(cmap->numchans * sizeof(jp2_cmapent_t)))) { |
512 | + if (!(cmap->ents = jas_alloc2(cmap->numchans, sizeof(jp2_cmapent_t)))) { |
513 | return -1; |
514 | } |
515 | for (i = 0; i < cmap->numchans; ++i) { |
516 | @@ -795,11 +795,15 @@ |
517 | jp2_cmap_t *cmap = &box->data.cmap; |
518 | unsigned int i; |
519 | jp2_cmapent_t *ent; |
520 | - fprintf(out, "numchans = %d\n", (int) cmap->numchans); |
521 | + if (jas_getdbglevel() >= 1) { |
522 | + fprintf(out, "numchans = %d\n", (int) cmap->numchans); |
523 | + } |
524 | for (i = 0; i < cmap->numchans; ++i) { |
525 | ent = &cmap->ents[i]; |
526 | - fprintf(out, "cmptno=%d; map=%d; pcol=%d\n", |
527 | - (int) ent->cmptno, (int) ent->map, (int) ent->pcol); |
528 | + if (jas_getdbglevel() >= 1) { |
529 | + fprintf(out, "cmptno=%d; map=%d; pcol=%d\n", |
530 | + (int) ent->cmptno, (int) ent->map, (int) ent->pcol); |
531 | + } |
532 | } |
533 | } |
534 | |
535 | @@ -828,10 +832,10 @@ |
536 | return -1; |
537 | } |
538 | lutsize = pclr->numlutents * pclr->numchans; |
539 | - if (!(pclr->lutdata = jas_malloc(lutsize * sizeof(int_fast32_t)))) { |
540 | + if (!(pclr->lutdata = jas_alloc2(lutsize, sizeof(int_fast32_t)))) { |
541 | return -1; |
542 | } |
543 | - if (!(pclr->bpc = jas_malloc(pclr->numchans * sizeof(uint_fast8_t)))) { |
544 | + if (!(pclr->bpc = jas_alloc2(pclr->numchans, sizeof(uint_fast8_t)))) { |
545 | return -1; |
546 | } |
547 | for (i = 0; i < pclr->numchans; ++i) { |
548 | diff -Naur jasper-1.900.1/src/libjasper/jp2/jp2_dec.c jasper.fixed/src/libjasper/jp2/jp2_dec.c |
549 | --- jasper-1.900.1/src/libjasper/jp2/jp2_dec.c 2007-01-19 22:43:05.000000000 +0100 |
550 | +++ jasper.fixed/src/libjasper/jp2/jp2_dec.c 2008-12-08 21:13:55.000000000 +0100 |
551 | @@ -293,7 +293,9 @@ |
552 | dec->colr->data.colr.iccplen); |
553 | assert(iccprof); |
554 | jas_iccprof_gethdr(iccprof, &icchdr); |
555 | - jas_eprintf("ICC Profile CS %08x\n", icchdr.colorspc); |
556 | + if (jas_getdbglevel() >= 1) { |
557 | + jas_eprintf("ICC Profile CS %08x\n", icchdr.colorspc); |
558 | + } |
559 | jas_image_setclrspc(dec->image, fromiccpcs(icchdr.colorspc)); |
560 | dec->image->cmprof_ = jas_cmprof_createfromiccprof(iccprof); |
561 | assert(dec->image->cmprof_); |
562 | @@ -336,7 +338,7 @@ |
563 | } |
564 | |
565 | /* Allocate space for the channel-number to component-number LUT. */ |
566 | - if (!(dec->chantocmptlut = jas_malloc(dec->numchans * sizeof(uint_fast16_t)))) { |
567 | + if (!(dec->chantocmptlut = jas_alloc2(dec->numchans, sizeof(uint_fast16_t)))) { |
568 | jas_eprintf("error: no memory\n"); |
569 | goto error; |
570 | } |
571 | @@ -354,7 +356,7 @@ |
572 | if (cmapent->map == JP2_CMAP_DIRECT) { |
573 | dec->chantocmptlut[channo] = channo; |
574 | } else if (cmapent->map == JP2_CMAP_PALETTE) { |
575 | - lutents = jas_malloc(pclrd->numlutents * sizeof(int_fast32_t)); |
576 | + lutents = jas_alloc2(pclrd->numlutents, sizeof(int_fast32_t)); |
577 | for (i = 0; i < pclrd->numlutents; ++i) { |
578 | lutents[i] = pclrd->lutdata[cmapent->pcol + i * pclrd->numchans]; |
579 | } |
580 | diff -Naur jasper-1.900.1/src/libjasper/jp2/jp2_enc.c jasper.fixed/src/libjasper/jp2/jp2_enc.c |
581 | --- jasper-1.900.1/src/libjasper/jp2/jp2_enc.c 2007-01-19 22:43:05.000000000 +0100 |
582 | +++ jasper.fixed/src/libjasper/jp2/jp2_enc.c 2008-12-08 21:02:03.000000000 +0100 |
583 | @@ -191,7 +191,7 @@ |
584 | } |
585 | bpcc = &box->data.bpcc; |
586 | bpcc->numcmpts = jas_image_numcmpts(image); |
587 | - if (!(bpcc->bpcs = jas_malloc(bpcc->numcmpts * |
588 | + if (!(bpcc->bpcs = jas_alloc2(bpcc->numcmpts, |
589 | sizeof(uint_fast8_t)))) { |
590 | goto error; |
591 | } |
592 | @@ -285,7 +285,7 @@ |
593 | } |
594 | cdef = &box->data.cdef; |
595 | cdef->numchans = jas_image_numcmpts(image); |
596 | - cdef->ents = jas_malloc(cdef->numchans * sizeof(jp2_cdefchan_t)); |
597 | + cdef->ents = jas_alloc2(cdef->numchans, sizeof(jp2_cdefchan_t)); |
598 | for (i = 0; i < jas_image_numcmpts(image); ++i) { |
599 | cdefchanent = &cdef->ents[i]; |
600 | cdefchanent->channo = i; |
601 | @@ -343,7 +343,8 @@ |
602 | /* Output the JPEG-2000 code stream. */ |
603 | |
604 | overhead = jas_stream_getrwcount(out); |
605 | - sprintf(buf, "%s\n_jp2overhead=%lu\n", (optstr ? optstr : ""), |
606 | + snprintf(buf, sizeof buf, "%s\n_jp2overhead=%lu\n", |
607 | + (optstr ? optstr : ""), |
608 | (unsigned long) overhead); |
609 | |
610 | if (jpc_encode(image, out, buf)) { |
611 | diff -Naur jasper-1.900.1/src/libjasper/jpc/jpc_cs.c jasper.fixed/src/libjasper/jpc/jpc_cs.c |
612 | --- jasper-1.900.1/src/libjasper/jpc/jpc_cs.c 2007-01-19 22:43:07.000000000 +0100 |
613 | +++ jasper.fixed/src/libjasper/jpc/jpc_cs.c 2008-12-08 21:02:03.000000000 +0100 |
614 | @@ -502,7 +502,7 @@ |
615 | !siz->tileheight || !siz->numcomps) { |
616 | return -1; |
617 | } |
618 | - if (!(siz->comps = jas_malloc(siz->numcomps * sizeof(jpc_sizcomp_t)))) { |
619 | + if (!(siz->comps = jas_alloc2(siz->numcomps, sizeof(jpc_sizcomp_t)))) { |
620 | return -1; |
621 | } |
622 | for (i = 0; i < siz->numcomps; ++i) { |
623 | @@ -982,8 +982,11 @@ |
624 | compparms->numstepsizes = (len - n) / 2; |
625 | break; |
626 | } |
627 | - if (compparms->numstepsizes > 0) { |
628 | - compparms->stepsizes = jas_malloc(compparms->numstepsizes * |
629 | + if (compparms->numstepsizes > 3 * JPC_MAXRLVLS + 1) { |
630 | + jpc_qcx_destroycompparms(compparms); |
631 | + return -1; |
632 | + } else if (compparms->numstepsizes > 0) { |
633 | + compparms->stepsizes = jas_alloc2(compparms->numstepsizes, |
634 | sizeof(uint_fast16_t)); |
635 | assert(compparms->stepsizes); |
636 | for (i = 0; i < compparms->numstepsizes; ++i) { |
637 | @@ -1091,7 +1094,7 @@ |
638 | |
639 | ppm->len = ms->len - 1; |
640 | if (ppm->len > 0) { |
641 | - if (!(ppm->data = jas_malloc(ppm->len * sizeof(unsigned char)))) { |
642 | + if (!(ppm->data = jas_malloc(ppm->len))) { |
643 | goto error; |
644 | } |
645 | if (JAS_CAST(uint, jas_stream_read(in, ppm->data, ppm->len)) != ppm->len) { |
646 | @@ -1160,7 +1163,7 @@ |
647 | } |
648 | ppt->len = ms->len - 1; |
649 | if (ppt->len > 0) { |
650 | - if (!(ppt->data = jas_malloc(ppt->len * sizeof(unsigned char)))) { |
651 | + if (!(ppt->data = jas_malloc(ppt->len))) { |
652 | goto error; |
653 | } |
654 | if (jas_stream_read(in, (char *) ppt->data, ppt->len) != JAS_CAST(int, ppt->len)) { |
655 | @@ -1223,7 +1226,7 @@ |
656 | uint_fast8_t tmp; |
657 | poc->numpchgs = (cstate->numcomps > 256) ? (ms->len / 9) : |
658 | (ms->len / 7); |
659 | - if (!(poc->pchgs = jas_malloc(poc->numpchgs * sizeof(jpc_pocpchg_t)))) { |
660 | + if (!(poc->pchgs = jas_alloc2(poc->numpchgs, sizeof(jpc_pocpchg_t)))) { |
661 | goto error; |
662 | } |
663 | for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; ++pchgno, |
664 | @@ -1328,7 +1331,7 @@ |
665 | jpc_crgcomp_t *comp; |
666 | uint_fast16_t compno; |
667 | crg->numcomps = cstate->numcomps; |
668 | - if (!(crg->comps = jas_malloc(cstate->numcomps * sizeof(uint_fast16_t)))) { |
669 | + if (!(crg->comps = jas_alloc2(cstate->numcomps, sizeof(uint_fast16_t)))) { |
670 | return -1; |
671 | } |
672 | for (compno = 0, comp = crg->comps; compno < cstate->numcomps; |
673 | @@ -1467,7 +1470,7 @@ |
674 | cstate = 0; |
675 | |
676 | if (ms->len > 0) { |
677 | - if (!(unk->data = jas_malloc(ms->len * sizeof(unsigned char)))) { |
678 | + if (!(unk->data = jas_malloc(ms->len))) { |
679 | return -1; |
680 | } |
681 | if (jas_stream_read(in, (char *) unk->data, ms->len) != JAS_CAST(int, ms->len)) { |
682 | diff -Naur jasper-1.900.1/src/libjasper/jpc/jpc_dec.c jasper.fixed/src/libjasper/jpc/jpc_dec.c |
683 | --- jasper-1.900.1/src/libjasper/jpc/jpc_dec.c 2007-01-19 22:43:07.000000000 +0100 |
684 | +++ jasper.fixed/src/libjasper/jpc/jpc_dec.c 2008-12-08 21:13:55.000000000 +0100 |
685 | @@ -449,7 +449,7 @@ |
686 | |
687 | if (dec->state == JPC_MH) { |
688 | |
689 | - compinfos = jas_malloc(dec->numcomps * sizeof(jas_image_cmptparm_t)); |
690 | + compinfos = jas_alloc2(dec->numcomps, sizeof(jas_image_cmptparm_t)); |
691 | assert(compinfos); |
692 | for (cmptno = 0, cmpt = dec->cmpts, compinfo = compinfos; |
693 | cmptno < dec->numcomps; ++cmptno, ++cmpt, ++compinfo) { |
694 | @@ -692,7 +692,7 @@ |
695 | tile->realmode = 1; |
696 | } |
697 | tcomp->numrlvls = ccp->numrlvls; |
698 | - if (!(tcomp->rlvls = jas_malloc(tcomp->numrlvls * |
699 | + if (!(tcomp->rlvls = jas_alloc2(tcomp->numrlvls, |
700 | sizeof(jpc_dec_rlvl_t)))) { |
701 | return -1; |
702 | } |
703 | @@ -764,7 +764,7 @@ |
704 | rlvl->cbgheightexpn); |
705 | |
706 | rlvl->numbands = (!rlvlno) ? 1 : 3; |
707 | - if (!(rlvl->bands = jas_malloc(rlvl->numbands * |
708 | + if (!(rlvl->bands = jas_alloc2(rlvl->numbands, |
709 | sizeof(jpc_dec_band_t)))) { |
710 | return -1; |
711 | } |
712 | @@ -797,7 +797,7 @@ |
713 | |
714 | assert(rlvl->numprcs); |
715 | |
716 | - if (!(band->prcs = jas_malloc(rlvl->numprcs * sizeof(jpc_dec_prc_t)))) { |
717 | + if (!(band->prcs = jas_alloc2(rlvl->numprcs, sizeof(jpc_dec_prc_t)))) { |
718 | return -1; |
719 | } |
720 | |
721 | @@ -834,7 +834,7 @@ |
722 | if (!(prc->numimsbstagtree = jpc_tagtree_create(prc->numhcblks, prc->numvcblks))) { |
723 | return -1; |
724 | } |
725 | - if (!(prc->cblks = jas_malloc(prc->numcblks * sizeof(jpc_dec_cblk_t)))) { |
726 | + if (!(prc->cblks = jas_alloc2(prc->numcblks, sizeof(jpc_dec_cblk_t)))) { |
727 | return -1; |
728 | } |
729 | |
730 | @@ -1181,7 +1181,7 @@ |
731 | return -1; |
732 | } |
733 | |
734 | - if (!(dec->cmpts = jas_malloc(dec->numcomps * sizeof(jpc_dec_cmpt_t)))) { |
735 | + if (!(dec->cmpts = jas_alloc2(dec->numcomps, sizeof(jpc_dec_cmpt_t)))) { |
736 | return -1; |
737 | } |
738 | |
739 | @@ -1204,7 +1204,7 @@ |
740 | dec->numhtiles = JPC_CEILDIV(dec->xend - dec->tilexoff, dec->tilewidth); |
741 | dec->numvtiles = JPC_CEILDIV(dec->yend - dec->tileyoff, dec->tileheight); |
742 | dec->numtiles = dec->numhtiles * dec->numvtiles; |
743 | - if (!(dec->tiles = jas_malloc(dec->numtiles * sizeof(jpc_dec_tile_t)))) { |
744 | + if (!(dec->tiles = jas_alloc2(dec->numtiles, sizeof(jpc_dec_tile_t)))) { |
745 | return -1; |
746 | } |
747 | |
748 | @@ -1228,7 +1228,7 @@ |
749 | tile->pkthdrstreampos = 0; |
750 | tile->pptstab = 0; |
751 | tile->cp = 0; |
752 | - if (!(tile->tcomps = jas_malloc(dec->numcomps * |
753 | + if (!(tile->tcomps = jas_alloc2(dec->numcomps, |
754 | sizeof(jpc_dec_tcomp_t)))) { |
755 | return -1; |
756 | } |
757 | @@ -1466,7 +1466,9 @@ |
758 | dec = 0; |
759 | |
760 | jas_eprintf("warning: ignoring unknown marker segment\n"); |
761 | - jpc_ms_dump(ms, stderr); |
762 | + if (jas_getdbglevel() >= 1) { |
763 | + jpc_ms_dump(ms, stderr); |
764 | + } |
765 | return 0; |
766 | } |
767 | |
768 | @@ -1489,7 +1491,7 @@ |
769 | cp->numlyrs = 0; |
770 | cp->mctid = 0; |
771 | cp->csty = 0; |
772 | - if (!(cp->ccps = jas_malloc(cp->numcomps * sizeof(jpc_dec_ccp_t)))) { |
773 | + if (!(cp->ccps = jas_alloc2(cp->numcomps, sizeof(jpc_dec_ccp_t)))) { |
774 | return 0; |
775 | } |
776 | if (!(cp->pchglist = jpc_pchglist_create())) { |
777 | @@ -2048,7 +2050,7 @@ |
778 | } |
779 | streamlist->numstreams = 0; |
780 | streamlist->maxstreams = 100; |
781 | - if (!(streamlist->streams = jas_malloc(streamlist->maxstreams * |
782 | + if (!(streamlist->streams = jas_alloc2(streamlist->maxstreams, |
783 | sizeof(jas_stream_t *)))) { |
784 | jas_free(streamlist); |
785 | return 0; |
786 | @@ -2068,8 +2070,8 @@ |
787 | /* Grow the array of streams if necessary. */ |
788 | if (streamlist->numstreams >= streamlist->maxstreams) { |
789 | newmaxstreams = streamlist->maxstreams + 1024; |
790 | - if (!(newstreams = jas_realloc(streamlist->streams, |
791 | - (newmaxstreams + 1024) * sizeof(jas_stream_t *)))) { |
792 | + if (!(newstreams = jas_realloc2(streamlist->streams, |
793 | + (newmaxstreams + 1024), sizeof(jas_stream_t *)))) { |
794 | return -1; |
795 | } |
796 | for (i = streamlist->numstreams; i < streamlist->maxstreams; ++i) { |
797 | @@ -2155,8 +2157,7 @@ |
798 | { |
799 | jpc_ppxstabent_t **newents; |
800 | if (tab->maxents < maxents) { |
801 | - newents = (tab->ents) ? jas_realloc(tab->ents, maxents * |
802 | - sizeof(jpc_ppxstabent_t *)) : jas_malloc(maxents * sizeof(jpc_ppxstabent_t *)); |
803 | + newents = jas_realloc2(tab->ents, maxents, sizeof(jpc_ppxstabent_t *)); |
804 | if (!newents) { |
805 | return -1; |
806 | } |
807 | diff -Naur jasper-1.900.1/src/libjasper/jpc/jpc_enc.c jasper.fixed/src/libjasper/jpc/jpc_enc.c |
808 | --- jasper-1.900.1/src/libjasper/jpc/jpc_enc.c 2007-01-19 22:43:07.000000000 +0100 |
809 | +++ jasper.fixed/src/libjasper/jpc/jpc_enc.c 2008-12-08 21:02:03.000000000 +0100 |
810 | @@ -403,7 +403,7 @@ |
811 | vsteplcm *= jas_image_cmptvstep(image, cmptno); |
812 | } |
813 | |
814 | - if (!(cp->ccps = jas_malloc(cp->numcmpts * sizeof(jpc_enc_ccp_t)))) { |
815 | + if (!(cp->ccps = jas_alloc2(cp->numcmpts, sizeof(jpc_enc_ccp_t)))) { |
816 | goto error; |
817 | } |
818 | for (cmptno = 0, ccp = cp->ccps; cmptno < JAS_CAST(int, cp->numcmpts); ++cmptno, |
819 | @@ -656,7 +656,7 @@ |
820 | |
821 | if (ilyrrates && numilyrrates > 0) { |
822 | tcp->numlyrs = numilyrrates + 1; |
823 | - if (!(tcp->ilyrrates = jas_malloc((tcp->numlyrs - 1) * |
824 | + if (!(tcp->ilyrrates = jas_alloc2((tcp->numlyrs - 1), |
825 | sizeof(jpc_fix_t)))) { |
826 | goto error; |
827 | } |
828 | @@ -940,7 +940,7 @@ |
829 | siz->tilewidth = cp->tilewidth; |
830 | siz->tileheight = cp->tileheight; |
831 | siz->numcomps = cp->numcmpts; |
832 | - siz->comps = jas_malloc(siz->numcomps * sizeof(jpc_sizcomp_t)); |
833 | + siz->comps = jas_alloc2(siz->numcomps, sizeof(jpc_sizcomp_t)); |
834 | assert(siz->comps); |
835 | for (i = 0; i < JAS_CAST(int, cp->numcmpts); ++i) { |
836 | siz->comps[i].prec = cp->ccps[i].prec; |
837 | @@ -958,7 +958,8 @@ |
838 | if (!(enc->mrk = jpc_ms_create(JPC_MS_COM))) { |
839 | return -1; |
840 | } |
841 | - sprintf(buf, "Creator: JasPer Version %s", jas_getversion()); |
842 | + snprintf(buf, sizeof buf, "Creator: JasPer Version %s", |
843 | + jas_getversion()); |
844 | com = &enc->mrk->parms.com; |
845 | com->len = strlen(buf); |
846 | com->regid = JPC_COM_LATIN; |
847 | @@ -977,7 +978,7 @@ |
848 | return -1; |
849 | } |
850 | crg = &enc->mrk->parms.crg; |
851 | - crg->comps = jas_malloc(crg->numcomps * sizeof(jpc_crgcomp_t)); |
852 | + crg->comps = jas_alloc2(crg->numcomps, sizeof(jpc_crgcomp_t)); |
853 | if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { |
854 | jas_eprintf("cannot write CRG marker\n"); |
855 | return -1; |
856 | @@ -1955,7 +1956,7 @@ |
857 | tile->mctid = cp->tcp.mctid; |
858 | |
859 | tile->numlyrs = cp->tcp.numlyrs; |
860 | - if (!(tile->lyrsizes = jas_malloc(tile->numlyrs * |
861 | + if (!(tile->lyrsizes = jas_alloc2(tile->numlyrs, |
862 | sizeof(uint_fast32_t)))) { |
863 | goto error; |
864 | } |
865 | @@ -1964,7 +1965,7 @@ |
866 | } |
867 | |
868 | /* Allocate an array for the per-tile-component information. */ |
869 | - if (!(tile->tcmpts = jas_malloc(cp->numcmpts * sizeof(jpc_enc_tcmpt_t)))) { |
870 | + if (!(tile->tcmpts = jas_alloc2(cp->numcmpts, sizeof(jpc_enc_tcmpt_t)))) { |
871 | goto error; |
872 | } |
873 | /* Initialize a few members critical for error recovery. */ |
874 | @@ -2110,7 +2111,7 @@ |
875 | jas_seq2d_ystart(tcmpt->data), jas_seq2d_xend(tcmpt->data), |
876 | jas_seq2d_yend(tcmpt->data), bandinfos); |
877 | |
878 | - if (!(tcmpt->rlvls = jas_malloc(tcmpt->numrlvls * sizeof(jpc_enc_rlvl_t)))) { |
879 | + if (!(tcmpt->rlvls = jas_alloc2(tcmpt->numrlvls, sizeof(jpc_enc_rlvl_t)))) { |
880 | goto error; |
881 | } |
882 | for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls; |
883 | @@ -2213,7 +2214,7 @@ |
884 | rlvl->numvprcs = JPC_FLOORDIVPOW2(brprcbry - tlprctly, rlvl->prcheightexpn); |
885 | rlvl->numprcs = rlvl->numhprcs * rlvl->numvprcs; |
886 | |
887 | - if (!(rlvl->bands = jas_malloc(rlvl->numbands * sizeof(jpc_enc_band_t)))) { |
888 | + if (!(rlvl->bands = jas_alloc2(rlvl->numbands, sizeof(jpc_enc_band_t)))) { |
889 | goto error; |
890 | } |
891 | for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; |
892 | @@ -2290,7 +2291,7 @@ |
893 | band->synweight = bandinfo->synenergywt; |
894 | |
895 | if (band->data) { |
896 | - if (!(band->prcs = jas_malloc(rlvl->numprcs * sizeof(jpc_enc_prc_t)))) { |
897 | + if (!(band->prcs = jas_alloc2(rlvl->numprcs, sizeof(jpc_enc_prc_t)))) { |
898 | goto error; |
899 | } |
900 | for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs; ++prcno, |
901 | @@ -2422,7 +2423,7 @@ |
902 | goto error; |
903 | } |
904 | |
905 | - if (!(prc->cblks = jas_malloc(prc->numcblks * sizeof(jpc_enc_cblk_t)))) { |
906 | + if (!(prc->cblks = jas_alloc2(prc->numcblks, sizeof(jpc_enc_cblk_t)))) { |
907 | goto error; |
908 | } |
909 | for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; |
910 | diff -Naur jasper-1.900.1/src/libjasper/jpc/jpc_mqdec.c jasper.fixed/src/libjasper/jpc/jpc_mqdec.c |
911 | --- jasper-1.900.1/src/libjasper/jpc/jpc_mqdec.c 2007-01-19 22:43:07.000000000 +0100 |
912 | +++ jasper.fixed/src/libjasper/jpc/jpc_mqdec.c 2008-12-08 21:02:03.000000000 +0100 |
913 | @@ -118,7 +118,7 @@ |
914 | mqdec->in = in; |
915 | mqdec->maxctxs = maxctxs; |
916 | /* Allocate memory for the per-context state information. */ |
917 | - if (!(mqdec->ctxs = jas_malloc(mqdec->maxctxs * sizeof(jpc_mqstate_t *)))) { |
918 | + if (!(mqdec->ctxs = jas_alloc2(mqdec->maxctxs, sizeof(jpc_mqstate_t *)))) { |
919 | goto error; |
920 | } |
921 | /* Set the current context to the first context. */ |
922 | diff -Naur jasper-1.900.1/src/libjasper/jpc/jpc_mqenc.c jasper.fixed/src/libjasper/jpc/jpc_mqenc.c |
923 | --- jasper-1.900.1/src/libjasper/jpc/jpc_mqenc.c 2007-01-19 22:43:07.000000000 +0100 |
924 | +++ jasper.fixed/src/libjasper/jpc/jpc_mqenc.c 2008-12-08 21:02:03.000000000 +0100 |
925 | @@ -197,7 +197,7 @@ |
926 | mqenc->maxctxs = maxctxs; |
927 | |
928 | /* Allocate memory for the per-context state information. */ |
929 | - if (!(mqenc->ctxs = jas_malloc(mqenc->maxctxs * sizeof(jpc_mqstate_t *)))) { |
930 | + if (!(mqenc->ctxs = jas_alloc2(mqenc->maxctxs, sizeof(jpc_mqstate_t *)))) { |
931 | goto error; |
932 | } |
933 | |
934 | diff -Naur jasper-1.900.1/src/libjasper/jpc/jpc_qmfb.c jasper.fixed/src/libjasper/jpc/jpc_qmfb.c |
935 | --- jasper-1.900.1/src/libjasper/jpc/jpc_qmfb.c 2007-01-19 22:43:07.000000000 +0100 |
936 | +++ jasper.fixed/src/libjasper/jpc/jpc_qmfb.c 2008-12-08 21:02:03.000000000 +0100 |
937 | @@ -321,7 +321,7 @@ |
938 | #if !defined(HAVE_VLA) |
939 | /* Get a buffer. */ |
940 | if (bufsize > QMFB_SPLITBUFSIZE) { |
941 | - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { |
942 | + if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) { |
943 | /* We have no choice but to commit suicide in this case. */ |
944 | abort(); |
945 | } |
946 | @@ -389,7 +389,7 @@ |
947 | #if !defined(HAVE_VLA) |
948 | /* Get a buffer. */ |
949 | if (bufsize > QMFB_SPLITBUFSIZE) { |
950 | - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { |
951 | + if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) { |
952 | /* We have no choice but to commit suicide in this case. */ |
953 | abort(); |
954 | } |
955 | @@ -460,7 +460,7 @@ |
956 | #if !defined(HAVE_VLA) |
957 | /* Get a buffer. */ |
958 | if (bufsize > QMFB_SPLITBUFSIZE) { |
959 | - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { |
960 | + if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) { |
961 | /* We have no choice but to commit suicide in this case. */ |
962 | abort(); |
963 | } |
964 | @@ -549,7 +549,7 @@ |
965 | #if !defined(HAVE_VLA) |
966 | /* Get a buffer. */ |
967 | if (bufsize > QMFB_SPLITBUFSIZE) { |
968 | - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { |
969 | + if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) { |
970 | /* We have no choice but to commit suicide in this case. */ |
971 | abort(); |
972 | } |
973 | @@ -633,7 +633,7 @@ |
974 | #if !defined(HAVE_VLA) |
975 | /* Allocate memory for the join buffer from the heap. */ |
976 | if (bufsize > QMFB_JOINBUFSIZE) { |
977 | - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { |
978 | + if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) { |
979 | /* We have no choice but to commit suicide. */ |
980 | abort(); |
981 | } |
982 | @@ -698,7 +698,7 @@ |
983 | #if !defined(HAVE_VLA) |
984 | /* Allocate memory for the join buffer from the heap. */ |
985 | if (bufsize > QMFB_JOINBUFSIZE) { |
986 | - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { |
987 | + if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) { |
988 | /* We have no choice but to commit suicide. */ |
989 | abort(); |
990 | } |
991 | @@ -766,7 +766,7 @@ |
992 | #if !defined(HAVE_VLA) |
993 | /* Allocate memory for the join buffer from the heap. */ |
994 | if (bufsize > QMFB_JOINBUFSIZE) { |
995 | - if (!(buf = jas_malloc(bufsize * JPC_QMFB_COLGRPSIZE * sizeof(jpc_fix_t)))) { |
996 | + if (!(buf = jas_alloc2(bufsize, JPC_QMFB_COLGRPSIZE * sizeof(jpc_fix_t)))) { |
997 | /* We have no choice but to commit suicide. */ |
998 | abort(); |
999 | } |
1000 | @@ -852,7 +852,7 @@ |
1001 | #if !defined(HAVE_VLA) |
1002 | /* Allocate memory for the join buffer from the heap. */ |
1003 | if (bufsize > QMFB_JOINBUFSIZE) { |
1004 | - if (!(buf = jas_malloc(bufsize * numcols * sizeof(jpc_fix_t)))) { |
1005 | + if (!(buf = jas_alloc3(bufsize, numcols, sizeof(jpc_fix_t)))) { |
1006 | /* We have no choice but to commit suicide. */ |
1007 | abort(); |
1008 | } |
1009 | diff -Naur jasper-1.900.1/src/libjasper/jpc/jpc_t1enc.c jasper.fixed/src/libjasper/jpc/jpc_t1enc.c |
1010 | --- jasper-1.900.1/src/libjasper/jpc/jpc_t1enc.c 2007-01-19 22:43:07.000000000 +0100 |
1011 | +++ jasper.fixed/src/libjasper/jpc/jpc_t1enc.c 2008-12-08 21:02:03.000000000 +0100 |
1012 | @@ -219,7 +219,7 @@ |
1013 | |
1014 | cblk->numpasses = (cblk->numbps > 0) ? (3 * cblk->numbps - 2) : 0; |
1015 | if (cblk->numpasses > 0) { |
1016 | - cblk->passes = jas_malloc(cblk->numpasses * sizeof(jpc_enc_pass_t)); |
1017 | + cblk->passes = jas_alloc2(cblk->numpasses, sizeof(jpc_enc_pass_t)); |
1018 | assert(cblk->passes); |
1019 | } else { |
1020 | cblk->passes = 0; |
1021 | diff -Naur jasper-1.900.1/src/libjasper/jpc/jpc_t2cod.c jasper.fixed/src/libjasper/jpc/jpc_t2cod.c |
1022 | --- jasper-1.900.1/src/libjasper/jpc/jpc_t2cod.c 2007-01-19 22:43:07.000000000 +0100 |
1023 | +++ jasper.fixed/src/libjasper/jpc/jpc_t2cod.c 2008-12-08 21:02:03.000000000 +0100 |
1024 | @@ -573,7 +573,7 @@ |
1025 | } |
1026 | if (pchglist->numpchgs >= pchglist->maxpchgs) { |
1027 | newmaxpchgs = pchglist->maxpchgs + 128; |
1028 | - if (!(newpchgs = jas_realloc(pchglist->pchgs, newmaxpchgs * sizeof(jpc_pchg_t *)))) { |
1029 | + if (!(newpchgs = jas_realloc2(pchglist->pchgs, newmaxpchgs, sizeof(jpc_pchg_t *)))) { |
1030 | return -1; |
1031 | } |
1032 | pchglist->maxpchgs = newmaxpchgs; |
1033 | diff -Naur jasper-1.900.1/src/libjasper/jpc/jpc_t2dec.c jasper.fixed/src/libjasper/jpc/jpc_t2dec.c |
1034 | --- jasper-1.900.1/src/libjasper/jpc/jpc_t2dec.c 2007-01-19 22:43:07.000000000 +0100 |
1035 | +++ jasper.fixed/src/libjasper/jpc/jpc_t2dec.c 2008-12-08 21:02:03.000000000 +0100 |
1036 | @@ -478,7 +478,7 @@ |
1037 | return 0; |
1038 | } |
1039 | pi->numcomps = dec->numcomps; |
1040 | - if (!(pi->picomps = jas_malloc(pi->numcomps * sizeof(jpc_picomp_t)))) { |
1041 | + if (!(pi->picomps = jas_alloc2(pi->numcomps, sizeof(jpc_picomp_t)))) { |
1042 | jpc_pi_destroy(pi); |
1043 | return 0; |
1044 | } |
1045 | @@ -490,7 +490,7 @@ |
1046 | for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps; |
1047 | compno < pi->numcomps; ++compno, ++tcomp, ++picomp) { |
1048 | picomp->numrlvls = tcomp->numrlvls; |
1049 | - if (!(picomp->pirlvls = jas_malloc(picomp->numrlvls * |
1050 | + if (!(picomp->pirlvls = jas_alloc2(picomp->numrlvls, |
1051 | sizeof(jpc_pirlvl_t)))) { |
1052 | jpc_pi_destroy(pi); |
1053 | return 0; |
1054 | @@ -503,7 +503,7 @@ |
1055 | rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) { |
1056 | /* XXX sizeof(long) should be sizeof different type */ |
1057 | pirlvl->numprcs = rlvl->numprcs; |
1058 | - if (!(pirlvl->prclyrnos = jas_malloc(pirlvl->numprcs * |
1059 | + if (!(pirlvl->prclyrnos = jas_alloc2(pirlvl->numprcs, |
1060 | sizeof(long)))) { |
1061 | jpc_pi_destroy(pi); |
1062 | return 0; |
1063 | diff -Naur jasper-1.900.1/src/libjasper/jpc/jpc_t2enc.c jasper.fixed/src/libjasper/jpc/jpc_t2enc.c |
1064 | --- jasper-1.900.1/src/libjasper/jpc/jpc_t2enc.c 2007-01-19 22:43:07.000000000 +0100 |
1065 | +++ jasper.fixed/src/libjasper/jpc/jpc_t2enc.c 2008-12-08 21:02:03.000000000 +0100 |
1066 | @@ -565,7 +565,7 @@ |
1067 | } |
1068 | pi->pktno = -1; |
1069 | pi->numcomps = cp->numcmpts; |
1070 | - if (!(pi->picomps = jas_malloc(pi->numcomps * sizeof(jpc_picomp_t)))) { |
1071 | + if (!(pi->picomps = jas_alloc2(pi->numcomps, sizeof(jpc_picomp_t)))) { |
1072 | jpc_pi_destroy(pi); |
1073 | return 0; |
1074 | } |
1075 | @@ -577,7 +577,7 @@ |
1076 | for (compno = 0, tcomp = tile->tcmpts, picomp = pi->picomps; |
1077 | compno < pi->numcomps; ++compno, ++tcomp, ++picomp) { |
1078 | picomp->numrlvls = tcomp->numrlvls; |
1079 | - if (!(picomp->pirlvls = jas_malloc(picomp->numrlvls * |
1080 | + if (!(picomp->pirlvls = jas_alloc2(picomp->numrlvls, |
1081 | sizeof(jpc_pirlvl_t)))) { |
1082 | jpc_pi_destroy(pi); |
1083 | return 0; |
1084 | @@ -591,7 +591,7 @@ |
1085 | /* XXX sizeof(long) should be sizeof different type */ |
1086 | pirlvl->numprcs = rlvl->numprcs; |
1087 | if (rlvl->numprcs) { |
1088 | - if (!(pirlvl->prclyrnos = jas_malloc(pirlvl->numprcs * |
1089 | + if (!(pirlvl->prclyrnos = jas_alloc2(pirlvl->numprcs, |
1090 | sizeof(long)))) { |
1091 | jpc_pi_destroy(pi); |
1092 | return 0; |
1093 | diff -Naur jasper-1.900.1/src/libjasper/jpc/jpc_tagtree.c jasper.fixed/src/libjasper/jpc/jpc_tagtree.c |
1094 | --- jasper-1.900.1/src/libjasper/jpc/jpc_tagtree.c 2007-01-19 22:43:07.000000000 +0100 |
1095 | +++ jasper.fixed/src/libjasper/jpc/jpc_tagtree.c 2008-12-08 21:02:03.000000000 +0100 |
1096 | @@ -125,7 +125,7 @@ |
1097 | ++numlvls; |
1098 | } while (n > 1); |
1099 | |
1100 | - if (!(tree->nodes_ = jas_malloc(tree->numnodes_ * sizeof(jpc_tagtreenode_t)))) { |
1101 | + if (!(tree->nodes_ = jas_alloc2(tree->numnodes_, sizeof(jpc_tagtreenode_t)))) { |
1102 | return 0; |
1103 | } |
1104 | |
1105 | diff -Naur jasper-1.900.1/src/libjasper/jpc/jpc_util.c jasper.fixed/src/libjasper/jpc/jpc_util.c |
1106 | --- jasper-1.900.1/src/libjasper/jpc/jpc_util.c 2007-01-19 22:43:07.000000000 +0100 |
1107 | +++ jasper.fixed/src/libjasper/jpc/jpc_util.c 2008-12-08 21:02:03.000000000 +0100 |
1108 | @@ -109,7 +109,7 @@ |
1109 | } |
1110 | |
1111 | if (n) { |
1112 | - if (!(vs = jas_malloc(n * sizeof(double)))) { |
1113 | + if (!(vs = jas_alloc2(n, sizeof(double)))) { |
1114 | return -1; |
1115 | } |
1116 | |
1117 | diff -Naur jasper-1.900.1/src/libjasper/mif/mif_cod.c jasper.fixed/src/libjasper/mif/mif_cod.c |
1118 | --- jasper-1.900.1/src/libjasper/mif/mif_cod.c 2007-01-19 22:43:05.000000000 +0100 |
1119 | +++ jasper.fixed/src/libjasper/mif/mif_cod.c 2008-12-08 21:02:03.000000000 +0100 |
1120 | @@ -438,8 +438,7 @@ |
1121 | int cmptno; |
1122 | mif_cmpt_t **newcmpts; |
1123 | assert(maxcmpts >= hdr->numcmpts); |
1124 | - newcmpts = (!hdr->cmpts) ? jas_malloc(maxcmpts * sizeof(mif_cmpt_t *)) : |
1125 | - jas_realloc(hdr->cmpts, maxcmpts * sizeof(mif_cmpt_t *)); |
1126 | + newcmpts = jas_realloc2(hdr->cmpts, maxcmpts, sizeof(mif_cmpt_t *)); |
1127 | if (!newcmpts) { |
1128 | return -1; |
1129 | } |
1130 | diff -Naur jasper-1.900.1/src/libjasper/pnm/pnm_enc.c jasper.fixed/src/libjasper/pnm/pnm_enc.c |
1131 | --- jasper-1.900.1/src/libjasper/pnm/pnm_enc.c 2007-01-19 22:43:05.000000000 +0100 |
1132 | +++ jasper.fixed/src/libjasper/pnm/pnm_enc.c 2008-12-08 21:02:03.000000000 +0100 |
1133 | @@ -374,7 +374,7 @@ |
1134 | } |
1135 | } |
1136 | } else { |
1137 | - n = sprintf(buf, "%s%ld", ((!(!x && !cmptno)) ? " " : ""), |
1138 | + n = snprintf(buf, sizeof buf, "%s%ld", ((!(!x && !cmptno)) ? " " : ""), |
1139 | (long) v); |
1140 | if (linelen > 0 && linelen + n > PNM_MAXLINELEN) { |
1141 | jas_stream_printf(out, "\n"); |