From ffe3bba13ee143e479f67b10e96e7d9bc3f55407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 25 Jan 2012 14:54:26 -0500 Subject: [PATCH] cairo-util: Return NULL instead of exit() on jpeg load failure --- clients/cairo-util.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/clients/cairo-util.c b/clients/cairo-util.c index 54a05b1a5..61de82fc5 100644 --- a/clients/cairo-util.c +++ b/clients/cairo-util.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "cairo-util.h" @@ -304,6 +305,12 @@ swizzle_row(JSAMPLE *row, JDIMENSION width) } } +static void +error_exit(j_common_ptr cinfo) +{ + longjmp(cinfo->client_data, 1); +} + cairo_surface_t * load_jpeg(const char *filename) { @@ -312,8 +319,14 @@ load_jpeg(const char *filename) FILE *fp; int stride, i, first; JSAMPLE *data, *rows[4]; + jmp_buf env; cinfo.err = jpeg_std_error(&jerr); + jerr.error_exit = error_exit; + cinfo.client_data = env; + if (setjmp(env)) + return NULL; + jpeg_create_decompress(&cinfo); fp = fopen(filename, "rb");