1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

[RofiIconFetcher] Don't exit out on libjpeg error, but don't load image.

This commit is contained in:
Dave Davenport 2020-10-17 21:59:12 +02:00
parent e00ef7d993
commit cc5a1989d8
2 changed files with 32 additions and 2 deletions

View file

@ -126,6 +126,7 @@ AC_SEARCH_LIBS([floor],[m],, AC_MSG_ERROR("Could not find floor in math lib
AC_SEARCH_LIBS([ceil], [m],, AC_MSG_ERROR("Could not find ceil in math library"))
AC_CHECK_HEADER([sysexits.h],, AC_MSG_ERROR("Could not find the sysexists.h header file"))
AC_CHECK_HEADER([setjmp.h],, AC_MSG_ERROR("Could not find the setjmp.h header file"))
dnl ---------------------------------------------------------------------
dnl Check dependencies

View file

@ -42,6 +42,8 @@
#include <stdint.h>
#include <jpeglib.h>
#include <setjmp.h>
typedef struct
{
// Context for icon-themes.
@ -171,11 +173,29 @@ static cairo_surface_t* cairo_image_surface_create_from_jpeg_private ( struct jp
return surface;
}
struct jpegErrorManager {
/* "public" fields */
struct jpeg_error_mgr pub;
/* for return to caller */
jmp_buf setjmp_buffer;
};
char jpegLastErrorMsg[JMSG_LENGTH_MAX];
static void jpegErrorExit (j_common_ptr cinfo)
{
/* cinfo->err actually points to a jpegErrorManager struct */
struct jpegErrorManager* myerr = (struct jpegErrorManager*) cinfo->err;
/* Create the message */
( *(cinfo->err->format_message) ) (cinfo, jpegLastErrorMsg);
g_warning ( jpegLastErrorMsg );
/* Jump to the setjmp point */
longjmp(myerr->setjmp_buffer, 1);
}
static cairo_surface_t* cairo_image_surface_create_from_jpeg ( const char* file )
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
cairo_surface_t * surface;
FILE * infile;
@ -183,7 +203,16 @@ static cairo_surface_t* cairo_image_surface_create_from_jpeg ( const char* file
return NULL;
}
cinfo.err = jpeg_std_error ( &jerr );
struct jpegErrorManager jerr;
cinfo.err = jpeg_std_error( &jerr.pub);
jerr.pub.error_exit = jpegErrorExit;
/* Establish the setjmp return context for my_error_exit to use. */
if (setjmp(jerr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error. */
jpeg_destroy_decompress(&cinfo);
fclose(infile);
return NULL;
}
jpeg_create_decompress ( &cinfo );
jpeg_stdio_src ( &cinfo, infile );