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