summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-06-19 18:08:16 +0100
committerRobin Watts <robin.watts@artifex.com>2013-06-19 18:22:26 +0100
commit06417814d2fcea74e3f7128c77cef8cc43952a8a (patch)
tree22bf8b168644a56bb437b08299e8ffeac4d281e8 /fitz
parentce6dc95e477cbf58a2c5e4465d00f156a56fefe5 (diff)
downloadmupdf-06417814d2fcea74e3f7128c77cef8cc43952a8a.tar.xz
Exception handling fixes.
Various tweaks to ensure the exception handling works as expected when throwing error values. The key thing is not to reset the error value on a try, as this can cause problems when code calls trys in the always section.
Diffstat (limited to 'fitz')
-rw-r--r--fitz/base_context.c2
-rw-r--r--fitz/base_error.c11
2 files changed, 7 insertions, 6 deletions
diff --git a/fitz/base_context.c b/fitz/base_context.c
index 231d9104..c65377a8 100644
--- a/fitz/base_context.c
+++ b/fitz/base_context.c
@@ -93,7 +93,7 @@ new_context_phase1(fz_alloc_context *alloc, fz_locks_context *locks)
if (!ctx->error)
goto cleanup;
ctx->error->top = -1;
- ctx->error->errcode = 0;
+ ctx->error->errcode = FZ_ERROR_NONE;
ctx->error->message[0] = 0;
ctx->warn = fz_malloc_no_throw(ctx, sizeof(fz_warn_context));
diff --git a/fitz/base_error.c b/fitz/base_error.c
index f16dd4d0..50b3c5aa 100644
--- a/fitz/base_error.c
+++ b/fitz/base_error.c
@@ -89,7 +89,6 @@ int fz_push_try(fz_error_context *ex)
{
assert(ex);
ex->top++;
- ex->errcode = FZ_ERROR_NONE;
/* Normal case, get out of here quick */
if (ex->top < nelem(ex->stack)-1)
return 1; /* We exit here, and the setjmp sets the code to 0 */
@@ -107,15 +106,13 @@ int fz_push_try(fz_error_context *ex)
int fz_caught(fz_context *ctx)
{
- assert(ctx);
- assert(ctx->error);
+ assert(ctx && ctx->error && ctx->error->errcode >= FZ_ERROR_NONE);
return ctx->error->errcode;
}
const char *fz_caught_message(fz_context *ctx)
{
- assert(ctx);
- assert(ctx->error);
+ assert(ctx && ctx->error && ctx->error->errcode >= FZ_ERROR_NONE);
return ctx->error->message;
}
@@ -136,12 +133,16 @@ void fz_throw(fz_context *ctx, int code, const char *fmt, ...)
void fz_rethrow(fz_context *ctx)
{
+ assert(ctx && ctx->error && ctx->error->errcode >= FZ_ERROR_NONE);
throw(ctx->error);
}
void fz_rethrow_message(fz_context *ctx, const char *fmt, ...)
{
va_list args;
+
+ assert(ctx && ctx->error && ctx->error->errcode >= FZ_ERROR_NONE);
+
va_start(args, fmt);
vsnprintf(ctx->error->message, sizeof ctx->error->message, fmt, args);
va_end(args);