ref: 9ec2217b0b1843a27db1bd4996951edeaba1ff93
parent: 06800cf352d454fdb472bb50c8434483132797b7
author: Sebastian Rasmussen <[email protected]>
date: Tue May 22 20:22:41 EDT 2018
jbig2dec: Error callback should not modify jbig2_error() return code. If a function detects an error it should call jbig2_error(ctx, JBIG2_SEVERITY_FATAL, ...) and return -1. The caller of this function may then detect the return code indicating error and call jbig2_error(ctx, JBIG2_SEVERITY_WARNING, ...). Previously this latter call to jbig2_error() would not return -1, but it is good form for the calling function to fail and return -1 to the next caller. Therefore the error callback no longer has the option to override the return code from jbig2_error(), instead jbig2_error() always returns -1.
--- a/jbig2.c
+++ b/jbig2.c
@@ -68,7 +68,7 @@
/* jbig2_free and jbig2_realloc moved to the bottom of this file */
-static int
+static void
jbig2_default_error(void *data, const char *msg, Jbig2Severity severity, int32_t seg_idx)
{
/* report only fatal errors by default */
@@ -79,8 +79,6 @@
fprintf(stderr, "\n");
fflush(stderr);
}
-
- return 0;
}
int
@@ -89,7 +87,6 @@
char buf[1024];
va_list ap;
int n;
- int code;
va_start(ap, fmt);
n = vsnprintf(buf, sizeof(buf), fmt, ap);
@@ -96,10 +93,8 @@
va_end(ap);
if (n < 0 || n == sizeof(buf))
strncpy(buf, "jbig2_error: error in generating error string", sizeof(buf));
- code = ctx->error_callback(ctx->error_callback_data, buf, severity, segment_number);
- if (severity == JBIG2_SEVERITY_FATAL)
- code = -1;
- return code;
+ ctx->error_callback(ctx->error_callback_data, buf, severity, segment_number);
+ return -1;
}
Jbig2Ctx *
@@ -199,8 +194,7 @@
* to (continue to) parse it as part of a jbig2 data stream.
*
* Return code: 0 on success
- * -1 if there is a parsing error, or whatever
- * the error handling callback returns
+ * -1 if there is a parsing error
**/
int
jbig2_data_in(Jbig2Ctx *ctx, const unsigned char *data, size_t size)
--- a/jbig2.h
+++ b/jbig2.h
@@ -62,7 +62,7 @@
handler is used which prints fatal errors to the stderr stream. */
/* error callback */
-typedef int (*Jbig2ErrorCallback)(void *data, const char *msg, Jbig2Severity severity, int32_t seg_idx);
+typedef void (*Jbig2ErrorCallback)(void *data, const char *msg, Jbig2Severity severity, int32_t seg_idx);
/* memory allocation is likewise done via a set of callbacks so that
clients can better control memory usage. If a NULL is passed for
--- a/jbig2dec.c
+++ b/jbig2dec.c
@@ -243,7 +243,7 @@
return 1;
}
-static int
+static void
error_callback(void *error_callback_data, const char *buf, Jbig2Severity severity, int32_t seg_idx)
{
const jbig2dec_params_t *params = (jbig2dec_params_t *) error_callback_data;
@@ -253,17 +253,17 @@
switch (severity) {
case JBIG2_SEVERITY_DEBUG:
if (params->verbose < 3)
- return 0;
+ return;
type = "DEBUG";
break;
case JBIG2_SEVERITY_INFO:
if (params->verbose < 2)
- return 0;
+ return;
type = "info";
break;
case JBIG2_SEVERITY_WARNING:
if (params->verbose < 1)
- return 0;
+ return;
type = "WARNING";
break;
case JBIG2_SEVERITY_FATAL:
@@ -279,8 +279,6 @@
snprintf(segment, sizeof(segment), "(segment 0x%02x)", seg_idx);
fprintf(stderr, "jbig2dec %s %s %s\n", type, buf, segment);
-
- return 0;
}
static char *