shithub: jbig2

Download patch

ref: bd3d8ebb98beec5fdb3e93534569dc0bc3d50e7a
parent: be7e85301ae58f21e9bbc60eb58ae58fc1217465
author: Sebastian Rasmussen <[email protected]>
date: Mon May 28 18:46:16 EDT 2018

jbig2dec: Rephrase jbig2_error() messages.

* Do not prefix messages with "jbig2 error:", this ought to be
  done by the error callback itself.
* Avoid using function names in messages as they mean nothing to
  the end user.
* Avoid contractions in messages.
* Try to adhere to "failed to" pattern as far as possible.
* Messages start with lower case character, unless it refers to
  something in the specification.
* Messages do not end with punctuation.

--- a/jbig2.c
+++ b/jbig2.c
@@ -94,7 +94,7 @@
     n = vsnprintf(buf, sizeof(buf), fmt, ap);
     va_end(ap);
     if (n < 0 || n == sizeof(buf))
-        strncpy(buf, "jbig2_error: error in generating error string", sizeof(buf));
+        strncpy(buf, "failed to generate error string", sizeof(buf));
     ctx->error_callback(ctx->error_callback_data, buf, severity, segment_number);
     return -1;
 }
@@ -111,7 +111,7 @@
 
     result = (Jbig2Ctx *) jbig2_alloc(allocator, sizeof(Jbig2Ctx), 1);
     if (result == NULL) {
-        error_callback(error_callback_data, "initial context allocation failed", JBIG2_SEVERITY_FATAL, -1);
+        error_callback(error_callback_data, "failed to allocate initial context", JBIG2_SEVERITY_FATAL, -1);
         return NULL;
     }
 
@@ -129,7 +129,7 @@
     result->n_segments_max = 16;
     result->segments = jbig2_new(result, Jbig2Segment *, result->n_segments_max);
     if (result->segments == NULL) {
-        error_callback(error_callback_data, "initial segments allocation failed", JBIG2_SEVERITY_FATAL, -1);
+        error_callback(error_callback_data, "failed to allocate initial segments", JBIG2_SEVERITY_FATAL, -1);
         jbig2_free(allocator, result);
         return NULL;
     }
@@ -139,7 +139,7 @@
     result->max_page_index = 4;
     result->pages = jbig2_new(result, Jbig2Page, result->max_page_index);
     if (result->pages == NULL) {
-        error_callback(error_callback_data, "initial pages allocation failed", JBIG2_SEVERITY_FATAL, -1);
+        error_callback(error_callback_data, "failed to allocated initial pages", JBIG2_SEVERITY_FATAL, -1);
         jbig2_free(allocator, result->segments);
         jbig2_free(allocator, result);
         return NULL;
@@ -211,7 +211,7 @@
         while (buf_size < size);
         ctx->buf = jbig2_new(ctx, byte, buf_size);
         if (ctx->buf == NULL) {
-            return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate ctx->buf in jbig2_data_in");
+            return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate buffer when reading data");
         }
         ctx->buf_size = buf_size;
         ctx->buf_rd_ix = 0;
@@ -228,7 +228,7 @@
             while (buf_size < ctx->buf_wr_ix - ctx->buf_rd_ix + size);
             buf = jbig2_new(ctx, byte, buf_size);
             if (buf == NULL) {
-                return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate buf in jbig2_data_in");
+                return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate bigger buffer when reading data");
             }
             memcpy(buf, ctx->buf + ctx->buf_rd_ix, ctx->buf_wr_ix - ctx->buf_rd_ix);
             jbig2_free(ctx->allocator, ctx->buf);
@@ -303,7 +303,7 @@
                 segments = jbig2_renew(ctx, ctx->segments, Jbig2Segment *, (ctx->n_segments_max <<= 2));
                 if (segments == NULL) {
                     ctx->state = JBIG2_FILE_EOF;
-                    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "could not reallocate space for more segments");
+                    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate space for more segments");
                 }
                 ctx->segments = segments;
             }
@@ -472,7 +472,7 @@
     Jbig2WordStreamBuf *result = jbig2_new(ctx, Jbig2WordStreamBuf, 1);
 
     if (result == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate Jbig2WordStreamBuf in jbig2_word_stream_buf_new");
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate word stream");
         return NULL;
     }
 
--- a/jbig2_arith.c
+++ b/jbig2_arith.c
@@ -161,7 +161,7 @@
 
     result = jbig2_new(ctx, Jbig2ArithState, 1);
     if (result == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate Jbig2ArithState in jbig2_arith_new");
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate arithmetic coding state");
         return NULL;
     }
 
--- a/jbig2_arith_iaid.c
+++ b/jbig2_arith_iaid.c
@@ -48,7 +48,7 @@
     int ctx_size = 1 << SBSYMCODELEN;
 
     if (result == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate storage in jbig2_arith_iaid_ctx_new");
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate IAID arithmetic coding state");
         return NULL;
     }
 
@@ -57,7 +57,7 @@
     if (result->IAIDx == NULL)
     {
         jbig2_free(ctx->allocator, result);
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate symbol ID storage in jbig2_arith_iaid_ctx_new");
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate symbol ID in IAID arithmetic coding state");
         return NULL;
     }
 
--- a/jbig2_arith_int.c
+++ b/jbig2_arith_int.c
@@ -49,7 +49,7 @@
     Jbig2ArithIntCtx *result = jbig2_new(ctx, Jbig2ArithIntCtx, 1);
 
     if (result == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate Jbig2ArithIntCtx in jbig2_arith_int_ctx_new");
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate arithmetic integer coding state");
         return NULL;
     } else {
         memset(result->IAx, 0, sizeof(result->IAx));
--- a/jbig2_generic.c
+++ b/jbig2_generic.c
@@ -811,7 +811,7 @@
             jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, "gbat[%d] = %d", i, params->gbat[i]);
     }
 
-    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "decode_generic_region: MMR=%d TPGDON=%d GBTEMPLATE=%d", params->MMR, params->TPGDON, params->GBTEMPLATE);
+    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "unsupported generic region (MMR=%d, GBTEMPLATE=%d)", params->MMR, params->GBTEMPLATE);
 }
 
 /**
@@ -901,7 +901,7 @@
 
     image = jbig2_image_new(ctx, rsi.width, height);
     if (image == NULL)
-        return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to allocate generic image");
+        return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate generic image");
     jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, "allocated %d x %d image buffer for region decode results", rsi.width, height);
 
     if (params.MMR) {
@@ -915,7 +915,7 @@
 
         GB_stats = jbig2_new(ctx, Jbig2ArithCx, stats_size);
         if (GB_stats == NULL) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "unable to allocate GB_stats in jbig2_immediate_generic_region");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate arithmetic decoder states when handling immediate generic region");
             goto cleanup;
         }
         memset(GB_stats, 0, stats_size);
@@ -922,17 +922,17 @@
 
         ws = jbig2_word_stream_buf_new(ctx, segment_data + offset, segment->data_length - offset);
         if (ws == NULL) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to allocate ws in jbig2_immediate_generic_region");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocated word stream when handling immediate generic region");
             goto cleanup;
         }
         as = jbig2_arith_new(ctx, ws);
         if (as == NULL) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to allocate as in jbig2_immediate_generic_region");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate arithmetic coding state when handling immediate generic region");
             goto cleanup;
         }
         code = jbig2_decode_generic_region(ctx, segment, &params, as, image, GB_stats);
         if (code < 0) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode generic region");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode immediate generic region");
             goto cleanup;
         }
     }
--- a/jbig2_halftone.c
+++ b/jbig2_halftone.c
@@ -137,7 +137,7 @@
     /* allocate the collective image */
     image = jbig2_image_new(ctx, params->HDPW * (params->GRAYMAX + 1), params->HDPH);
     if (image == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate collective bitmap for halftone dict");
+        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate collective bitmap for halftone dictionary");
         return NULL;
     }
 
@@ -166,13 +166,13 @@
             if (as != NULL) {
                 code = jbig2_decode_generic_region(ctx, segment, &rparams, as, image, GB_stats);
             } else {
-                code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate storage for as in halftone dict");
+                code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate arithmetic coding state when handling halftone dictionary");
             }
 
             jbig2_free(ctx->allocator, as);
             jbig2_word_stream_buf_free(ctx, ws);
         } else {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate storage for ws in halftone dict");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate word stream when handling halftone dictionary");
         }
     }
 
@@ -179,7 +179,7 @@
     if (code == 0)
         hd = jbig2_hd_new(ctx, params, image);
     else
-        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "error while decoding immediate_generic_region");
+        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode immediate generic region");
     jbig2_image_release(ctx, image);
 
     return hd;
@@ -223,7 +223,7 @@
 
         GB_stats = jbig2_new(ctx, Jbig2ArithCx, stats_size);
         if (GB_stats == NULL)
-            return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate GB_stats in pattern dictionary");
+            return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate arithmetic coding state when handling pattern dictionary");
         memset(GB_stats, 0, stats_size);
     }
 
@@ -313,13 +313,13 @@
     } else {
         ws = jbig2_word_stream_buf_new(ctx, data, size);
         if (ws == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate ws in jbig2_decode_gray_scale_image");
+            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate word stream when decoding gray scale image");
             goto cleanup;
         }
 
         as = jbig2_arith_new(ctx, ws);
         if (as == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate as in jbig2_decode_gray_scale_image");
+            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate arithmetic coding state when decoding gray scale image");
             goto cleanup;
         }
 
@@ -611,7 +611,7 @@
 
         GB_stats = jbig2_new(ctx, Jbig2ArithCx, stats_size);
         if (GB_stats == NULL) {
-            return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate GB_stats in halftone region");
+            return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate arithmetic decoder states in halftone region");
         }
         memset(GB_stats, 0, stats_size);
     }
@@ -619,7 +619,7 @@
     image = jbig2_image_new(ctx, region_info.width, region_info.height);
     if (image == NULL) {
         jbig2_free(ctx->allocator, GB_stats);
-        return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to allocate halftone image");
+        return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate halftone image");
     }
 
     code = jbig2_decode_halftone_region(ctx, segment, &params, segment_data + offset, segment->data_length - offset, image, GB_stats);
--- a/jbig2_huffman.c
+++ b/jbig2_huffman.c
@@ -391,7 +391,7 @@
     LENCOUNT = jbig2_new(ctx, int, lencountcount);
 
     if (LENCOUNT == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "couldn't allocate storage for huffman histogram");
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate huffman histogram");
         return NULL;
     }
     memset(LENCOUNT, 0, sizeof(int) * lencountcount);
@@ -419,7 +419,7 @@
 
     result = jbig2_new(ctx, Jbig2HuffmanTable, 1);
     if (result == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "couldn't allocate result storage in jbig2_build_huffman_table");
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate result");
         jbig2_free(ctx->allocator, LENCOUNT);
         return NULL;
     }
@@ -426,7 +426,7 @@
     result->log_table_size = log_table_size;
     entries = jbig2_new(ctx, Jbig2HuffmanEntry, max_j);
     if (entries == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "couldn't allocate entries storage in jbig2_build_huffman_table");
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate result entries");
         jbig2_free(ctx->allocator, result);
         jbig2_free(ctx->allocator, LENCOUNT);
         return NULL;
@@ -586,12 +586,12 @@
         /* allocate HuffmanParams & HuffmanLine */
         params = jbig2_new(ctx, Jbig2HuffmanParams, 1);
         if (params == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "could not allocate Huffman Table Parameter");
+            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate Huffman Table Parameter");
             goto error_exit;
         }
         line = jbig2_new(ctx, Jbig2HuffmanLine, lines_max);
         if (line == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "could not allocate Huffman Table Lines");
+            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate huffman table lines");
             goto error_exit;
         }
         /* B.2 5) */
@@ -638,7 +638,7 @@
                                                      Jbig2HuffmanLine, NTEMP);
 
             if (new_line == NULL) {
-                jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "could not reallocate Huffman Table Lines");
+                jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to reallocate huffman table lines");
                 goto error_exit;
             }
             line = new_line;
--- a/jbig2_image.c
+++ b/jbig2_image.c
@@ -42,15 +42,13 @@
     uint32_t stride;
 
     if (width == 0 || height == 0) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
-            "zero width (%d) or height (%d) in jbig2_image_new",
-            width, height);
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to create zero sized image");
         return NULL;
     }
 
     image = jbig2_new(ctx, Jbig2Image, 1);
     if (image == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "could not allocate image structure in jbig2_image_new");
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate image");
         return NULL;
     }
 
@@ -58,13 +56,13 @@
 
     /* check for integer multiplication overflow */
     if (height > (INT32_MAX / stride)) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "integer multiplication overflow stride=%u, height=%u", stride, height);
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "integer multiplication overflow (stride=%u, height=%u)", stride, height);
         jbig2_free(ctx->allocator, image);
         return NULL;
     }
     image->data = jbig2_new(ctx, uint8_t, (size_t) height * stride);
     if (image->data == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "could not allocate image data buffer! [stride(%u)*height(%u) bytes]", stride, height);
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate image data buffer (stride=%u, height=%u)", stride, height);
         jbig2_free(ctx->allocator, image);
         return NULL;
     }
@@ -114,13 +112,13 @@
     if (width == image->width) {
         /* check for integer multiplication overflow */
         if (image->height > (INT32_MAX / image->stride)) {
-            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "integer multiplication overflow during resize stride(%u)*height(%u)", image->stride, height);
+            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "integer multiplication overflow during resize (stride=%u, height=%u)", image->stride, height);
             return NULL;
         }
         /* use the same stride, just change the length */
         image->data = jbig2_renew(ctx, image->data, uint8_t, (size_t) height * image->stride);
         if (image->data == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "could not resize image buffer");
+            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to reallocate image");
             return NULL;
         }
         if (height > image->height) {
--- a/jbig2_image_pbm.c
+++ b/jbig2_image_pbm.c
@@ -136,7 +136,7 @@
             }
             buf[i] = '\0';
             if (sscanf(buf, "%d", &dim[done]) != 1) {
-                fprintf(stderr, "couldn't read pbm image dimensions\n");
+                fprintf(stderr, "failed to read pbm image dimensions\n");
                 return NULL;
             }
             i = 0;
@@ -146,7 +146,7 @@
     /* allocate image structure */
     image = jbig2_image_new(ctx, dim[0], dim[1]);
     if (image == NULL) {
-        fprintf(stderr, "could not allocate %dx%d image for pbm file\n", dim[0], dim[1]);
+        fprintf(stderr, "failed to allocate %dx%d image for pbm file\n", dim[0], dim[1]);
         return NULL;
     }
     /* the pbm data is byte-aligned, so we can
--- a/jbig2_page.c
+++ b/jbig2_page.c
@@ -81,7 +81,7 @@
                 /* grow the list */
                 pages = jbig2_renew(ctx, ctx->pages, Jbig2Page, (ctx->max_page_index <<= 2));
                 if (pages == NULL) {
-                    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to reallocate space for more pages");
+                    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to reallocate pages");
                 }
                 ctx->pages = pages;
                 for (j = index; j < ctx->max_page_index; j++) {
@@ -348,5 +348,5 @@
     }
 
     /* no matching pages */
-    jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "jbig2_release_page called on unknown page");
+    jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to release unknown page");
 }
--- a/jbig2_refinement.c
+++ b/jbig2_refinement.c
@@ -396,7 +396,7 @@
     for (index = 0; index < nsegments; index++) {
         rsegment = jbig2_find_segment(ctx, segment->referred_to_segments[index]);
         if (rsegment == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "could not find referred to segment %d", segment->referred_to_segments[index]);
+            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to find referred to segment %d", segment->referred_to_segments[index]);
             continue;
         }
         switch (rsegment->flags & 63) {
@@ -463,7 +463,7 @@
 
         ref = jbig2_region_find_referred(ctx, segment);
         if (ref == NULL)
-            return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "could not find reference bitmap");
+            return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to find reference bitmap");
         if (ref->result == NULL)
             return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "reference bitmap has no decoded image");
         /* the reference bitmap is the result of a previous
@@ -495,7 +495,7 @@
 
         image = jbig2_image_new(ctx, rsi.width, rsi.height);
         if (image == NULL) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to allocate refinement image");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate refinement image");
             goto cleanup;
         }
         jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, "allocated %d x %d image buffer for region decode results", rsi.width, rsi.height);
@@ -503,7 +503,7 @@
         stats_size = params.GRTEMPLATE ? 1 << 10 : 1 << 13;
         GR_stats = jbig2_new(ctx, Jbig2ArithCx, stats_size);
         if (GR_stats == NULL) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate GR-stats in jbig2_refinement_region");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate arithmetic decoder state for generic refinement regions");
             goto cleanup;
         }
         memset(GR_stats, 0, stats_size);
@@ -510,13 +510,13 @@
 
         ws = jbig2_word_stream_buf_new(ctx, segment_data + offset, segment->data_length - offset);
         if (ws == NULL) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate ws in jbig2_refinement_region");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate word stream when handling refinement region");
             goto cleanup;
         }
 
         as = jbig2_arith_new(ctx, ws);
         if (as == NULL) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate as in jbig2_refinement_region");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate arithmetic coding state when handling refinement region");
             goto cleanup;
         }
 
--- a/jbig2_segment.c
+++ b/jbig2_segment.c
@@ -61,7 +61,7 @@
 
     result = jbig2_new(ctx, Jbig2Segment, 1);
     if (result == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate segment in jbig2_parse_segment_header");
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate segment");
         return NULL;
     }
 
@@ -87,7 +87,7 @@
     referred_to_segment_size = result->number <= 256 ? 1 : result->number <= 65536 ? 2 : 4;     /* 7.2.5 */
     pa_size = result->flags & 0x40 ? 4 : 1;     /* 7.2.6 */
     if (offset + referred_to_segment_count * referred_to_segment_size + pa_size + 4 > buf_size) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, result->number, "jbig2_parse_segment_header() called with insufficient data", -1);
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, result->number, "insufficient data to parse segment header", -1);
         jbig2_free(ctx->allocator, result);
         return NULL;
     }
@@ -98,7 +98,7 @@
 
         referred_to_segments = jbig2_new(ctx, uint32_t, referred_to_segment_count * referred_to_segment_size);
         if (referred_to_segments == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, result->number, "could not allocate referred_to_segments in jbig2_parse_segment_header");
+            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, result->number, "failed to allocate referred to segments");
             return NULL;
         }
 
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -76,7 +76,7 @@
 
     if (dict == NULL)
         return;
-    jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "dumping symbol dict as %d individual png files", dict->n_symbols);
+    jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "dumping symbol dictionary as %d individual png files", dict->n_symbols);
     for (index = 0; index < dict->n_symbols; index++) {
         snprintf(filename, sizeof(filename), "symbol_%02d-%04d.png", segment->number, index);
         jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, "dumping symbol %d/%d as '%s'", index, dict->n_symbols, filename);
@@ -102,7 +102,7 @@
         new_dict->glyphs = jbig2_new(ctx, Jbig2Image *, n_symbols);
         new_dict->n_symbols = n_symbols;
     } else {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to allocate new empty symbol dict");
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate new empty symbol dictionary");
         return NULL;
     }
 
@@ -109,7 +109,7 @@
     if (new_dict->glyphs != NULL) {
         memset(new_dict->glyphs, 0, n_symbols * sizeof(Jbig2Image *));
     } else if (new_dict->n_symbols > 0) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to allocate glyphs for new empty symbol dict");
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate glyphs for new empty symbol dictionary");
         jbig2_free(ctx->allocator, new_dict);
         return NULL;
     }
@@ -260,13 +260,13 @@
 
     ws = jbig2_word_stream_buf_new(ctx, data, size);
     if (ws == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate ws in jbig2_decode_symbol_dict");
+        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate word stream when decoding symbol dictionary");
         return NULL;
     }
 
     as = jbig2_arith_new(ctx, ws);
     if (as == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate as in jbig2_decode_symbol_dict");
+        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate arithmetic coding state when decoding symbol dictionary");
         jbig2_word_stream_buf_free(ctx, ws);
         return NULL;
     }
@@ -279,13 +279,13 @@
         tparams.SBHUFFRSIZE = jbig2_build_huffman_table(ctx, &jbig2_huffman_params_A); /* Table B.1 */
         if (hs == NULL || tparams.SBHUFFRDX == NULL ||
                 tparams.SBHUFFRDY == NULL || tparams.SBHUFFRSIZE == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate storage for symbol bitmap");
+            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate for symbol bitmap");
             goto cleanup;
         }
         if (!params->SDREFAGG) {
             SDNEWSYMWIDTHS = jbig2_new(ctx, uint32_t, params->SDNUMNEWSYMS);
             if (SDNEWSYMWIDTHS == NULL) {
-                jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "could not allocate storage for (%u) symbol widths", params->SDNUMNEWSYMS);
+                jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate symbol widths (%u)", params->SDNUMNEWSYMS);
                 goto cleanup;
             }
         } else {
@@ -307,7 +307,7 @@
         IAEX = jbig2_arith_int_ctx_new(ctx);
         IAAI = jbig2_arith_int_ctx_new(ctx);
         if (IADH == NULL || IADW == NULL || IAEX == NULL || IAAI == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate storage for symbol bitmap");
+            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++);
@@ -316,7 +316,7 @@
         tparams.IARDY = jbig2_arith_int_ctx_new(ctx);
         if (tparams.IAID == NULL || tparams.IARDX == NULL ||
                 tparams.IARDY == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "out of memory creating text region arith decoder entries");
+            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate text region arithmetic decoder contexts");
             goto cleanup;
         }
         if (params->SDREFAGG) {
@@ -333,8 +333,7 @@
                     tparams.IADS == NULL || tparams.IAIT == NULL ||
                     tparams.IARI == NULL || tparams.IARDW == NULL ||
                     tparams.IARDH == NULL) {
-                jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "out of memory creating text region arith decoder entries");
-                goto cleanup;
+                jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate text region arith decoder contexts");
             }
         }
     }
@@ -350,7 +349,7 @@
 
     SDNEWSYMS = jbig2_sd_new(ctx, params->SDNUMNEWSYMS);
     if (SDNEWSYMS == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "could not allocate storage for (%u) new symbols", params->SDNUMNEWSYMS);
+        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate new symbols (%u)", params->SDNUMNEWSYMS);
         goto cleanup;
     }
 
@@ -456,7 +455,7 @@
 
                     image = jbig2_image_new(ctx, SYMWIDTH, HCHEIGHT);
                     if (image == NULL) {
-                        code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate image in jbig2_decode_symbol_dict");
+                        code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate image");
                         goto cleanup;
                     }
 
@@ -497,7 +496,7 @@
 
                         image = jbig2_image_new(ctx, SYMWIDTH, HCHEIGHT);
                         if (image == NULL) {
-                            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "out of memory creating symbol image");
+                            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate symbol image");
                             goto cleanup;
                         }
 
@@ -553,11 +552,11 @@
                         }
 
                         jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
-                                    "symbol is a refinement of id %d with the refinement applied at (%d,%d)", ID, RDX, RDY);
+                                    "symbol is a refinement of ID %d with the refinement applied at (%d,%d)", ID, RDX, RDY);
 
                         image = jbig2_image_new(ctx, SYMWIDTH, HCHEIGHT);
                         if (image == NULL) {
-                            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "out of memory creating symbol image");
+                            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate symbol image");
                             goto cleanup;
                         }
 
@@ -653,7 +652,7 @@
 
             image = jbig2_image_new(ctx, TOTWIDTH, HCHEIGHT);
             if (image == NULL) {
-                jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "could not allocate collective bitmap image");
+                jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate collective bitmap image");
                 goto cleanup;
             }
 
@@ -1032,7 +1031,7 @@
 
         GB_stats = jbig2_new(ctx, Jbig2ArithCx, stats_size);
         if (GB_stats == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate GB_stats in jbig2_symbol_dictionary");
+            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate arithmetic decoder states for generic regions");
             goto cleanup;
         }
         memset(GB_stats, 0, stats_size);
@@ -1040,7 +1039,7 @@
         stats_size = params.SDRTEMPLATE ? 1 << 10 : 1 << 13;
         GR_stats = jbig2_new(ctx, Jbig2ArithCx, stats_size);
         if (GR_stats == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate GR_stats in jbig2_symbol_dictionary");
+            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate arithmetic decoder states for generic refinement regions");
             jbig2_free(ctx->allocator, GB_stats);
             goto cleanup;
         }
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -101,7 +101,7 @@
         jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, "huffman coded text region");
         hs = jbig2_huffman_new(ctx, ws);
         if (hs == NULL)
-            return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate storage for text region");
+            return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate text region");
 
         /* 7.4.3.1.7 - decode symbol ID Huffman table */
         /* this is actually part of the segment header, but it is more
@@ -127,14 +127,14 @@
         runcodeparams.n_lines = 35;
         runcodes = jbig2_build_huffman_table(ctx, &runcodeparams);
         if (runcodes == NULL) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "error constructing symbol id runcode table");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "error constructing symbol ID runcode table");
             goto cleanup1;
         }
 
-        /* decode the symbol id code lengths using the runlength table */
+        /* decode the symbol ID code lengths using the runlength table */
         symcodelengths = jbig2_new(ctx, Jbig2HuffmanLine, SBNUMSYMS);
         if (symcodelengths == NULL) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "memory allocation failure reading symbol ID huffman table");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate memory when reading symbol ID huffman table");
             goto cleanup1;
         }
         index = 0;
@@ -159,7 +159,7 @@
             } else {
                 if (code == 32) {
                     if (index < 1) {
-                        code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "error decoding symbol id table: run length with no antecedent");
+                        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;
@@ -185,7 +185,7 @@
             jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, "  read runcode%d at index %d (length %d range %d)", code, index, len, range);
             if (index + range > SBNUMSYMS) {
                 jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
-                            "runlength extends %d entries beyond the end of symbol id table", index + range - SBNUMSYMS);
+                            "runlength extends %d entries beyond the end of symbol ID table", index + range - SBNUMSYMS);
                 range = SBNUMSYMS - index;
             }
             for (r = 0; r < range; r++) {
@@ -211,7 +211,7 @@
             goto cleanup1;
         }
 
-        /* finally, construct the symbol id huffman table itself */
+        /* finally, construct the symbol ID huffman table itself */
         SBSYMCODES = jbig2_build_huffman_table(ctx, &symcodeparams);
 
 cleanup1:
@@ -219,7 +219,7 @@
         jbig2_release_huffman_table(ctx, runcodes);
 
         if (SBSYMCODES == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "could not construct Symbol ID huffman table");
+            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to construct symbol ID huffman table");
             jbig2_huffman_free(ctx, hs);
             return ((code != 0) ? code : -1);
         }
@@ -329,7 +329,7 @@
             }
             T = STRIPT + CURT;
 
-            /* (3b.iv) / 6.4.10 - decode the symbol id */
+            /* (3b.iv) / 6.4.10 - decode the symbol ID */
             if (params->SBHUFF) {
                 ID = jbig2_huffman_get(hs, SBSYMCODES, &code);
             } else {
@@ -344,7 +344,7 @@
                 goto cleanup2;
             }
             if (ID >= SBNUMSYMS) {
-                jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "symbol id out of range, ignoring (%d/%d)", ID, SBNUMSYMS);
+                jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "ignoring out of range symbol ID (%d/%d)", ID, SBNUMSYMS);
                 IB = NULL;
             } else {
                 /* (3c.v) / 6.4.11 - look up the symbol bitmap IB */
@@ -422,7 +422,7 @@
                 }
                 refimage = jbig2_image_new(ctx, IBO->width + RDW, IBO->height + RDH);
                 if (refimage == NULL) {
-                    code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "couldn't allocate reference image");
+                    code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate reference image");
                     goto cleanup2;
                 }
                 jbig2_image_clear(ctx, refimage, 0x00);
@@ -533,7 +533,7 @@
             /* (3c.ix) */
 #ifdef JBIG2_DEBUG
             jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
-                        "composing glyph id %d: %dx%d @ (%d,%d) symbol %d/%d", ID, IB->width, IB->height, x, y, NINSTANCES + 1, params->SBNUMINSTANCES);
+                        "composing glyph ID %d: %dx%d @ (%d,%d) symbol %d/%d", ID, IB->width, IB->height, x, y, NINSTANCES + 1, params->SBNUMINSTANCES);
 #endif
             code = jbig2_image_compose(ctx, image, IB, x, y, params->SBCOMBOP);
             if (code < 0) {
@@ -908,7 +908,7 @@
 
         GR_stats = jbig2_new(ctx, Jbig2ArithCx, stats_size);
         if (GR_stats == NULL) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "could not allocate GR_stats");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "could not allocate arithmetic decoder state");
             goto cleanup1;
         }
         memset(GR_stats, 0, stats_size);
@@ -916,7 +916,7 @@
 
     image = jbig2_image_new(ctx, region_info.width, region_info.height);
     if (image == NULL) {
-        code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "couldn't allocate text region image");
+        code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate text region image");
         goto cleanup2;
     }
 
@@ -924,13 +924,13 @@
         goto too_short;
     ws = jbig2_word_stream_buf_new(ctx, segment_data + offset, segment->data_length - offset);
     if (ws == NULL) {
-        code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "couldn't allocate ws in text region image");
+        code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate word stream when handling text region image");
         goto cleanup2;
     }
 
     as = jbig2_arith_new(ctx, ws);
     if (as == NULL) {
-        code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "couldn't allocate as in text region image");
+        code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate arithmetic coding context when handling text region image");
         goto cleanup2;
     }
 
@@ -947,7 +947,7 @@
         params.IADS = jbig2_arith_int_ctx_new(ctx);
         params.IAIT = jbig2_arith_int_ctx_new(ctx);
         if (params.IADT == NULL || params.IAFS == NULL || params.IADS == NULL || params.IAIT == NULL) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "couldn't allocate text region image data");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate text region image data");
             goto cleanup3;
         }
 
@@ -962,7 +962,7 @@
         params.IARDY = jbig2_arith_int_ctx_new(ctx);
         if (params.IAID == NULL || params.IARI == NULL ||
             params.IARDW == NULL || params.IARDH == NULL || params.IARDX == NULL || params.IARDY == NULL) {
-            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "couldn't allocate text region image data");
+            code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate text region image data");
             goto cleanup4;
         }
     }
@@ -1027,5 +1027,5 @@
     return code;
 
 too_short:
-    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "Segment too short");
+    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "segment too short");
 }
--- a/jbig2dec.c
+++ b/jbig2dec.c
@@ -291,7 +291,7 @@
     int len;
 
     if (extension == NULL) {
-        fprintf(stderr, "make_output_filename called with no extension!\n");
+        fprintf(stderr, "no filename extension; cannot create output filename!\n");
         exit(1);
     }
 
@@ -321,7 +321,7 @@
     /* allocate enough space for the base + ext */
     output_filename = (char *)malloc(len + strlen(extension) + 1);
     if (output_filename == NULL) {
-        fprintf(stderr, "couldn't allocate memory for output_filename\n");
+        fprintf(stderr, "failed to allocate memory for output filename\n");
         exit(1);
     }