diff options
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/base_error.c | 18 | ||||
-rw-r--r-- | fitz/filt_dctd.c | 3 | ||||
-rw-r--r-- | fitz/fitz.h | 6 | ||||
-rw-r--r-- | fitz/image_jpx.c | 9 | ||||
-rw-r--r-- | fitz/res_font.c | 2 | ||||
-rw-r--r-- | fitz/res_path.c | 3 | ||||
-rw-r--r-- | fitz/stm_open.c | 2 |
7 files changed, 27 insertions, 16 deletions
diff --git a/fitz/base_error.c b/fitz/base_error.c index 71a32a2e..ce048a1e 100644 --- a/fitz/base_error.c +++ b/fitz/base_error.c @@ -54,15 +54,21 @@ static void throw(fz_error_context *ex) } } -void fz_push_try(fz_error_context *ex) +int fz_push_try(fz_error_context *ex) { assert(ex); - if (ex->top + 1 >= nelem(ex->stack)) - { - fprintf(stderr, "exception stack overflow!\n"); - exit(EXIT_FAILURE); - } ex->top++; + /* Normal case, get out of here quick */ + if (ex->top < nelem(ex->stack)-1) + return 1; + /* We reserve the top slot on the exception stack purely to cope with + * the case when we overflow. If we DO hit this, then we 'throw' + * immediately - returning 0 stops the setjmp happening and takes us + * direct to the always/catch clauses. */ + assert(ex->top == nelem(ex->stack)-1); + strcpy(ex->message, "exception stack overflow!\n"); + ex->stack[ex->top].code = 1; + return 0; } char *fz_caught(fz_context *ctx) diff --git a/fitz/filt_dctd.c b/fitz/filt_dctd.c index 1b588d2a..76f82abe 100644 --- a/fitz/filt_dctd.c +++ b/fitz/filt_dctd.c @@ -107,6 +107,7 @@ read_dctd(fz_stream *stm, unsigned char *buf, int len) jpeg_std_error(cinfo->err); cinfo->err->error_exit = error_exit; jpeg_create_decompress(cinfo); + state->init = 1; /* Skip over any stray returns at the start of the stream */ while ((c = fz_peek_byte(state->chain)) == '\n' || c == '\r') @@ -165,8 +166,6 @@ read_dctd(fz_stream *stm, unsigned char *buf, int len) state->scanline = fz_malloc(state->ctx, state->stride); state->rp = state->scanline; state->wp = state->scanline; - - state->init = 1; } while (state->rp < state->wp && p < ep) diff --git a/fitz/fitz.h b/fitz/fitz.h index a04ef584..8bbc2ec4 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -237,8 +237,8 @@ void fz_var_imp(void *); */ #define fz_try(ctx) \ - if (fz_push_try(ctx->error), \ - (ctx->error->stack[ctx->error->top].code = fz_setjmp(ctx->error->stack[ctx->error->top].buffer)) == 0) \ + if (fz_push_try(ctx->error) && \ + ((ctx->error->stack[ctx->error->top].code = fz_setjmp(ctx->error->stack[ctx->error->top].buffer)) == 0))\ { do { #define fz_always(ctx) \ @@ -251,7 +251,7 @@ void fz_var_imp(void *); } \ if (ctx->error->stack[ctx->error->top--].code) -void fz_push_try(fz_error_context *ex); +int fz_push_try(fz_error_context *ex); void fz_throw(fz_context *, char *, ...) __printflike(2, 3); void fz_rethrow(fz_context *); void fz_warn(fz_context *ctx, char *fmt, ...) __printflike(2, 3); diff --git a/fitz/image_jpx.c b/fitz/image_jpx.c index af5ef263..04bcfecd 100644 --- a/fitz/image_jpx.c +++ b/fitz/image_jpx.c @@ -70,11 +70,20 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs for (k = 1; k < jpx->numcomps; k++) { if (jpx->comps[k].w != jpx->comps[0].w) + { + opj_image_destroy(jpx); fz_throw(ctx, "image components have different width"); + } if (jpx->comps[k].h != jpx->comps[0].h) + { + opj_image_destroy(jpx); fz_throw(ctx, "image components have different height"); + } if (jpx->comps[k].prec != jpx->comps[0].prec) + { + opj_image_destroy(jpx); fz_throw(ctx, "image components have different precision"); + } } n = jpx->numcomps; diff --git a/fitz/res_font.c b/fitz/res_font.c index a68a1ff1..50420d97 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -911,7 +911,6 @@ fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_co ctm = fz_concat(font->t3matrix, trm); dev = fz_new_draw_device_type3(ctx, glyph); font->t3run(font->t3doc, font->t3resources, contents, dev, ctm, NULL); - /* RJW: "cannot draw type3 glyph" */ fz_free_device(dev); if (!model) @@ -953,7 +952,6 @@ fz_render_t3_glyph_direct(fz_context *ctx, fz_device *dev, fz_font *font, int gi ctm = fz_concat(font->t3matrix, trm); font->t3run(font->t3doc, font->t3resources, contents, dev, ctm, gstate); - /* RJW: "cannot draw type3 glyph" */ } #ifndef NDEBUG diff --git a/fitz/res_path.c b/fitz/res_path.c index d02ea560..a030cc29 100644 --- a/fitz/res_path.c +++ b/fitz/res_path.c @@ -415,11 +415,10 @@ fz_print_path(fz_context *ctx, FILE *out, fz_path *path, int indent) fz_stroke_state * fz_keep_stroke_state(fz_context *ctx, fz_stroke_state *stroke) { - fz_lock(ctx, FZ_LOCK_ALLOC); - if (!stroke) return NULL; + fz_lock(ctx, FZ_LOCK_ALLOC); if (stroke->refs > 0) stroke->refs++; fz_unlock(ctx, FZ_LOCK_ALLOC); diff --git a/fitz/stm_open.c b/fitz/stm_open.c index 1709340b..3d605e1a 100644 --- a/fitz/stm_open.c +++ b/fitz/stm_open.c @@ -140,7 +140,7 @@ fz_open_file_w(fz_context *ctx, const wchar_t *name) { int fd = _wopen(name, O_BINARY | O_RDONLY, 0); if (fd == -1) - return NULL; + fz_throw(ctx, "cannot open file %Ls", name); return fz_open_fd(ctx, fd); } #endif |