ref: 36a8a98780518f0cfe3f4afd9ea34b7b21ba2ac5
parent: d0edf5a64a15f019db986a60e4e6db1846e5e19a
author: Shailesh Mistry <shailesh.mistry@hotmail.co.uk>
date: Fri Feb 10 23:30:56 EST 2017
Bug 697531 : Tidy up unused code. The first patch for this bug made the error return from jbig2_word_stream_buf_get_next_word pointless so this patch removes all the remaining redundant code. jbig2_word_stream_buf_get_next_word does not need to return any value so this is now defined as a void type and the rest of the code has been updated accordingly.
--- a/jbig2.c
+++ b/jbig2.c
@@ -378,7 +378,7 @@
size_t size;
} Jbig2WordStreamBuf;
-static int
+static void
jbig2_word_stream_buf_get_next_word(Jbig2WordStream *self, size_t offset, uint32_t *word)
{
Jbig2WordStreamBuf *z = (Jbig2WordStreamBuf *) self;
@@ -393,8 +393,6 @@
for (i = 0; i < z->size - offset; i++)
*word |= data[offset + i] << ((3 - i) << 3);
}
-
- return 0;
}
Jbig2WordStream *
--- a/jbig2_arith.c
+++ b/jbig2_arith.c
@@ -40,8 +40,6 @@
Jbig2WordStream *ws;
int offset;
-
- Jbig2Ctx *ctx;
};
#undef SOFTWARE_CONVENTION
@@ -60,7 +58,7 @@
*/
-static int
+static void
jbig2_arith_bytein(Jbig2ArithState *as)
{
byte B;
@@ -75,10 +73,7 @@
if (as->next_word_bytes == 1) {
Jbig2WordStream *ws = as->ws;
- if (ws->get_next_word(ws, as->offset, &as->next_word)) {
- jbig2_error(as->ctx, JBIG2_SEVERITY_FATAL, -1, "end of jbig2 buffer reached at offset %d", as->offset);
- return -1;
- }
+ ws->get_next_word(ws, as->offset, &as->next_word);
as->offset += 4;
B1 = (byte)((as->next_word >> 24) & 0xFF);
if (B1 > 0x8F) {
@@ -138,10 +133,7 @@
if (as->next_word_bytes == 0) {
Jbig2WordStream *ws = as->ws;
- if (ws->get_next_word(ws, as->offset, &as->next_word)) {
- jbig2_error(as->ctx, JBIG2_SEVERITY_FATAL, -1, "end of jbig2 buffer reached at offset %d", as->offset);
- return -1;
- }
+ ws->get_next_word(ws, as->offset, &as->next_word);
as->offset += 4;
as->next_word_bytes = 4;
}
@@ -152,7 +144,6 @@
as->C += (B << 8);
#endif
}
- return 0;
}
#if defined(JBIG2_DEBUG) || defined(JBIG2_DEBUG_ARITH)
@@ -179,13 +170,8 @@
}
result->ws = ws;
- result->ctx = ctx;
- if (ws->get_next_word(ws, 0, &result->next_word)) {
- jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to get first word in jbig2_arith_new");
- jbig2_free(ctx->allocator, result);
- return NULL;
- }
+ ws->get_next_word(ws, 0, &result->next_word);
result->next_word_bytes = 4;
result->offset = 4;
@@ -196,10 +182,7 @@
result->C = (result->next_word >> 8) & 0xFF0000;
#endif
- if (jbig2_arith_bytein(result)) {
- jbig2_free(ctx->allocator, result);
- return NULL;
- }
+ jbig2_arith_bytein(result);
result->C <<= 7;
result->CT -= 7;
result->A = 0x8000;
@@ -266,18 +249,17 @@
{0x5601, 46 ^ 46, 46 ^ 46}
};
-static int
+static void
jbig2_arith_renormd(Jbig2ArithState *as)
{
/* Figure E.18 */
do {
- if ((as->CT == 0) && (jbig2_arith_bytein(as) < 0))
- return -1;
+ if (as->CT == 0)
+ jbig2_arith_bytein(as);
as->A <<= 1;
as->C <<= 1;
as->CT--;
} while ((as->A & 0x8000) == 0);
- return 0;
}
bool
@@ -316,8 +298,7 @@
D = cx >> 7;
*pcx ^= pqe->mps_xor;
}
- if (jbig2_arith_renormd(as))
- return -1;
+ jbig2_arith_renormd(as);
return D;
} else
return cx >> 7;
@@ -335,8 +316,7 @@
D = 1 - (cx >> 7);
*pcx ^= pqe->lps_xor;
}
- if (jbig2_arith_renormd(as))
- return -1;
+ jbig2_arith_renormd(as);
return D;
}
}
@@ -349,7 +329,7 @@
#ifdef TEST
-static int
+static uint32_t
test_get_word(Jbig2WordStream *self, int offset, uint32_t *word)
{
byte stream[] = {
@@ -359,8 +339,10 @@
0x00, 0x00
};
if (offset >= sizeof(stream))
- return -1;
- *word = (stream[offset] << 24) | (stream[offset + 1] << 16) | (stream[offset + 2] << 8) | stream[offset + 3];
+ *word = 0;
+ else
+ *word = (stream[offset] << 24) | (stream[offset + 1] << 16) |
+ (stream[offset + 2] << 8) | stream[offset + 3];
return 0;
}
--- a/jbig2_arith_iaid.c
+++ b/jbig2_arith_iaid.c
@@ -77,8 +77,6 @@
/* A.3 (2) */
for (i = 0; i < SBSYMCODELEN; i++) {
D = jbig2_arith_decode(as, &IAIDx[PREV]);
- if (D < 0)
- return -1;
#ifdef VERBOSE
fprintf(stderr, "IAID%x: D = %d\n", PREV, D);
#endif
--- a/jbig2_arith_int.c
+++ b/jbig2_arith_int.c
@@ -63,36 +63,24 @@
int i;
S = jbig2_arith_decode(as, &IAx[PREV]);
- if (S < 0)
- return -1;
PREV = (PREV << 1) | S;
bit = jbig2_arith_decode(as, &IAx[PREV]);
- if (bit < 0)
- return -1;
PREV = (PREV << 1) | bit;
if (bit) {
bit = jbig2_arith_decode(as, &IAx[PREV]);
- if (bit < 0)
- return -1;
PREV = (PREV << 1) | bit;
if (bit) {
bit = jbig2_arith_decode(as, &IAx[PREV]);
- if (bit < 0)
- return -1;
PREV = (PREV << 1) | bit;
if (bit) {
bit = jbig2_arith_decode(as, &IAx[PREV]);
- if (bit < 0)
- return -1;
PREV = (PREV << 1) | bit;
if (bit) {
bit = jbig2_arith_decode(as, &IAx[PREV]);
- if (bit < 0)
- return -1;
PREV = (PREV << 1) | bit;
if (bit) {
@@ -122,8 +110,6 @@
V = 0;
for (i = 0; i < n_tail; i++) {
bit = jbig2_arith_decode(as, &IAx[PREV]);
- if (bit < 0)
- return -1;
PREV = ((PREV << 1) & 511) | (PREV & 256) | bit;
V = (V << 1) | bit;
}
--- a/jbig2_generic.c
+++ b/jbig2_generic.c
@@ -96,8 +96,6 @@
bool bit;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
- if (bit < 0)
- return -1;
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x7bf7) << 1) | bit | ((line_m1 >> (7 - x_minor)) & 0x10) | ((line_m2 >> (7 - x_minor)) & 0x800);
}
@@ -145,8 +143,6 @@
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 2) << 14;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[6], y + params->gbat[7]) << 15;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
- if (bit < 0)
- return -1;
jbig2_image_set_pixel(image, x, y, bit);
}
}
@@ -200,8 +196,6 @@
bool bit;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
- if (bit < 0)
- return -1;
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0xefb) << 1) | bit | ((line_m1 >> (8 - x_minor)) & 0x8) | ((line_m2 >> (8 - x_minor)) & 0x200);
}
@@ -263,8 +257,6 @@
bool bit;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
- if (bit < 0)
- return -1;
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x1bd) << 1) | bit | ((line_m1 >> (10 - x_minor)) & 0x4) | ((line_m2 >> (10 - x_minor)) & 0x80);
}
@@ -326,8 +318,6 @@
bool bit;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
- if (bit < 0)
- return -1;
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x1b9) << 1) | bit |
((line_m1 >> (10 - x_minor)) & 0x8) | ((line_m1 >> (9 - x_minor)) & 0x4) | ((line_m2 >> (10 - x_minor)) & 0x80);
@@ -386,8 +376,6 @@
bool bit;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
- if (bit < 0)
- return -1;
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x1f7) << 1) | bit | ((line_m1 >> (10 - x_minor)) & 0x010);
}
@@ -430,8 +418,6 @@
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y - 1) << 8;
CONTEXT |= jbig2_image_get_pixel(image, x - 3, y - 1) << 9;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
- if (bit < 0)
- return -1;
jbig2_image_set_pixel(image, x, y, bit);
}
}
@@ -465,10 +451,7 @@
int LTP = 0;
for (y = 0; y < GBH; y++) {
- bit = jbig2_arith_decode(as, &GB_stats[0x9B25]);
- if (bit < 0)
- return -1;
- LTP ^= bit;
+ LTP ^= jbig2_arith_decode(as, &GB_stats[0x9B25]);
if (!LTP) {
for (x = 0; x < GBW; x++) {
CONTEXT = jbig2_image_get_pixel(image, x - 1, y);
@@ -488,8 +471,6 @@
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 2) << 14;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[6], y + params->gbat[7]) << 15;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
- if (bit < 0)
- return -1;
jbig2_image_set_pixel(image, x, y, bit);
}
} else {
@@ -513,10 +494,7 @@
int LTP = 0;
for (y = 0; y < GBH; y++) {
- bit = jbig2_arith_decode(as, &GB_stats[0x0795]);
- if (bit < 0)
- return -1;
- LTP ^= bit;
+ LTP ^= jbig2_arith_decode(as, &GB_stats[0x0795]);
if (!LTP) {
for (x = 0; x < GBW; x++) {
CONTEXT = jbig2_image_get_pixel(image, x - 1, y);
@@ -533,8 +511,6 @@
CONTEXT |= jbig2_image_get_pixel(image, x, y - 2) << 11;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 2) << 12;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
- if (bit < 0)
- return -1;
jbig2_image_set_pixel(image, x, y, bit);
}
} else {
@@ -558,10 +534,7 @@
int LTP = 0;
for (y = 0; y < GBH; y++) {
- bit = jbig2_arith_decode(as, &GB_stats[0xE5]);
- if (bit < 0)
- return -1;
- LTP ^= bit;
+ LTP ^= jbig2_arith_decode(as, &GB_stats[0xE5]);
if (!LTP) {
for (x = 0; x < GBW; x++) {
CONTEXT = jbig2_image_get_pixel(image, x - 1, y);
@@ -575,8 +548,6 @@
CONTEXT |= jbig2_image_get_pixel(image, x, y - 2) << 8;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 2) << 9;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
- if (bit < 0)
- return -1;
jbig2_image_set_pixel(image, x, y, bit);
}
} else {
@@ -600,10 +571,7 @@
int LTP = 0;
for (y = 0; y < GBH; y++) {
- bit = jbig2_arith_decode(as, &GB_stats[0x0195]);
- if (bit < 0)
- return -1;
- LTP ^= bit;
+ LTP ^= jbig2_arith_decode(as, &GB_stats[0x0195]);
if (!LTP) {
for (x = 0; x < GBW; x++) {
CONTEXT = jbig2_image_get_pixel(image, x - 1, y);
@@ -617,8 +585,6 @@
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y - 1) << 8;
CONTEXT |= jbig2_image_get_pixel(image, x - 3, y - 1) << 9;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
- if (bit < 0)
- return -1;
jbig2_image_set_pixel(image, x, y, bit);
}
} else {
--- a/jbig2_huffman.c
+++ b/jbig2_huffman.c
@@ -61,8 +61,7 @@
uint32_t word = 0;
Jbig2WordStream *ws = hs->ws;
- if ((ws->get_next_word(ws, offset, &word)) && ((hs->offset_limit == 0) || (offset < hs->offset_limit)))
- hs->offset_limit = offset;
+ ws->get_next_word(ws, offset, &word);
return word;
}
--- a/jbig2_priv.h
+++ b/jbig2_priv.h
@@ -182,7 +182,7 @@
typedef struct _Jbig2WordStream Jbig2WordStream;
struct _Jbig2WordStream {
- int (*get_next_word)(Jbig2WordStream *self, size_t offset, uint32_t *word);
+ void (*get_next_word)(Jbig2WordStream *self, size_t offset, uint32_t *word);
};
Jbig2WordStream *jbig2_word_stream_buf_new(Jbig2Ctx *ctx, const byte *data, size_t size);
--- a/jbig2_refinement.c
+++ b/jbig2_refinement.c
@@ -78,8 +78,6 @@
CONTEXT |= jbig2_image_get_pixel(ref, x - dx + 0, y - dy - 1) << 11;
CONTEXT |= jbig2_image_get_pixel(ref, x - dx + params->grat[2], y - dy + params->grat[3]) << 12;
bit = jbig2_arith_decode(as, &GR_stats[CONTEXT]);
- if (bit < 0)
- return -1;
jbig2_image_set_pixel(image, x, y, bit);
}
}
@@ -127,8 +125,6 @@
CONTEXT |= jbig2_image_get_pixel(ref, x - dx - 1, y - dy + 0) << 8;
CONTEXT |= jbig2_image_get_pixel(ref, x - dx + 0, y - dy - 1) << 9;
bit = jbig2_arith_decode(as, &GR_stats[CONTEXT]);
- if (bit < 0)
- return -1;
jbig2_image_set_pixel(image, x, y, bit);
}
}
@@ -200,8 +196,6 @@
bool bit;
bit = jbig2_arith_decode(as, &GR_stats[CONTEXT]);
- if (bit < 0)
- return -1;
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x0d6) << 1) | bit |
((line_m1 >> (9 - x_minor)) & 0x002) |
@@ -296,15 +290,10 @@
ContextBuilder mkctx = (params->GRTEMPLATE ? mkctx1 : mkctx0);
for (y = 0; y < GRH; y++) {
- bit = jbig2_arith_decode(as, &GR_stats[start_context]);
- if (bit < 0)
- return -1;
- LTP = LTP ^ bit;
+ LTP ^= jbig2_arith_decode(as, &GR_stats[start_context]);
if (!LTP) {
for (x = 0; x < GRW; x++) {
bit = jbig2_arith_decode(as, &GR_stats[mkctx(params, image, x, y)]);
- if (bit < 0)
- return -1;
jbig2_image_set_pixel(image, x, y, bit);
}
} else {
@@ -312,8 +301,6 @@
iv = implicit_value(params, image, x, y);
if (iv < 0) {
bit = jbig2_arith_decode(as, &GR_stats[mkctx(params, image, x, y)]);
- if (bit < 0)
- return -1;
jbig2_image_set_pixel(image, x, y, bit);
} else
jbig2_image_set_pixel(image, x, y, iv);