From ef25e5a4c8102c9d981e3f720c27462c72102b54 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 2 Apr 2006 01:27:36 +0000 Subject: [PATCH] don't crash when loading images with verbose==false (patch 1449823) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38513 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/imagjpeg.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/common/imagjpeg.cpp b/src/common/imagjpeg.cpp index 7e4dcedfba..6a475f70bf 100644 --- a/src/common/imagjpeg.cpp +++ b/src/common/imagjpeg.cpp @@ -163,12 +163,22 @@ CPP_METHODDEF(void) wx_error_exit (j_common_ptr cinfo) /* Always display the message. */ /* We could postpone this until after returning, if we chose. */ - if (cinfo->err->output_message) (*cinfo->err->output_message) (cinfo); + (*cinfo->err->output_message) (cinfo); /* Return control to the setjmp point */ longjmp(myerr->setjmp_buffer, 1); } +/* + * This will replace the standard output_message method when the user + * wants us to be silent (verbose==false). We must have such method instead of + * simply using NULL for cinfo->err->output_message because it's called + * unconditionally from within libjpeg when there's "garbage input". + */ +CPP_METHODDEF(void) wx_ignore_message (j_common_ptr WXUNUSED(cinfo)) +{ +} + void wx_jpeg_io_src( j_decompress_ptr cinfo, wxInputStream& infile ) { wx_src_ptr src; @@ -210,7 +220,8 @@ bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos cinfo.err = jpeg_std_error( &jerr.pub ); jerr.pub.error_exit = wx_error_exit; - if (!verbose) cinfo.err->output_message=NULL; + if (!verbose) + cinfo.err->output_message = wx_ignore_message; /* Establish the setjmp return context for wx_error_exit to use. */ if (setjmp(jerr.setjmp_buffer)) { @@ -323,7 +334,8 @@ bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = wx_error_exit; - if (!verbose) cinfo.err->output_message=NULL; + if (!verbose) + cinfo.err->output_message = wx_ignore_message; /* Establish the setjmp return context for wx_error_exit to use. */ if (setjmp(jerr.setjmp_buffer)) -- 2.47.2