cairo-util: Return NULL instead of exit() on jpeg load failure
authorKristian Høgsberg <krh@bitplanet.net>
Wed, 25 Jan 2012 19:54:26 +0000 (14:54 -0500)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 25 Jan 2012 19:54:26 +0000 (14:54 -0500)
clients/cairo-util.c

index 54a05b1..61de82f 100644 (file)
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <math.h>
+#include <setjmp.h>
 #include <cairo.h>
 #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");