/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* pngerror.c - stub functions for i/o and memory allocation
*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed:
*
* Last changed in libpng 1.5.4 [July 7, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*
* This file provides a location for all error handling. Users who
* need special error handling are expected to write replacement functions
* and use png_set_error_fn() to use those functions. See the instructions
* at each function.
*/
#include "pngpriv.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#ifdef PNG_WARNINGS_SUPPORTED
static void /* PRIVATE */
#endif /* PNG_WARNINGS_SUPPORTED */
/* This function is called whenever there is a fatal error. This function
* should not be changed. If there is a need to handle errors differently,
* you should supply a replacement error function and use png_set_error_fn()
* to replace the error function at run-time.
*/
#ifdef PNG_ERROR_TEXT_SUPPORTED
{
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
{
{
if (*error_message == PNG_LITERAL_SHARP)
{
/* Strip "#nnnn " from beginning of error message. */
int offset;
break;
{
int i;
for (i = 0; i < offset - 1; i++)
error_message = msg;
}
else
error_message += offset;
}
else
{
{
msg[0] = '0';
error_message = msg;
}
}
}
}
#endif
/* If the custom handler doesn't exist, or if it returns,
use the default handler, which will not return. */
}
#else
{
/* Prior to 1.5.2 the error_fn received a NULL pointer, expressed
* erroneously as '\0', instead of the empty string "". This was
* apparently an error, introduced in libpng-1.2.20, and png_default_error
* will crash in this case.
*/
/* If the custom handler doesn't exist, or if it returns,
use the default handler, which will not return. */
}
#endif /* PNG_ERROR_TEXT_SUPPORTED */
/* Utility to safely appends strings to a buffer. This never errors out so
* error checking is not required in the caller.
*/
{
{
}
return pos;
}
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)
/* Utility to dump an unsigned value into a buffer, given a start pointer and
* and end pointer (which should point just *beyond* the end of the buffer!)
* Returns the pointer to the start of the formatted string.
*/
{
*--end = '\0';
/* This is written so that the loop always runs at least once, even with
* number zero.
*/
{
switch (format)
{
case PNG_NUMBER_FORMAT_fixed:
/* Needs five digits (the fraction) */
mincount = 5;
{
output = 1;
}
number /= 10;
break;
case PNG_NUMBER_FORMAT_02u:
/* Expects at least 2 digits. */
mincount = 2;
/* fall through */
case PNG_NUMBER_FORMAT_u:
number /= 10;
break;
case PNG_NUMBER_FORMAT_02x:
/* This format expects at least two digits */
mincount = 2;
/* fall through */
case PNG_NUMBER_FORMAT_x:
number >>= 4;
break;
default: /* an error */
number = 0;
break;
}
/* Keep track of the number of digits added */
++count;
/* Float a fixed number here: */
{
/* End of the fraction, but maybe nothing was output? In that case
* drop the decimal point. If the number is a true zero handle that
* here.
*/
if (output)
*--end = '.';
else if (number == 0) /* and !output */
*--end = '0';
}
}
return end;
}
#endif
#ifdef PNG_WARNINGS_SUPPORTED
/* This function is called whenever there is a non-fatal error. This function
* should not be changed. If there is a need to handle warnings differently,
* you should supply a replacement warning function and use
* png_set_error_fn() to replace the warning function at run-time.
*/
void PNGAPI
{
int offset = 0;
{
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
#endif
{
if (*warning_message == PNG_LITERAL_SHARP)
{
break;
}
}
}
else
}
/* These functions support 'formatted' warning messages with up to
* PNG_WARNING_PARAMETER_COUNT parameters. In the format string the parameter
* is introduced by @<number>, where 'number' starts at 1. This follows the
*/
void
{
}
void
{
}
void
{
/* Avoid overflow by doing the negate in a png_alloc_size_t: */
u = (png_alloc_size_t)value;
if (value < 0)
u = ~u + 1;
*--str = '-';
}
void
{
/* The internal buffer is just 128 bytes - enough for all our messages,
* overflow doesn't happen because this code checks!
*/
size_t i;
{
if (*message == '@')
{
switch (*++message)
{
case '1':
parameter = 0;
break;
case '2':
parameter = 1;
break;
case '\0':
continue; /* To break out of the for loop above. */
default:
break;
}
{
/* Append this parameter */
/* No need to copy the trailing '\0' here, but there is no guarantee
* that parm[] has been initialized, so there is no guarantee of a
* trailing '\0':
*/
++message;
continue;
}
/* else not a parameter and there is a character after the @ sign; just
* copy that.
*/
}
/* At this point *message can't be '\0', even in the bad parameter case
* above where there is a lone '@' at the end of the message string.
*/
}
/* i is always less than (sizeof msg), so: */
msg[i] = '\0';
/* And this is the formatted message: */
}
#endif /* PNG_WARNINGS_SUPPORTED */
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
void PNGAPI
{
else
}
#endif
/* These utilities are used internally to build an error message that relates
* to the current chunk. The chunk name comes from png_ptr->chunk_name,
* this is used to prefix the message. The message is limited in length
* to 63 bytes, the name characters are output as hex digits wrapped in []
* if the character is invalid.
*/
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'
};
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
static void /* PRIVATE */
{
while (iin < 4)
{
if (isnonalpha(c))
{
}
else
{
}
}
if (error_message == NULL)
else
{
iin = 0;
/* iin < PNG_MAX_ERROR_TEXT, so the following is safe: */
}
}
#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */
#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
{
else
{
}
}
#endif /* PNG_READ_SUPPORTED && PNG_ERROR_TEXT_SUPPORTED */
#ifdef PNG_WARNINGS_SUPPORTED
void PNGAPI
{
else
{
}
}
#endif /* PNG_WARNINGS_SUPPORTED */
#ifdef PNG_READ_SUPPORTED
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
void PNGAPI
{
else
}
#endif
#endif /* PNG_READ_SUPPORTED */
#ifdef PNG_ERROR_TEXT_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED
PNG_FUNCTION(void,
{
int iin;
iin = 0;
{
++iin;
}
}
#endif
#endif
#ifdef PNG_SETJMP_SUPPORTED
/* This API only exists if ANSI-C style error handling is used,
* otherwise it is necessary for png_default_error to be overridden.
*/
{
return NULL;
return &png_ptr->longjmp_buffer;
}
#endif
/* This is the default error handling function. Note that replacements for
* this function MUST NOT RETURN, or the program will likely crash. This
* function is used by default, or if the program supplies NULL for the
* error function pointer in png_set_error_fn().
*/
{
#ifdef PNG_CONSOLE_IO_SUPPORTED
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
/* Check on NULL only added in 1.5.4 */
{
/* Strip "#nnnn " from beginning of error message. */
int offset;
{
break;
}
{
}
else
{
}
}
else
#endif
{
"undefined");
}
#else
#endif
}
{
#ifdef PNG_SETJMP_SUPPORTED
{
# ifdef USE_FAR_KEYWORD
{
}
# else
# endif
}
#endif
/* Here if not setjmp support or if png_ptr is null. */
PNG_ABORT();
}
#ifdef PNG_WARNINGS_SUPPORTED
/* This function is called when there is a warning, but the library thinks
* it can continue anyway. Replacement functions don't have to do anything
* here if you don't want them to. In the default configuration, png_ptr is
* not used, but it is passed in case it may be useful.
*/
static void /* PRIVATE */
{
#ifdef PNG_CONSOLE_IO_SUPPORTED
# ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (*warning_message == PNG_LITERAL_SHARP)
{
int offset;
{
break;
}
{
}
else
{
}
}
else
# endif
{
}
#else
#endif
}
#endif /* PNG_WARNINGS_SUPPORTED */
/* This function is called when the application wants to use another method
* of handling errors and warnings. Note that the error function MUST NOT
* return to the calling routine or serious problems will occur. The return
* method used in the default routine calls longjmp(png_ptr->longjmp_buffer, 1)
*/
void PNGAPI
{
return;
#ifdef PNG_WARNINGS_SUPPORTED
#else
#endif
}
/* This function returns a pointer to the error_ptr associated with the user
* functions. The application should free any memory associated with this
* pointer before png_write_destroy and png_read_destroy are called.
*/
{
return NULL;
}
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
void PNGAPI
{
{
}
}
#endif
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */