shithub: jbig2

Download patch

ref: c2c5bd5716340b14d52c8f6b99631396028e51d5
parent: ce3a7fe3d687598968a4f032b67f5f8fe5337565
author: Sebastian Rasmussen <sebras@gmail.com>
date: Wed May 23 19:21:27 EDT 2018

jbig2dec: Directly return jbig2_error(FATAL); they indicate errors.

Because jbig2_error(ctx, JBIG2_SEVERITY_FATAL, ...) returns -1,
it can be immediately returned or assigned as a return code.

--- a/jbig2_huffman.c
+++ b/jbig2_huffman.c
@@ -228,9 +228,8 @@
     int32_t result;
 
     if (hs->offset_limit && hs->offset >= hs->offset_limit) {
-        jbig2_error(hs->ctx, JBIG2_SEVERITY_FATAL, -1, "end of jbig2 buffer reached at offset %d", hs->offset);
         *err = -1;
-        return -1;
+        return jbig2_error(hs->ctx, JBIG2_SEVERITY_FATAL, -1, "end of jbig2 buffer reached at offset %d", hs->offset);
     }
 
     result = this_word >> (32 - bits);
@@ -264,10 +263,9 @@
     int32_t result;
 
     if (hs->offset_limit && hs->offset >= hs->offset_limit) {
-        jbig2_error(hs->ctx, JBIG2_SEVERITY_FATAL, -1, "end of Jbig2WordStream reached at offset %d", hs->offset);
         if (oob)
             *oob = -1;
-        return -1;
+        return jbig2_error(hs->ctx, JBIG2_SEVERITY_FATAL, -1, "end of Jbig2WordStream reached at offset %d", hs->offset);
     }
 
     for (;;) {
--- a/jbig2_metadata.c
+++ b/jbig2_metadata.c
@@ -98,10 +98,8 @@
         keys = jbig2_renew(ctx, md->keys, char *, md->max_entries);
         values = jbig2_renew(ctx, md->values, char *, md->max_entries);
 
-        if (keys == NULL || values == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to resize metadata structure");
-            return -1;
-        }
+        if (keys == NULL || values == NULL)
+            return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to resize metadata structure");
         md->keys = keys;
         md->values = values;
     }
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -119,8 +119,7 @@
         runcodeparams.n_lines = 35;
         runcodes = jbig2_build_huffman_table(ctx, &runcodeparams);
         if (runcodes == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "error constructing symbol id runcode table");
-            code = -1;
+            code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "error constructing symbol id runcode table");
             goto cleanup1;
         }
 
@@ -127,8 +126,7 @@
         /* decode the symbol id code lengths using the runlength table */
         symcodelengths = jbig2_new(ctx, Jbig2HuffmanLine, SBNUMSYMS);
         if (symcodelengths == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "memory allocation failure reading symbol ID huffman table");
-            code = -1;
+            code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "memory allocation failure reading symbol ID huffman table");
             goto cleanup1;
         }
         index = 0;
@@ -146,8 +144,7 @@
             } else {
                 if (code == 32) {
                     if (index < 1) {
-                        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "error decoding symbol id table: run length with no antecedent");
-                        code = -1;
+                        code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "error decoding symbol id table: run length with no antecedent");
                         goto cleanup1;
                     }
                     len = symcodelengths[index - 1].PREFLEN;