Fix compiler warning and potential error in PNG error handling.
Compilation with gcc -Wall -Wextra displayed the following warning: Fl_PNG_Image.cxx: In member function ‘void Fl_PNG_Image::load_png_(const char*, const unsigned char*, int)’: Fl_PNG_Image.cxx:118:9: warning: variable ‘fp’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered] Making the variable static and initializing it properly avoids this potential error in the PNG lib's error handling. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12439 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
4a8e829f09
commit
b0a2223642
2
CHANGES
2
CHANGES
@ -92,6 +92,8 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2017
|
||||
Bug Fixes
|
||||
|
||||
- (add new items here)
|
||||
- Fix Fl_PNG_Image error handling. An error was potentially caused
|
||||
by error handling of the image library with setjmp/longjmp.
|
||||
- Fix Fl_Browser background and text color parsing (STR #3376).
|
||||
- Fix Windows CreateDC/DeleteDC mismatch (STR #3373).
|
||||
- Fix Fl_Tabs label drawing for Fl_Window children (STR #3075).
|
||||
|
@ -6,6 +6,8 @@
|
||||
// Copyright 1997-2012 by Easy Software Products.
|
||||
// Image support by Matthias Melcher, Copyright 2000-2009.
|
||||
//
|
||||
// Copyright 2013-2017 by Bill Spitzak and others.
|
||||
//
|
||||
// This library is free software. Distribution and use rights are outlined in
|
||||
// the file "COPYING" which should have been included with this file. If this
|
||||
// file is missing or damaged, see the license at:
|
||||
@ -31,9 +33,10 @@
|
||||
#include <FL/Fl_System_Driver.H>
|
||||
#include <FL/Fl_PNG_Image.H>
|
||||
#include <FL/Fl_Shared_Image.H>
|
||||
#include <FL/fl_utf8.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <FL/fl_utf8.h>
|
||||
|
||||
#if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ)
|
||||
extern "C"
|
||||
@ -90,14 +93,14 @@ Fl_PNG_Image::Fl_PNG_Image (const char *filename): Fl_RGB_Image(0,0,0)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
\brief Constructor that reads a PNG image from memory.
|
||||
|
||||
Construct an image from a block of memory inside the application. Fluid offers
|
||||
"binary Data" chunks as a great way to add image data into the C++ source code.
|
||||
name_png can be NULL. If a name is given, the image is added to the list of
|
||||
name_png can be NULL. If a name is given, the image is added to the list of
|
||||
shared images (see: Fl_Shared_Image) and will be available by that name.
|
||||
|
||||
|
||||
\param name_png A name given to this image or NULL
|
||||
\param buffer Pointer to the start of the PNG image in memory
|
||||
\param maxsize Size in bytes of the memory buffer containing the PNG image
|
||||
@ -112,15 +115,19 @@ Fl_PNG_Image::Fl_PNG_Image (
|
||||
void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_png, int maxsize)
|
||||
{
|
||||
#if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ)
|
||||
int i; // Looping var
|
||||
FILE *fp = NULL; // File pointer
|
||||
int channels; // Number of color channels
|
||||
png_structp pp; // PNG read pointer
|
||||
png_infop info = 0; // PNG info pointers
|
||||
png_bytep *rows;// PNG row pointers
|
||||
int i; // Looping var
|
||||
int channels; // Number of color channels
|
||||
png_structp pp; // PNG read pointer
|
||||
png_infop info = 0; // PNG info pointers
|
||||
png_bytep *rows; // PNG row pointers
|
||||
fl_png_memory png_mem_data;
|
||||
int from_memory = (buffer_png != NULL); // true if reading image from memory
|
||||
|
||||
// Note: The file pointer fp must not be an automatic (stack) variable
|
||||
// to avoid potential clobbering by setjmp/longjmp (gcc: [-Wclobbered]).
|
||||
static FILE *fp; // intentionally initialized separately below
|
||||
fp = NULL; // always initialize file pointer
|
||||
|
||||
if (!from_memory) {
|
||||
if ((fp = fl_fopen(name_png, "rb")) == NULL) {
|
||||
ld(ERR_FILE_ACCESS);
|
||||
@ -139,9 +146,8 @@ void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_p
|
||||
w(0); h(0); d(0); ld(ERR_FORMAT);
|
||||
return;
|
||||
}
|
||||
|
||||
if (setjmp(png_jmpbuf(pp)))
|
||||
{
|
||||
|
||||
if (setjmp(png_jmpbuf(pp))) {
|
||||
png_destroy_read_struct(&pp, &info, NULL);
|
||||
if (!from_memory) fclose(fp);
|
||||
Fl::warning("PNG file or data \"%s\" is too large or contains errors!\n", display_name);
|
||||
@ -157,7 +163,7 @@ void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_p
|
||||
png_set_read_fn (pp, (png_voidp) &png_mem_data, png_read_data_from_mem);
|
||||
} else {
|
||||
png_init_io(pp, fp); // Initialize the PNG file read "engine"...
|
||||
}
|
||||
}
|
||||
|
||||
// Get the image dimensions and convert to grayscale or RGB...
|
||||
png_read_info(pp, info);
|
||||
|
Loading…
Reference in New Issue
Block a user