summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-12-12 17:47:17 +0000
committerRobin Watts <robin.watts@artifex.com>2016-12-13 00:21:55 +0000
commite698d5c11d27212aa1098bc5b1673a3378563092 (patch)
tree8d92900606438857a0266f749a5510174fc29dd3
parent1369359f21a1c8a055cc745f920b17fbc3f30efd (diff)
Squash signed/unsigned warnings in MSVC jbig2 build.
Also rename "new" to "new_dict", because "new" is a bad variable name.
-rw-r--r--jbig2.c4
-rw-r--r--jbig2.h8
-rw-r--r--jbig2_generic.c2
-rw-r--r--jbig2_halftone.c24
-rw-r--r--jbig2_huffman.c10
-rw-r--r--jbig2_huffman.h2
-rw-r--r--jbig2_image.c32
-rw-r--r--jbig2_mmr.c66
-rw-r--r--jbig2_page.c6
-rw-r--r--jbig2_priv.h4
-rw-r--r--jbig2_segment.c10
-rw-r--r--jbig2_symbol_dict.c73
-rw-r--r--jbig2_symbol_dict.h6
-rw-r--r--jbig2_text.c16
-rw-r--r--jbig2_text.h2
15 files changed, 134 insertions, 131 deletions
diff --git a/jbig2.c b/jbig2.c
index f729e29..e51380f 100644
--- a/jbig2.c
+++ b/jbig2.c
@@ -379,7 +379,7 @@ typedef struct {
379} Jbig2WordStreamBuf; 379} Jbig2WordStreamBuf;
380 380
381static int 381static int
382jbig2_word_stream_buf_get_next_word(Jbig2WordStream *self, int offset, uint32_t *word) 382jbig2_word_stream_buf_get_next_word(Jbig2WordStream *self, size_t offset, uint32_t *word)
383{ 383{
384 Jbig2WordStreamBuf *z = (Jbig2WordStreamBuf *) self; 384 Jbig2WordStreamBuf *z = (Jbig2WordStreamBuf *) self;
385 const byte *data = z->data; 385 const byte *data = z->data;
@@ -390,7 +390,7 @@ jbig2_word_stream_buf_get_next_word(Jbig2WordStream *self, int offset, uint32_t
390 else if (offset > z->size) 390 else if (offset > z->size)
391 return -1; 391 return -1;
392 else { 392 else {
393 int i; 393 size_t i;
394 394
395 result = 0; 395 result = 0;
396 for (i = 0; i < z->size - offset; i++) 396 for (i = 0; i < z->size - offset; i++)
diff --git a/jbig2.h b/jbig2.h
index d5aa52f..624e0ed 100644
--- a/jbig2.h
+++ b/jbig2.h
@@ -56,17 +56,19 @@ typedef struct _Jbig2SymbolDictionary Jbig2SymbolDictionary;
56*/ 56*/
57 57
58struct _Jbig2Image { 58struct _Jbig2Image {
59 int width, height, stride; 59 uint32_t width;
60 uint32_t height;
61 uint32_t stride;
60 uint8_t *data; 62 uint8_t *data;
61 int refcount; 63 int refcount;
62}; 64};
63 65
64Jbig2Image *jbig2_image_new(Jbig2Ctx *ctx, int width, int height); 66Jbig2Image *jbig2_image_new(Jbig2Ctx *ctx, uint32_t width, uint32_t height);
65Jbig2Image *jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image); 67Jbig2Image *jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image);
66void jbig2_image_release(Jbig2Ctx *ctx, Jbig2Image *image); 68void jbig2_image_release(Jbig2Ctx *ctx, Jbig2Image *image);
67void jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image); 69void jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image);
68void jbig2_image_clear(Jbig2Ctx *ctx, Jbig2Image *image, int value); 70void jbig2_image_clear(Jbig2Ctx *ctx, Jbig2Image *image, int value);
69Jbig2Image *jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, int width, int height); 71Jbig2Image *jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, uint32_t width, uint32_t height);
70 72
71/* errors are returned from the library via a callback. If no callback 73/* errors are returned from the library via a callback. If no callback
72 is provided (a NULL argument is passed ot jbig2_ctx_new) a default 74 is provided (a NULL argument is passed ot jbig2_ctx_new) a default
diff --git a/jbig2_generic.c b/jbig2_generic.c
index 02fdbfb..9656198 100644
--- a/jbig2_generic.c
+++ b/jbig2_generic.c
@@ -718,7 +718,7 @@ jbig2_immediate_generic_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte
718 byte seg_flags; 718 byte seg_flags;
719 int8_t gbat[8]; 719 int8_t gbat[8];
720 int offset; 720 int offset;
721 int gbat_bytes = 0; 721 uint32_t gbat_bytes = 0;
722 Jbig2GenericRegionParams params; 722 Jbig2GenericRegionParams params;
723 int code = 0; 723 int code = 0;
724 Jbig2Image *image = NULL; 724 Jbig2Image *image = NULL;
diff --git a/jbig2_halftone.c b/jbig2_halftone.c
index aeab576..acfbc56 100644
--- a/jbig2_halftone.c
+++ b/jbig2_halftone.c
@@ -257,8 +257,8 @@ jbig2_decode_gray_scale_image(Jbig2Ctx *ctx, Jbig2Segment *segment,
257{ 257{
258 uint8_t **GSVALS = NULL; 258 uint8_t **GSVALS = NULL;
259 size_t consumed_bytes = 0; 259 size_t consumed_bytes = 0;
260 int i, j, code, stride; 260 uint32_t i, j, stride, x, y;
261 int x, y; 261 int code;
262 Jbig2Image **GSPLANES; 262 Jbig2Image **GSPLANES;
263 Jbig2GenericRegionParams rparams; 263 Jbig2GenericRegionParams rparams;
264 Jbig2WordStream *ws = NULL; 264 Jbig2WordStream *ws = NULL;
@@ -276,9 +276,8 @@ jbig2_decode_gray_scale_image(Jbig2Ctx *ctx, Jbig2Segment *segment,
276 if (GSPLANES[i] == NULL) { 276 if (GSPLANES[i] == NULL) {
277 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate %dx%d image for GSPLANES", GSW, GSH); 277 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate %dx%d image for GSPLANES", GSW, GSH);
278 /* free already allocated */ 278 /* free already allocated */
279 for (j = i - 1; j >= 0; --j) { 279 for (j = i; j > 0;)
280 jbig2_image_release(ctx, GSPLANES[j]); 280 jbig2_image_release(ctx, GSPLANES[--j]);
281 }
282 jbig2_free(ctx->allocator, GSPLANES); 281 jbig2_free(ctx->allocator, GSPLANES);
283 return NULL; 282 return NULL;
284 } 283 }
@@ -323,9 +322,10 @@ jbig2_decode_gray_scale_image(Jbig2Ctx *ctx, Jbig2Segment *segment,
323 } 322 }
324 323
325 /* C.5 step 2. Set j = GSBPP-2 */ 324 /* C.5 step 2. Set j = GSBPP-2 */
326 j = GSBPP - 2; 325 j = GSBPP - 1;
327 /* C.5 step 3. decode loop */ 326 /* C.5 step 3. decode loop */
328 while (j >= 0) { 327 while (j > 0) {
328 j--;
329 /* C.5 step 3. (a) */ 329 /* C.5 step 3. (a) */
330 if (GSMMR) { 330 if (GSMMR) {
331 code = jbig2_decode_halftone_mmr(ctx, &rparams, data + consumed_bytes, size - consumed_bytes, GSPLANES[j], &consumed_bytes); 331 code = jbig2_decode_halftone_mmr(ctx, &rparams, data + consumed_bytes, size - consumed_bytes, GSPLANES[j], &consumed_bytes);
@@ -345,7 +345,6 @@ jbig2_decode_gray_scale_image(Jbig2Ctx *ctx, Jbig2Segment *segment,
345 GSPLANES[j]->data[i] ^= GSPLANES[j + 1]->data[i]; 345 GSPLANES[j]->data[i] ^= GSPLANES[j + 1]->data[i];
346 346
347 /* C.5 step 3. (c) */ 347 /* C.5 step 3. (c) */
348 --j;
349 } 348 }
350 349
351 /* allocate GSVALS */ 350 /* allocate GSVALS */
@@ -359,9 +358,8 @@ jbig2_decode_gray_scale_image(Jbig2Ctx *ctx, Jbig2Segment *segment,
359 if (GSVALS[i] == NULL) { 358 if (GSVALS[i] == NULL) {
360 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate GSVALS: %d bytes", GSH * GSW); 359 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate GSVALS: %d bytes", GSH * GSW);
361 /* free already allocated */ 360 /* free already allocated */
362 for (j = i - 1; j >= 0; --j) { 361 for (j = i; j > 0;)
363 jbig2_free(ctx->allocator, GSVALS[j]); 362 jbig2_free(ctx->allocator, GSVALS[--j]);
364 }
365 jbig2_free(ctx->allocator, GSVALS); 363 jbig2_free(ctx->allocator, GSVALS);
366 GSVALS = NULL; 364 GSVALS = NULL;
367 goto cleanup; 365 goto cleanup;
@@ -450,7 +448,7 @@ jbig2_decode_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
450 uint8_t **GI; 448 uint8_t **GI;
451 Jbig2Image *HSKIP = NULL; 449 Jbig2Image *HSKIP = NULL;
452 Jbig2PatternDict *HPATS; 450 Jbig2PatternDict *HPATS;
453 int i; 451 uint32_t i;
454 uint32_t mg, ng; 452 uint32_t mg, ng;
455 int32_t x, y; 453 int32_t x, y;
456 uint8_t gray_val; 454 uint8_t gray_val;
@@ -476,7 +474,7 @@ jbig2_decode_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
476 474
477 /* calculate ceil(log2(HNUMPATS)) */ 475 /* calculate ceil(log2(HNUMPATS)) */
478 HBPP = 0; 476 HBPP = 0;
479 while (HNUMPATS > (1 << ++HBPP)); 477 while (HNUMPATS > (1U << ++HBPP));
480 478
481 /* 6.6.5 point 4. decode gray-scale image as mentioned in annex C */ 479 /* 6.6.5 point 4. decode gray-scale image as mentioned in annex C */
482 GI = jbig2_decode_gray_scale_image(ctx, segment, data, size, 480 GI = jbig2_decode_gray_scale_image(ctx, segment, data, size,
diff --git a/jbig2_huffman.c b/jbig2_huffman.c
index 4521b48..f77981b 100644
--- a/jbig2_huffman.c
+++ b/jbig2_huffman.c
@@ -47,16 +47,16 @@ struct _Jbig2HuffmanState {
47 is (offset + 4) * 8. */ 47 is (offset + 4) * 8. */
48 uint32_t this_word; 48 uint32_t this_word;
49 uint32_t next_word; 49 uint32_t next_word;
50 int offset_bits; 50 uint32_t offset_bits;
51 int offset; 51 uint32_t offset;
52 int offset_limit; 52 uint32_t offset_limit;
53 53
54 Jbig2WordStream *ws; 54 Jbig2WordStream *ws;
55 Jbig2Ctx *ctx; 55 Jbig2Ctx *ctx;
56}; 56};
57 57
58static uint32_t 58static uint32_t
59huff_get_next_word(Jbig2HuffmanState *hs, int offset) 59huff_get_next_word(Jbig2HuffmanState *hs, uint32_t offset)
60{ 60{
61 uint32_t word = 0; 61 uint32_t word = 0;
62 Jbig2WordStream *ws = hs->ws; 62 Jbig2WordStream *ws = hs->ws;
@@ -213,7 +213,7 @@ jbig2_huffman_advance(Jbig2HuffmanState *hs, int offset)
213/* return the offset of the huffman decode pointer (in bytes) 213/* return the offset of the huffman decode pointer (in bytes)
214 * from the beginning of the WordStream 214 * from the beginning of the WordStream
215 */ 215 */
216int 216uint32_t
217jbig2_huffman_offset(Jbig2HuffmanState *hs) 217jbig2_huffman_offset(Jbig2HuffmanState *hs)
218{ 218{
219 return hs->offset + (hs->offset_bits >> 3); 219 return hs->offset + (hs->offset_bits >> 3);
diff --git a/jbig2_huffman.h b/jbig2_huffman.h
index 5d1e6e0..cfda9e0 100644
--- a/jbig2_huffman.h
+++ b/jbig2_huffman.h
@@ -64,7 +64,7 @@ void jbig2_huffman_skip(Jbig2HuffmanState *hs);
64 64
65void jbig2_huffman_advance(Jbig2HuffmanState *hs, int offset); 65void jbig2_huffman_advance(Jbig2HuffmanState *hs, int offset);
66 66
67int jbig2_huffman_offset(Jbig2HuffmanState *hs); 67uint32_t jbig2_huffman_offset(Jbig2HuffmanState *hs);
68 68
69int32_t jbig2_huffman_get(Jbig2HuffmanState *hs, const Jbig2HuffmanTable *table, bool *oob); 69int32_t jbig2_huffman_get(Jbig2HuffmanState *hs, const Jbig2HuffmanTable *table, bool *oob);
70 70
diff --git a/jbig2_image.c b/jbig2_image.c
index 1ae614e..94e5a4c 100644
--- a/jbig2_image.c
+++ b/jbig2_image.c
@@ -32,10 +32,10 @@
32 32
33/* allocate a Jbig2Image structure and its associated bitmap */ 33/* allocate a Jbig2Image structure and its associated bitmap */
34Jbig2Image * 34Jbig2Image *
35jbig2_image_new(Jbig2Ctx *ctx, int width, int height) 35jbig2_image_new(Jbig2Ctx *ctx, uint32_t width, uint32_t height)
36{ 36{
37 Jbig2Image *image; 37 Jbig2Image *image;
38 int stride; 38 uint32_t stride;
39 int64_t check; 39 int64_t check;
40 40
41 image = jbig2_new(ctx, Jbig2Image, 1); 41 image = jbig2_new(ctx, Jbig2Image, 1);
@@ -99,7 +99,7 @@ jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image)
99 99
100/* resize a Jbig2Image */ 100/* resize a Jbig2Image */
101Jbig2Image * 101Jbig2Image *
102jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, int width, int height) 102jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, uint32_t width, uint32_t height)
103{ 103{
104 if (width == image->width) { 104 if (width == image->width) {
105 /* check for integer multiplication overflow */ 105 /* check for integer multiplication overflow */
@@ -133,11 +133,11 @@ jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, int width, int height)
133static int 133static int
134jbig2_image_compose_unopt(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int y, Jbig2ComposeOp op) 134jbig2_image_compose_unopt(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int y, Jbig2ComposeOp op)
135{ 135{
136 int i, j; 136 uint32_t i, j;
137 int sw = src->width; 137 uint32_t sw = src->width;
138 int sh = src->height; 138 uint32_t sh = src->height;
139 int sx = 0; 139 uint32_t sx = 0;
140 int sy = 0; 140 uint32_t sy = 0;
141 141
142 /* clip to the dst image boundaries */ 142 /* clip to the dst image boundaries */
143 if (x < 0) { 143 if (x < 0) {
@@ -200,10 +200,10 @@ jbig2_image_compose_unopt(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x
200int 200int
201jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int y, Jbig2ComposeOp op) 201jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int y, Jbig2ComposeOp op)
202{ 202{
203 int i, j; 203 uint32_t i, j;
204 int w, h; 204 uint32_t w, h;
205 int leftbyte, rightbyte; 205 uint32_t leftbyte, rightbyte;
206 int shift; 206 uint32_t shift;
207 uint8_t *s, *ss; 207 uint8_t *s, *ss;
208 uint8_t *d, *dd; 208 uint8_t *d, *dd;
209 uint8_t mask, rightmask; 209 uint8_t mask, rightmask;
@@ -226,8 +226,8 @@ jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int
226 h += y; 226 h += y;
227 y = 0; 227 y = 0;
228 } 228 }
229 w = (x + w < dst->width) ? w : dst->width - x; 229 w = ((uint32_t)x + w < dst->width) ? w : ((dst->width >= (uint32_t)x) ? dst->width - (uint32_t)x : 0);
230 h = (y + h < dst->height) ? h : dst->height - y; 230 h = ((uint32_t)y + h < dst->height) ? h : ((dst->height >= (uint32_t)y) ? dst->height - (uint32_t)y : 0);
231#ifdef JBIG2_DEBUG 231#ifdef JBIG2_DEBUG
232 jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "compositing %dx%d at (%d, %d) after clipping\n", w, h, x, y); 232 jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "compositing %dx%d at (%d, %d) after clipping\n", w, h, x, y);
233#endif 233#endif
@@ -249,8 +249,8 @@ jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int
249 } 249 }
250#endif 250#endif
251 251
252 leftbyte = x >> 3; 252 leftbyte = (uint32_t)x >> 3;
253 rightbyte = (x + w - 1) >> 3; 253 rightbyte = ((uint32_t)x + w - 1) >> 3;
254 shift = x & 7; 254 shift = x & 7;
255 255
256 /* general OR case */ 256 /* general OR case */
diff --git a/jbig2_mmr.c b/jbig2_mmr.c
index d4cd3a2..390e27c 100644
--- a/jbig2_mmr.c
+++ b/jbig2_mmr.c
@@ -38,19 +38,21 @@
38#include "jbig2_mmr.h" 38#include "jbig2_mmr.h"
39 39
40typedef struct { 40typedef struct {
41 int width; 41 uint32_t width;
42 int height; 42 uint32_t height;
43 const byte *data; 43 const byte *data;
44 size_t size; 44 size_t size;
45 int data_index; 45 uint32_t data_index;
46 int bit_index; 46 uint32_t bit_index;
47 uint32_t word; 47 uint32_t word;
48} Jbig2MmrCtx; 48} Jbig2MmrCtx;
49 49
50#define MINUS1 ((uint32_t)-1)
51
50static void 52static void
51jbig2_decode_mmr_init(Jbig2MmrCtx *mmr, int width, int height, const byte *data, size_t size) 53jbig2_decode_mmr_init(Jbig2MmrCtx *mmr, int width, int height, const byte *data, size_t size)
52{ 54{
53 int i; 55 size_t i;
54 uint32_t word = 0; 56 uint32_t word = 0;
55 57
56 mmr->width = width; 58 mmr->width = width;
@@ -732,14 +734,14 @@ const mmr_table_node jbig2_mmr_black_decode[] = {
732#define getbit(buf, x) ( ( buf[x >> 3] >> ( 7 - (x & 7) ) ) & 1 ) 734#define getbit(buf, x) ( ( buf[x >> 3] >> ( 7 - (x & 7) ) ) & 1 )
733 735
734static int 736static int
735jbig2_find_changing_element(const byte *line, int x, int w) 737jbig2_find_changing_element(const byte *line, uint32_t x, uint32_t w)
736{ 738{
737 int a, b; 739 int a, b;
738 740
739 if (line == 0) 741 if (line == 0)
740 return w; 742 return (int)w;
741 743
742 if (x == -1) { 744 if (x == MINUS1) {
743 a = 0; 745 a = 0;
744 x = 0; 746 x = 0;
745 } else { 747 } else {
@@ -758,7 +760,7 @@ jbig2_find_changing_element(const byte *line, int x, int w)
758} 760}
759 761
760static int 762static int
761jbig2_find_changing_element_of_color(const byte *line, int x, int w, int color) 763jbig2_find_changing_element_of_color(const byte *line, uint32_t x, uint32_t w, int color)
762{ 764{
763 if (line == 0) 765 if (line == 0)
764 return w; 766 return w;
@@ -772,9 +774,9 @@ static const byte lm[8] = { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01 };
772static const byte rm[8] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE }; 774static const byte rm[8] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
773 775
774static void 776static void
775jbig2_set_bits(byte *line, int x0, int x1) 777jbig2_set_bits(byte *line, uint32_t x0, uint32_t x1)
776{ 778{
777 int a0, a1, b0, b1, a; 779 uint32_t a0, a1, b0, b1, a;
778 780
779 a0 = x0 >> 3; 781 a0 = x0 >> 3;
780 a1 = x1 >> 3; 782 a1 = x1 >> 3;
@@ -831,8 +833,8 @@ jbig2_decode_get_run(Jbig2MmrCtx *mmr, const mmr_table_node *table, int initial_
831static int 833static int
832jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst) 834jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
833{ 835{
834 int a0 = -1; 836 uint32_t a0 = MINUS1;
835 int a1, a2, b1, b2; 837 uint32_t a1, a2, b1, b2;
836 int c = 0; /* 0 is white, black is 1 */ 838 int c = 0; /* 0 is white, black is 1 */
837 839
838 while (1) { 840 while (1) {
@@ -840,7 +842,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
840 842
841 /* printf ("%08x\n", word); */ 843 /* printf ("%08x\n", word); */
842 844
843 if (a0 >= mmr->width) 845 if (a0 != MINUS1 && a0 >= mmr->width)
844 break; 846 break;
845 847
846 if ((word >> (32 - 3)) == 1) { 848 if ((word >> (32 - 3)) == 1) {
@@ -848,7 +850,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
848 850
849 jbig2_decode_mmr_consume(mmr, 3); 851 jbig2_decode_mmr_consume(mmr, 3);
850 852
851 if (a0 == -1) 853 if (a0 == MINUS1)
852 a0 = 0; 854 a0 = 0;
853 855
854 if (c == 0) { 856 if (c == 0) {
@@ -860,7 +862,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
860 a1 = mmr->width; 862 a1 = mmr->width;
861 if (a2 > mmr->width) 863 if (a2 > mmr->width)
862 a2 = mmr->width; 864 a2 = mmr->width;
863 if (a2 < a1 || a1 < 0) 865 if (a1 == MINUS1 || a2 < a1)
864 return -1; 866 return -1;
865 jbig2_set_bits(dst, a1, a2); 867 jbig2_set_bits(dst, a1, a2);
866 a0 = a2; 868 a0 = a2;
@@ -874,7 +876,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
874 a1 = mmr->width; 876 a1 = mmr->width;
875 if (a2 > mmr->width) 877 if (a2 > mmr->width)
876 a2 = mmr->width; 878 a2 = mmr->width;
877 if (a1 < a0 || a0 < 0) 879 if (a0 == MINUS1 || a1 < a0)
878 return -1; 880 return -1;
879 jbig2_set_bits(dst, a0, a1); 881 jbig2_set_bits(dst, a0, a1);
880 a0 = a2; 882 a0 = a2;
@@ -888,7 +890,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
888 b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c); 890 b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
889 b2 = jbig2_find_changing_element(ref, b1, mmr->width); 891 b2 = jbig2_find_changing_element(ref, b1, mmr->width);
890 if (c) { 892 if (c) {
891 if (b2 < a0 || a0 < 0) 893 if (a0 == MINUS1 || b2 < a0)
892 return -1; 894 return -1;
893 jbig2_set_bits(dst, a0, b2); 895 jbig2_set_bits(dst, a0, b2);
894 } 896 }
@@ -900,7 +902,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
900 jbig2_decode_mmr_consume(mmr, 1); 902 jbig2_decode_mmr_consume(mmr, 1);
901 b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c); 903 b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
902 if (c) { 904 if (c) {
903 if (b1 < a0 || a0 < 0) 905 if (a0 == MINUS1 || b1 < a0)
904 return -1; 906 return -1;
905 jbig2_set_bits(dst, a0, b1); 907 jbig2_set_bits(dst, a0, b1);
906 } 908 }
@@ -915,7 +917,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
915 if (b1 + 1 > mmr->width) 917 if (b1 + 1 > mmr->width)
916 break; 918 break;
917 if (c) { 919 if (c) {
918 if (b1 + 1 < a0 || a0 < 0) 920 if (a0 == MINUS1 || b1 + 1 < a0)
919 return -1; 921 return -1;
920 jbig2_set_bits(dst, a0, b1 + 1); 922 jbig2_set_bits(dst, a0, b1 + 1);
921 } 923 }
@@ -930,7 +932,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
930 if (b1 + 2 > mmr->width) 932 if (b1 + 2 > mmr->width)
931 break; 933 break;
932 if (c) { 934 if (c) {
933 if (b1 + 2 < a0 || a0 < 0) 935 if (a0 == MINUS1 || b1 + 2 < a0)
934 return -1; 936 return -1;
935 jbig2_set_bits(dst, a0, b1 + 2); 937 jbig2_set_bits(dst, a0, b1 + 2);
936 } 938 }
@@ -942,10 +944,10 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
942 /* printf ("VR(3)\n"); */ 944 /* printf ("VR(3)\n"); */
943 jbig2_decode_mmr_consume(mmr, 7); 945 jbig2_decode_mmr_consume(mmr, 7);
944 b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c); 946 b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
945 if (b1 + 3 > mmr->width) 947 if (b1 + 3 > (int)mmr->width)
946 break; 948 break;
947 if (c) { 949 if (c) {
948 if (b1 + 3 < a0 || a0 < 0) 950 if (a0 == MINUS1 || b1 + 3 < a0)
949 return -1; 951 return -1;
950 jbig2_set_bits(dst, a0, b1 + 3); 952 jbig2_set_bits(dst, a0, b1 + 3);
951 } 953 }
@@ -957,10 +959,10 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
957 /* printf ("VL(1)\n"); */ 959 /* printf ("VL(1)\n"); */
958 jbig2_decode_mmr_consume(mmr, 3); 960 jbig2_decode_mmr_consume(mmr, 3);
959 b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c); 961 b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
960 if (b1 - 1 < 0) 962 if (b1 < 1)
961 break; 963 break;
962 if (c) { 964 if (c) {
963 if (b1 - 1 < a0 || a0 < 0) 965 if (a0 == MINUS1 || b1 - 1 < a0)
964 return -1; 966 return -1;
965 jbig2_set_bits(dst, a0, b1 - 1); 967 jbig2_set_bits(dst, a0, b1 - 1);
966 } 968 }
@@ -972,7 +974,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
972 /* printf ("VL(2)\n"); */ 974 /* printf ("VL(2)\n"); */
973 jbig2_decode_mmr_consume(mmr, 6); 975 jbig2_decode_mmr_consume(mmr, 6);
974 b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c); 976 b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
975 if (b1 - 2 < 0) 977 if (b1 < 2)
976 break; 978 break;
977 if (c) { 979 if (c) {
978 if (b1 - 2 < a0 || a0 < 0) 980 if (b1 - 2 < a0 || a0 < 0)
@@ -987,10 +989,10 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
987 /* printf ("VL(3)\n"); */ 989 /* printf ("VL(3)\n"); */
988 jbig2_decode_mmr_consume(mmr, 7); 990 jbig2_decode_mmr_consume(mmr, 7);
989 b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c); 991 b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
990 if (b1 - 3 < 0) 992 if (b1 < 3)
991 break; 993 break;
992 if (c) { 994 if (c) {
993 if (b1 - 3 < a0 || a0 < 0) 995 if (a0 == MINUS1 || b1 - 3 < a0)
994 return -1; 996 return -1;
995 jbig2_set_bits(dst, a0, b1 - 3); 997 jbig2_set_bits(dst, a0, b1 - 3);
996 } 998 }
@@ -1009,10 +1011,10 @@ int
1009jbig2_decode_generic_mmr(Jbig2Ctx *ctx, Jbig2Segment *segment, const Jbig2GenericRegionParams *params, const byte *data, size_t size, Jbig2Image *image) 1011jbig2_decode_generic_mmr(Jbig2Ctx *ctx, Jbig2Segment *segment, const Jbig2GenericRegionParams *params, const byte *data, size_t size, Jbig2Image *image)
1010{ 1012{
1011 Jbig2MmrCtx mmr; 1013 Jbig2MmrCtx mmr;
1012 const int rowstride = image->stride; 1014 const uint32_t rowstride = image->stride;
1013 byte *dst = image->data; 1015 byte *dst = image->data;
1014 byte *ref = NULL; 1016 byte *ref = NULL;
1015 int y; 1017 uint32_t y;
1016 int code = 0; 1018 int code = 0;
1017 1019
1018 jbig2_decode_mmr_init(&mmr, image->width, image->height, data, size); 1020 jbig2_decode_mmr_init(&mmr, image->width, image->height, data, size);
@@ -1047,10 +1049,10 @@ int
1047jbig2_decode_halftone_mmr(Jbig2Ctx *ctx, const Jbig2GenericRegionParams *params, const byte *data, size_t size, Jbig2Image *image, size_t *consumed_bytes) 1049jbig2_decode_halftone_mmr(Jbig2Ctx *ctx, const Jbig2GenericRegionParams *params, const byte *data, size_t size, Jbig2Image *image, size_t *consumed_bytes)
1048{ 1050{
1049 Jbig2MmrCtx mmr; 1051 Jbig2MmrCtx mmr;
1050 const int rowstride = image->stride; 1052 const uint32_t rowstride = image->stride;
1051 byte *dst = image->data; 1053 byte *dst = image->data;
1052 byte *ref = NULL; 1054 byte *ref = NULL;
1053 int y; 1055 uint32_t y;
1054 int code = 0; 1056 int code = 0;
1055 const uint32_t EOFB = 0x001001; 1057 const uint32_t EOFB = 0x001001;
1056 1058
diff --git a/jbig2_page.c b/jbig2_page.c
index 110ff7c..1ed1c8a 100644
--- a/jbig2_page.c
+++ b/jbig2_page.c
@@ -155,9 +155,9 @@ int
155jbig2_end_of_stripe(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data) 155jbig2_end_of_stripe(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data)
156{ 156{
157 Jbig2Page page = ctx->pages[ctx->current_page]; 157 Jbig2Page page = ctx->pages[ctx->current_page];
158 int end_row; 158 uint32_t end_row;
159 159
160 end_row = jbig2_get_int32(segment_data); 160 end_row = jbig2_get_uint32(segment_data);
161 if (end_row < page.end_row) { 161 if (end_row < page.end_row) {
162 jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, 162 jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
163 "end of stripe segment with non-positive end row advance" " (new end row %d vs current end row %d)", end_row, page.end_row); 163 "end of stripe segment with non-positive end row advance" " (new end row %d vs current end row %d)", end_row, page.end_row);
@@ -248,7 +248,7 @@ jbig2_page_add_result(Jbig2Ctx *ctx, Jbig2Page *page, Jbig2Image *image, int x,
248 248
249 /* grow the page to accomodate a new stripe if necessary */ 249 /* grow the page to accomodate a new stripe if necessary */
250 if (page->striped) { 250 if (page->striped) {
251 int new_height = y + image->height + page->end_row; 251 uint32_t new_height = y + image->height + page->end_row;
252 252
253 if (page->image->height < new_height) { 253 if (page->image->height < new_height) {
254 jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "growing page buffer to %d rows " "to accomodate new stripe", new_height); 254 jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "growing page buffer to %d rows " "to accomodate new stripe", new_height);
diff --git a/jbig2_priv.h b/jbig2_priv.h
index 42ba496..3d44b42 100644
--- a/jbig2_priv.h
+++ b/jbig2_priv.h
@@ -132,7 +132,7 @@ struct _Jbig2Page {
132 uint32_t x_resolution, y_resolution; /* in pixels per meter */ 132 uint32_t x_resolution, y_resolution; /* in pixels per meter */
133 uint16_t stripe_size; 133 uint16_t stripe_size;
134 bool striped; 134 bool striped;
135 int end_row; 135 uint32_t end_row;
136 uint8_t flags; 136 uint8_t flags;
137 Jbig2Image *image; 137 Jbig2Image *image;
138}; 138};
@@ -182,7 +182,7 @@ int jbig2_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segm
182typedef struct _Jbig2WordStream Jbig2WordStream; 182typedef struct _Jbig2WordStream Jbig2WordStream;
183 183
184struct _Jbig2WordStream { 184struct _Jbig2WordStream {
185 int (*get_next_word)(Jbig2WordStream *self, int offset, uint32_t *word); 185 int (*get_next_word)(Jbig2WordStream *self, size_t offset, uint32_t *word);
186}; 186};
187 187
188Jbig2WordStream *jbig2_word_stream_buf_new(Jbig2Ctx *ctx, const byte *data, size_t size); 188Jbig2WordStream *jbig2_word_stream_buf_new(Jbig2Ctx *ctx, const byte *data, size_t size);
diff --git a/jbig2_segment.c b/jbig2_segment.c
index 2e0db67..5b63706 100644
--- a/jbig2_segment.c
+++ b/jbig2_segment.c
@@ -39,10 +39,10 @@ jbig2_parse_segment_header(Jbig2Ctx *ctx, uint8_t *buf, size_t buf_size, size_t
39 uint8_t rtscarf; 39 uint8_t rtscarf;
40 uint32_t rtscarf_long; 40 uint32_t rtscarf_long;
41 uint32_t *referred_to_segments; 41 uint32_t *referred_to_segments;
42 int referred_to_segment_count; 42 uint32_t referred_to_segment_count;
43 int referred_to_segment_size; 43 uint32_t referred_to_segment_size;
44 int pa_size; 44 uint32_t pa_size;
45 int offset; 45 uint32_t offset;
46 46
47 /* minimum possible size of a jbig2 segment header */ 47 /* minimum possible size of a jbig2 segment header */
48 if (buf_size < 11) 48 if (buf_size < 11)
@@ -83,7 +83,7 @@ jbig2_parse_segment_header(Jbig2Ctx *ctx, uint8_t *buf, size_t buf_size, size_t
83 83
84 /* 7.2.5 */ 84 /* 7.2.5 */
85 if (referred_to_segment_count) { 85 if (referred_to_segment_count) {
86 int i; 86 uint32_t i;
87 87
88 referred_to_segments = jbig2_new(ctx, uint32_t, referred_to_segment_count * referred_to_segment_size); 88 referred_to_segments = jbig2_new(ctx, uint32_t, referred_to_segment_count * referred_to_segment_size);
89 if (referred_to_segments == NULL) { 89 if (referred_to_segments == NULL) {
diff --git a/jbig2_symbol_dict.c b/jbig2_symbol_dict.c
index 2c71a4c..11a2252 100644
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -88,40 +88,40 @@ jbig2_dump_symbol_dict(Jbig2Ctx *ctx, Jbig2Segment *segment)
88 88
89/* return a new empty symbol dict */ 89/* return a new empty symbol dict */
90Jbig2SymbolDict * 90Jbig2SymbolDict *
91jbig2_sd_new(Jbig2Ctx *ctx, int n_symbols) 91jbig2_sd_new(Jbig2Ctx *ctx, uint32_t n_symbols)
92{ 92{
93 Jbig2SymbolDict *new = NULL; 93 Jbig2SymbolDict *new_dict = NULL;
94 94
95 if (n_symbols < 0) { 95 if (n_symbols < 0) {
96 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "Negative number of symbols in symbol dict: %d", n_symbols); 96 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "Negative number of symbols in symbol dict: %d", n_symbols);
97 return NULL; 97 return NULL;
98 } 98 }
99 99
100 new = jbig2_new(ctx, Jbig2SymbolDict, 1); 100 new_dict = jbig2_new(ctx, Jbig2SymbolDict, 1);
101 if (new != NULL) { 101 if (new_dict != NULL) {
102 new->glyphs = jbig2_new(ctx, Jbig2Image *, n_symbols); 102 new_dict->glyphs = jbig2_new(ctx, Jbig2Image *, n_symbols);
103 new->n_symbols = n_symbols; 103 new_dict->n_symbols = n_symbols;
104 } else { 104 } else {
105 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to allocate new empty symbol dict"); 105 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to allocate new empty symbol dict");
106 return NULL; 106 return NULL;
107 } 107 }
108 108
109 if (new->glyphs != NULL) { 109 if (new_dict->glyphs != NULL) {
110 memset(new->glyphs, 0, n_symbols * sizeof(Jbig2Image *)); 110 memset(new_dict->glyphs, 0, n_symbols * sizeof(Jbig2Image *));
111 } else { 111 } else {
112 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to allocate glyphs for new empty symbol dict"); 112 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to allocate glyphs for new empty symbol dict");
113 jbig2_free(ctx->allocator, new); 113 jbig2_free(ctx->allocator, new_dict);
114 return NULL; 114 return NULL;
115 } 115 }
116 116
117 return new; 117 return new_dict;
118} 118}
119 119
120/* release the memory associated with a symbol dict */ 120/* release the memory associated with a symbol dict */
121void 121void
122jbig2_sd_release(Jbig2Ctx *ctx, Jbig2SymbolDict *dict) 122jbig2_sd_release(Jbig2Ctx *ctx, Jbig2SymbolDict *dict)
123{ 123{
124 int i; 124 uint32_t i;
125 125
126 if (dict == NULL) 126 if (dict == NULL)
127 return; 127 return;
@@ -142,12 +142,12 @@ jbig2_sd_glyph(Jbig2SymbolDict *dict, unsigned int id)
142} 142}
143 143
144/* count the number of dictionary segments referred to by the given segment */ 144/* count the number of dictionary segments referred to by the given segment */
145int 145uint32_t
146jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment) 146jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment)
147{ 147{
148 int index; 148 int index;
149 Jbig2Segment *rsegment; 149 Jbig2Segment *rsegment;
150 int n_dicts = 0; 150 uint32_t n_dicts = 0;
151 151
152 for (index = 0; index < segment->referred_to_segment_count; index++) { 152 for (index = 0; index < segment->referred_to_segment_count; index++) {
153 rsegment = jbig2_find_segment(ctx, segment->referred_to_segments[index]); 153 rsegment = jbig2_find_segment(ctx, segment->referred_to_segments[index]);
@@ -166,8 +166,8 @@ jbig2_sd_list_referred(Jbig2Ctx *ctx, Jbig2Segment *segment)
166 int index; 166 int index;
167 Jbig2Segment *rsegment; 167 Jbig2Segment *rsegment;
168 Jbig2SymbolDict **dicts; 168 Jbig2SymbolDict **dicts;
169 int n_dicts = jbig2_sd_count_referred(ctx, segment); 169 uint32_t n_dicts = jbig2_sd_count_referred(ctx, segment);
170 int dindex = 0; 170 uint32_t dindex = 0;
171 171
172 dicts = jbig2_new(ctx, Jbig2SymbolDict *, n_dicts); 172 dicts = jbig2_new(ctx, Jbig2SymbolDict *, n_dicts);
173 if (dicts == NULL) { 173 if (dicts == NULL) {
@@ -195,10 +195,10 @@ jbig2_sd_list_referred(Jbig2Ctx *ctx, Jbig2Segment *segment)
195/* generate a new symbol dictionary by concatenating a list of 195/* generate a new symbol dictionary by concatenating a list of
196 existing dictionaries */ 196 existing dictionaries */
197Jbig2SymbolDict * 197Jbig2SymbolDict *
198jbig2_sd_cat(Jbig2Ctx *ctx, int n_dicts, Jbig2SymbolDict **dicts) 198jbig2_sd_cat(Jbig2Ctx *ctx, uint32_t n_dicts, Jbig2SymbolDict **dicts)
199{ 199{
200 int i, j, k, symbols; 200 uint32_t i, j, k, symbols;
201 Jbig2SymbolDict *new = NULL; 201 Jbig2SymbolDict *new_dict = NULL;
202 202
203 /* count the imported symbols and allocate a new array */ 203 /* count the imported symbols and allocate a new array */
204 symbols = 0; 204 symbols = 0;
@@ -206,17 +206,17 @@ jbig2_sd_cat(Jbig2Ctx *ctx, int n_dicts, Jbig2SymbolDict **dicts)
206 symbols += dicts[i]->n_symbols; 206 symbols += dicts[i]->n_symbols;
207 207
208 /* fill a new array with cloned glyph pointers */ 208 /* fill a new array with cloned glyph pointers */
209 new = jbig2_sd_new(ctx, symbols); 209 new_dict = jbig2_sd_new(ctx, symbols);
210 if (new != NULL) { 210 if (new_dict != NULL) {
211 k = 0; 211 k = 0;
212 for (i = 0; i < n_dicts; i++) 212 for (i = 0; i < n_dicts; i++)
213 for (j = 0; j < dicts[i]->n_symbols; j++) 213 for (j = 0; j < dicts[i]->n_symbols; j++)
214 new->glyphs[k++] = jbig2_image_clone(ctx, dicts[i]->glyphs[j]); 214 new_dict->glyphs[k++] = jbig2_image_clone(ctx, dicts[i]->glyphs[j]);
215 } else { 215 } else {
216 jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to allocate new symbol dictionary"); 216 jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to allocate new symbol dictionary");
217 } 217 }
218 218
219 return new; 219 return new_dict;
220} 220}
221 221
222/* Decoding routines */ 222/* Decoding routines */
@@ -431,7 +431,7 @@ jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
431 431
432 if (REFAGGNINST > 1) { 432 if (REFAGGNINST > 1) {
433 Jbig2Image *image; 433 Jbig2Image *image;
434 int i; 434 uint32_t i;
435 435
436 if (tparams == NULL) { 436 if (tparams == NULL) {
437 /* First time through, we need to initialise the */ 437 /* First time through, we need to initialise the */
@@ -512,7 +512,7 @@ jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
512 uint32_t ID; 512 uint32_t ID;
513 int32_t RDX, RDY; 513 int32_t RDX, RDY;
514 int BMSIZE = 0; 514 int BMSIZE = 0;
515 int ninsyms = params->SDNUMINSYMS; 515 uint32_t ninsyms = params->SDNUMINSYMS;
516 int code1 = 0; 516 int code1 = 0;
517 int code2 = 0; 517 int code2 = 0;
518 int code3 = 0; 518 int code3 = 0;
@@ -609,8 +609,9 @@ jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
609 if (params->SDHUFF && !params->SDREFAGG) { 609 if (params->SDHUFF && !params->SDREFAGG) {
610 /* 6.5.9 */ 610 /* 6.5.9 */
611 Jbig2Image *image; 611 Jbig2Image *image;
612 int BMSIZE = jbig2_huffman_get(hs, params->SDHUFFBMSIZE, &code); 612 uint32_t BMSIZE = jbig2_huffman_get(hs, params->SDHUFFBMSIZE, &code);
613 int j, x; 613 uint32_t j;
614 int x;
614 615
615 if (code || (BMSIZE < 0)) { 616 if (code || (BMSIZE < 0)) {
616 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "error decoding size of collective bitmap!"); 617 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "error decoding size of collective bitmap!");
@@ -700,22 +701,22 @@ jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
700 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate symbols exported from symbols dictionary"); 701 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate symbols exported from symbols dictionary");
701 goto cleanup4; 702 goto cleanup4;
702 } else { 703 } else {
703 int i = 0; 704 uint32_t i = 0;
704 int j = 0; 705 uint32_t j = 0;
705 int k; 706 uint32_t k;
706 int exflag = 0; 707 int exflag = 0;
707 int64_t limit = params->SDNUMINSYMS + params->SDNUMNEWSYMS; 708 uint32_t limit = params->SDNUMINSYMS + params->SDNUMNEWSYMS;
708 int32_t exrunlength; 709 uint32_t exrunlength;
709 int zerolength = 0; 710 int zerolength = 0;
710 711
711 while (i < limit) { 712 while (i < limit) {
712 if (params->SDHUFF) 713 if (params->SDHUFF)
713 exrunlength = jbig2_huffman_get(hs, SBHUFFRSIZE, &code); 714 exrunlength = jbig2_huffman_get(hs, SBHUFFRSIZE, &code);
714 else 715 else
715 code = jbig2_arith_int_decode(IAEX, as, &exrunlength); 716 code = jbig2_arith_int_decode(IAEX, as, (int32_t *)&exrunlength);
716 /* prevent infinite loop */ 717 /* prevent infinite loop */
717 zerolength = exrunlength > 0 ? 0 : zerolength + 1; 718 zerolength = exrunlength > 0 ? 0 : zerolength + 1;
718 if (code || (exrunlength > limit - i) || (exrunlength < 0) || (zerolength > 4) || (exflag && (exrunlength > params->SDNUMEXSYMS - j))) { 719 if (code || (exrunlength > limit - i) || (exrunlength < 0) || (zerolength > 4) || (exflag && (exrunlength + j > params->SDNUMEXSYMS))) {
719 if (code) 720 if (code)
720 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode exrunlength for exported symbols"); 721 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode exrunlength for exported symbols");
721 else if (exrunlength <= 0) 722 else if (exrunlength <= 0)
@@ -797,8 +798,8 @@ jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segmen
797{ 798{
798 Jbig2SymbolDictParams params; 799 Jbig2SymbolDictParams params;
799 uint16_t flags; 800 uint16_t flags;
800 int sdat_bytes; 801 uint32_t sdat_bytes;
801 int offset; 802 uint32_t offset;
802 Jbig2ArithCx *GB_stats = NULL; 803 Jbig2ArithCx *GB_stats = NULL;
803 Jbig2ArithCx *GR_stats = NULL; 804 Jbig2ArithCx *GR_stats = NULL;
804 int table_index = 0; 805 int table_index = 0;
@@ -951,7 +952,7 @@ jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segmen
951 952
952 /* 7.4.2.2 (2) */ 953 /* 7.4.2.2 (2) */
953 { 954 {
954 int n_dicts = jbig2_sd_count_referred(ctx, segment); 955 uint32_t n_dicts = jbig2_sd_count_referred(ctx, segment);
955 Jbig2SymbolDict **dicts = NULL; 956 Jbig2SymbolDict **dicts = NULL;
956 957
957 if (n_dicts > 0) { 958 if (n_dicts > 0) {
diff --git a/jbig2_symbol_dict.h b/jbig2_symbol_dict.h
index d56d62d..30211d4 100644
--- a/jbig2_symbol_dict.h
+++ b/jbig2_symbol_dict.h
@@ -32,18 +32,18 @@ int jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *se
32Jbig2Image *jbig2_sd_glyph(Jbig2SymbolDict *dict, unsigned int id); 32Jbig2Image *jbig2_sd_glyph(Jbig2SymbolDict *dict, unsigned int id);
33 33
34/* return a new empty symbol dict */ 34/* return a new empty symbol dict */
35Jbig2SymbolDict *jbig2_sd_new(Jbig2Ctx *ctx, int n_symbols); 35Jbig2SymbolDict *jbig2_sd_new(Jbig2Ctx *ctx, uint32_t n_symbols);
36 36
37/* release the memory associated with a symbol dict */ 37/* release the memory associated with a symbol dict */
38void jbig2_sd_release(Jbig2Ctx *ctx, Jbig2SymbolDict *dict); 38void jbig2_sd_release(Jbig2Ctx *ctx, Jbig2SymbolDict *dict);
39 39
40/* generate a new symbol dictionary by concatenating a list of 40/* generate a new symbol dictionary by concatenating a list of
41 existing dictionaries */ 41 existing dictionaries */
42Jbig2SymbolDict *jbig2_sd_cat(Jbig2Ctx *ctx, int n_dicts, Jbig2SymbolDict **dicts); 42Jbig2SymbolDict *jbig2_sd_cat(Jbig2Ctx *ctx, uint32_t n_dicts, Jbig2SymbolDict **dicts);
43 43
44/* count the number of dictionary segments referred 44/* count the number of dictionary segments referred
45 to by the given segment */ 45 to by the given segment */
46int jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment); 46uint32_t jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment);
47 47
48/* return an array of pointers to symbol dictionaries referred 48/* return an array of pointers to symbol dictionaries referred
49 to by a segment */ 49 to by a segment */
diff --git a/jbig2_text.c b/jbig2_text.c
index 5c99640..e77460f 100644
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -55,7 +55,7 @@
55int 55int
56jbig2_decode_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, 56jbig2_decode_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
57 const Jbig2TextRegionParams *params, 57 const Jbig2TextRegionParams *params,
58 const Jbig2SymbolDict *const *dicts, const int n_dicts, 58 const Jbig2SymbolDict *const *dicts, const uint32_t n_dicts,
59 Jbig2Image *image, const byte *data, const size_t size, Jbig2ArithCx *GR_stats, Jbig2ArithState *as, Jbig2WordStream *ws) 59 Jbig2Image *image, const byte *data, const size_t size, Jbig2ArithCx *GR_stats, Jbig2ArithState *as, Jbig2WordStream *ws)
60{ 60{
61 /* relevent bits of 6.4.4 */ 61 /* relevent bits of 6.4.4 */
@@ -476,19 +476,19 @@ cleanup2:
476int 476int
477jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data) 477jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data)
478{ 478{
479 int offset = 0; 479 uint32_t offset = 0;
480 Jbig2RegionSegmentInfo region_info; 480 Jbig2RegionSegmentInfo region_info;
481 Jbig2TextRegionParams params; 481 Jbig2TextRegionParams params;
482 Jbig2Image *image = NULL; 482 Jbig2Image *image = NULL;
483 Jbig2SymbolDict **dicts = NULL; 483 Jbig2SymbolDict **dicts = NULL;
484 int n_dicts = 0; 484 uint32_t n_dicts = 0;
485 uint16_t flags = 0; 485 uint16_t flags = 0;
486 uint16_t huffman_flags = 0; 486 uint16_t huffman_flags = 0;
487 Jbig2ArithCx *GR_stats = NULL; 487 Jbig2ArithCx *GR_stats = NULL;
488 int code = 0; 488 int code = 0;
489 Jbig2WordStream *ws = NULL; 489 Jbig2WordStream *ws = NULL;
490 Jbig2ArithState *as = NULL; 490 Jbig2ArithState *as = NULL;
491 int table_index = 0; 491 uint32_t table_index = 0;
492 const Jbig2HuffmanParams *huffman_params = NULL; 492 const Jbig2HuffmanParams *huffman_params = NULL;
493 493
494 /* 7.4.1 */ 494 /* 7.4.1 */
@@ -779,7 +779,7 @@ jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data
779 code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "unable to retrive symbol dictionaries! previous parsing error?"); 779 code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "unable to retrive symbol dictionaries! previous parsing error?");
780 goto cleanup1; 780 goto cleanup1;
781 } else { 781 } else {
782 int index; 782 uint32_t index;
783 783
784 if (dicts[0] == NULL) { 784 if (dicts[0] == NULL) {
785 code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to find first referenced symbol dictionary!"); 785 code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to find first referenced symbol dictionary!");
@@ -823,8 +823,8 @@ jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data
823 } 823 }
824 824
825 if (!params.SBHUFF) { 825 if (!params.SBHUFF) {
826 int SBSYMCODELEN, index; 826 uint32_t SBSYMCODELEN, index;
827 int SBNUMSYMS = 0; 827 uint32_t SBNUMSYMS = 0;
828 828
829 for (index = 0; index < n_dicts; index++) { 829 for (index = 0; index < n_dicts; index++) {
830 SBNUMSYMS += dicts[index]->n_symbols; 830 SBNUMSYMS += dicts[index]->n_symbols;
@@ -840,7 +840,7 @@ jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data
840 } 840 }
841 841
842 /* Table 31 */ 842 /* Table 31 */
843 for (SBSYMCODELEN = 0; (1 << SBSYMCODELEN) < SBNUMSYMS; SBSYMCODELEN++) { 843 for (SBSYMCODELEN = 0; (1U << SBSYMCODELEN) < SBNUMSYMS; SBSYMCODELEN++) {
844 } 844 }
845 params.IAID = jbig2_arith_iaid_ctx_new(ctx, SBSYMCODELEN); 845 params.IAID = jbig2_arith_iaid_ctx_new(ctx, SBSYMCODELEN);
846 params.IARI = jbig2_arith_int_ctx_new(ctx); 846 params.IARI = jbig2_arith_int_ctx_new(ctx);
diff --git a/jbig2_text.h b/jbig2_text.h
index aec2732..51d242e 100644
--- a/jbig2_text.h
+++ b/jbig2_text.h
@@ -70,5 +70,5 @@ typedef struct {
70int 70int
71jbig2_decode_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, 71jbig2_decode_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
72 const Jbig2TextRegionParams *params, 72 const Jbig2TextRegionParams *params,
73 const Jbig2SymbolDict *const *dicts, const int n_dicts, 73 const Jbig2SymbolDict *const *dicts, const uint32_t n_dicts,
74 Jbig2Image *image, const byte *data, const size_t size, Jbig2ArithCx *GR_stats, Jbig2ArithState *as, Jbig2WordStream *ws); 74 Jbig2Image *image, const byte *data, const size_t size, Jbig2ArithCx *GR_stats, Jbig2ArithState *as, Jbig2WordStream *ws);