From 06417814d2fcea74e3f7128c77cef8cc43952a8a Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 19 Jun 2013 18:08:16 +0100 Subject: 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. --- fitz/base_context.c | 2 +- fitz/base_error.c | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'fitz') 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); -- cgit v1.2.3