summaryrefslogtreecommitdiff
path: root/jbig2dec
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2019-09-29 12:09:40 +0200
committerSebastian Rasmussen <sebras@gmail.com>2020-03-20 17:56:08 +0800
commit5947fb2f1c022982e82406639517ebacae8d5cf6 (patch)
treeed3b3b258e176c22c0f35cfdadb5f91b9e60afc8 /jbig2dec
parent9394be6a45aea026f61900e1cb661a30db192c15 (diff)
downloadghostpdl-5947fb2f1c022982e82406639517ebacae8d5cf6.tar.gz
jbig2dec: Address all signedness comparison issues.
Diffstat (limited to 'jbig2dec')
-rw-r--r--jbig2dec/jbig2_arith.c4
-rw-r--r--jbig2dec/jbig2_arith_iaid.c6
-rw-r--r--jbig2dec/jbig2_arith_iaid.h2
-rw-r--r--jbig2dec/jbig2_halftone.c16
-rw-r--r--jbig2dec/jbig2_halftone.h2
-rw-r--r--jbig2dec/jbig2_huffman.c4
-rw-r--r--jbig2dec/jbig2_symbol_dict.c7
-rw-r--r--jbig2dec/jbig2_text.c7
8 files changed, 24 insertions, 24 deletions
diff --git a/jbig2dec/jbig2_arith.c b/jbig2dec/jbig2_arith.c
index 6ce00e693..116c55c3d 100644
--- a/jbig2dec/jbig2_arith.c
+++ b/jbig2dec/jbig2_arith.c
@@ -31,7 +31,7 @@
struct _Jbig2ArithState {
uint32_t C;
- int A;
+ uint32_t A;
int CT;
@@ -228,7 +228,7 @@ jbig2_arith_new(Jbig2Ctx *ctx, Jbig2WordStream *ws)
/* could put bit fields in to minimize memory usage */
typedef struct {
- unsigned short Qe;
+ uint16_t Qe;
byte mps_xor; /* mps_xor = index ^ NMPS */
byte lps_xor; /* lps_xor = index ^ NLPS ^ (SWITCH << 7) */
} Jbig2ArithQe;
diff --git a/jbig2dec/jbig2_arith_iaid.c b/jbig2dec/jbig2_arith_iaid.c
index bbc38a0b6..11358349d 100644
--- a/jbig2dec/jbig2_arith_iaid.c
+++ b/jbig2dec/jbig2_arith_iaid.c
@@ -37,12 +37,12 @@
#include "jbig2_arith_iaid.h"
struct _Jbig2ArithIaidCtx {
- int SBSYMCODELEN;
+ uint8_t SBSYMCODELEN;
Jbig2ArithCx *IAIDx;
};
Jbig2ArithIaidCtx *
-jbig2_arith_iaid_ctx_new(Jbig2Ctx *ctx, int SBSYMCODELEN)
+jbig2_arith_iaid_ctx_new(Jbig2Ctx *ctx, uint8_t SBSYMCODELEN)
{
Jbig2ArithIaidCtx *result;
size_t ctx_size;
@@ -80,7 +80,7 @@ int
jbig2_arith_iaid_decode(Jbig2Ctx *ctx, Jbig2ArithIaidCtx *actx, Jbig2ArithState *as, int32_t *p_result)
{
Jbig2ArithCx *IAIDx = actx->IAIDx;
- int SBSYMCODELEN = actx->SBSYMCODELEN;
+ uint8_t SBSYMCODELEN = actx->SBSYMCODELEN;
/* A.3 (1) */
int PREV = 1;
int D;
diff --git a/jbig2dec/jbig2_arith_iaid.h b/jbig2dec/jbig2_arith_iaid.h
index b0b3a652b..bd87879d4 100644
--- a/jbig2dec/jbig2_arith_iaid.h
+++ b/jbig2dec/jbig2_arith_iaid.h
@@ -22,7 +22,7 @@
typedef struct _Jbig2ArithIaidCtx Jbig2ArithIaidCtx;
-Jbig2ArithIaidCtx *jbig2_arith_iaid_ctx_new(Jbig2Ctx *ctx, int SBSYMCODELEN);
+Jbig2ArithIaidCtx *jbig2_arith_iaid_ctx_new(Jbig2Ctx *ctx, uint8_t SBSYMCODELEN);
int jbig2_arith_iaid_decode(Jbig2Ctx *ctx, Jbig2ArithIaidCtx *actx, Jbig2ArithState *as, int32_t *p_result);
diff --git a/jbig2dec/jbig2_halftone.c b/jbig2dec/jbig2_halftone.c
index e67c6d18f..b2b7bdbcb 100644
--- a/jbig2dec/jbig2_halftone.c
+++ b/jbig2dec/jbig2_halftone.c
@@ -47,8 +47,7 @@ jbig2_hd_new(Jbig2Ctx *ctx, const Jbig2PatternDictParams *params, Jbig2Image *im
const uint32_t HPW = params->HDPW;
const uint32_t HPH = params->HDPH;
int code;
- uint32_t i;
- int j;
+ uint32_t i, j;
if (N == 0) {
/* We've wrapped. */
@@ -464,8 +463,7 @@ jbig2_decode_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
Jbig2Image *HSKIP = NULL;
Jbig2PatternDict *HPATS;
uint32_t i;
- int32_t mg, ng;
- int32_t x, y;
+ uint32_t mg, ng;
uint16_t gray_val;
int code = 0;
@@ -487,10 +485,10 @@ jbig2_decode_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
for (mg = 0; mg < params->HGH; ++mg) {
for (ng = 0; ng < params->HGW; ++ng) {
- x = (params->HGX + mg * params->HRY + ng * params->HRX) >> 8;
- y = (params->HGY + mg * params->HRX - ng * params->HRY) >> 8;
+ int64_t x = ((int64_t) params->HGX + mg * params->HRY + ng * params->HRX) >> 8;
+ int64_t y = ((int64_t) params->HGY + mg * params->HRX - ng * params->HRY) >> 8;
- if (x + HPATS->HPW <= 0 || x >= (int32_t) image->width || y + HPATS->HPH <= 0 || y >= (int32_t) image->height) {
+ if (x + HPATS->HPW <= 0 || x >= image->width || y + HPATS->HPH <= 0 || y >= image->height) {
jbig2_image_set_pixel(HSKIP, ng, mg, 1);
} else {
jbig2_image_set_pixel(HSKIP, ng, mg, 0);
@@ -519,8 +517,8 @@ jbig2_decode_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
/* 6.6.5 point 5. place patterns with procedure mentioned in 6.6.5.2 */
for (mg = 0; mg < params->HGH; ++mg) {
for (ng = 0; ng < params->HGW; ++ng) {
- x = (params->HGX + mg * (int32_t) params->HRY + ng * (int32_t) params->HRX) >> 8;
- y = (params->HGY + mg * (int32_t) params->HRX - ng * (int32_t) params->HRY) >> 8;
+ int64_t x = ((int64_t) params->HGX + mg * params->HRY + ng * params->HRX) >> 8;
+ int64_t y = ((int64_t) params->HGY + mg * params->HRX - ng * params->HRY) >> 8;
/* prevent pattern index >= HNUMPATS */
gray_val = GI[ng][mg];
diff --git a/jbig2dec/jbig2_halftone.h b/jbig2dec/jbig2_halftone.h
index 22bf666c5..08e1e1569 100644
--- a/jbig2dec/jbig2_halftone.h
+++ b/jbig2dec/jbig2_halftone.h
@@ -23,7 +23,7 @@
typedef struct {
int n_patterns;
Jbig2Image **patterns;
- int HPW, HPH;
+ uint32_t HPW, HPH;
} Jbig2PatternDict;
/* Table 24 */
diff --git a/jbig2dec/jbig2_huffman.c b/jbig2dec/jbig2_huffman.c
index 59bf8b223..f975b9fa8 100644
--- a/jbig2dec/jbig2_huffman.c
+++ b/jbig2dec/jbig2_huffman.c
@@ -2072,13 +2072,13 @@ static int test2()
return 0;
}
- for (i = 0; i < countof(tests); i++) {
+ for (i = 0; i < (int) countof(tests); i++) {
Jbig2HuffmanTable *table;
Jbig2HuffmanState *hs;
test_stream_t st;
int32_t code;
bool oob;
- int j;
+ size_t j;
st.ws.get_next_word = test_get_word2;
st.h = &tests[i];
diff --git a/jbig2dec/jbig2_symbol_dict.c b/jbig2dec/jbig2_symbol_dict.c
index bc6e98c3e..f5022af3b 100644
--- a/jbig2dec/jbig2_symbol_dict.c
+++ b/jbig2dec/jbig2_symbol_dict.c
@@ -236,7 +236,7 @@ jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
uint32_t SYMWIDTH, TOTWIDTH;
uint32_t HCFIRSTSYM;
uint32_t *SDNEWSYMWIDTHS = NULL;
- int SBSYMCODELEN = 0;
+ uint8_t SBSYMCODELEN = 0;
Jbig2WordStream *ws = NULL;
Jbig2HuffmanState *hs = NULL;
Jbig2ArithState *as = NULL;
@@ -271,6 +271,8 @@ jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
return NULL;
}
+ for (SBSYMCODELEN = 0; ((uint64_t) 1 << SBSYMCODELEN) < ((uint64_t) params->SDNUMINSYMS + params->SDNUMNEWSYMS); SBSYMCODELEN++);
+
if (params->SDHUFF) {
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, "huffman coded symbol dictionary");
hs = jbig2_huffman_new(ctx, ws);
@@ -311,7 +313,6 @@ jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate symbol bitmap");
goto cleanup;
}
- for (SBSYMCODELEN = 0; ((uint64_t) 1 << SBSYMCODELEN) < ((uint64_t) params->SDNUMINSYMS + params->SDNUMNEWSYMS); SBSYMCODELEN++);
tparams.IAID = jbig2_arith_iaid_ctx_new(ctx, SBSYMCODELEN);
tparams.IARDX = jbig2_arith_int_ctx_new(ctx);
tparams.IARDY = jbig2_arith_int_ctx_new(ctx);
@@ -432,7 +433,7 @@ jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "DW value (%d) would make SYMWIDTH (%u) negative at symbol %u", DW, SYMWIDTH, NSYMSDECODED + 1);
goto cleanup;
}
- if (DW > 0 && DW > UINT32_MAX - SYMWIDTH) {
+ if (DW > 0 && (uint32_t) DW > UINT32_MAX - SYMWIDTH) {
code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "DW value (%d) would make SYMWIDTH (%u) too large at symbol %u", DW, SYMWIDTH, NSYMSDECODED + 1);
goto cleanup;
}
diff --git a/jbig2dec/jbig2_text.c b/jbig2dec/jbig2_text.c
index 57b31de02..6d983b6dd 100644
--- a/jbig2dec/jbig2_text.c
+++ b/jbig2dec/jbig2_text.c
@@ -937,7 +937,8 @@ jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data
}
if (!params.SBHUFF) {
- uint32_t SBSYMCODELEN, index;
+ uint8_t SBSYMCODELEN;
+ uint32_t index;
uint32_t SBNUMSYMS = 0;
for (index = 0; index < n_dicts; index++) {
@@ -954,8 +955,8 @@ jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data
}
/* Table 31 */
- for (SBSYMCODELEN = 0; (1U << SBSYMCODELEN) < SBNUMSYMS; SBSYMCODELEN++) {
- }
+ for (SBSYMCODELEN = 0; ((uint64_t) 1 << SBSYMCODELEN) < (uint64_t) SBNUMSYMS; SBSYMCODELEN++);
+
params.IAID = jbig2_arith_iaid_ctx_new(ctx, SBSYMCODELEN);
params.IARI = jbig2_arith_int_ctx_new(ctx);
params.IARDW = jbig2_arith_int_ctx_new(ctx);