dbf-halloween2015

annotate libs/libpng/pngerror.c @ 2:5ae5fd3626fa

macosx port works
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Nov 2015 00:51:36 +0200
parents
children
rev   line source
nuclear@1 1
nuclear@1 2 /* pngerror.c - stub functions for i/o and memory allocation
nuclear@1 3 *
nuclear@1 4 * Last changed in libpng 1.2.30 [August 15, 2008]
nuclear@1 5 * For conditions of distribution and use, see copyright notice in png.h
nuclear@1 6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson
nuclear@1 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
nuclear@1 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
nuclear@1 9 *
nuclear@1 10 * This file provides a location for all error handling. Users who
nuclear@1 11 * need special error handling are expected to write replacement functions
nuclear@1 12 * and use png_set_error_fn() to use those functions. See the instructions
nuclear@1 13 * at each function.
nuclear@1 14 */
nuclear@1 15
nuclear@1 16 #define PNG_INTERNAL
nuclear@1 17 #include "png.h"
nuclear@1 18 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
nuclear@1 19
nuclear@1 20 static void /* PRIVATE */
nuclear@1 21 png_default_error PNGARG((png_structp png_ptr,
nuclear@1 22 png_const_charp error_message));
nuclear@1 23 #ifndef PNG_NO_WARNINGS
nuclear@1 24 static void /* PRIVATE */
nuclear@1 25 png_default_warning PNGARG((png_structp png_ptr,
nuclear@1 26 png_const_charp warning_message));
nuclear@1 27 #endif /* PNG_NO_WARNINGS */
nuclear@1 28
nuclear@1 29 /* This function is called whenever there is a fatal error. This function
nuclear@1 30 * should not be changed. If there is a need to handle errors differently,
nuclear@1 31 * you should supply a replacement error function and use png_set_error_fn()
nuclear@1 32 * to replace the error function at run-time.
nuclear@1 33 */
nuclear@1 34 #ifndef PNG_NO_ERROR_TEXT
nuclear@1 35 void PNGAPI
nuclear@1 36 png_error(png_structp png_ptr, png_const_charp error_message)
nuclear@1 37 {
nuclear@1 38 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
nuclear@1 39 char msg[16];
nuclear@1 40 if (png_ptr != NULL)
nuclear@1 41 {
nuclear@1 42 if (png_ptr->flags&
nuclear@1 43 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
nuclear@1 44 {
nuclear@1 45 if (*error_message == '#')
nuclear@1 46 {
nuclear@1 47 /* Strip "#nnnn " from beginning of error message. */
nuclear@1 48 int offset;
nuclear@1 49 for (offset = 1; offset<15; offset++)
nuclear@1 50 if (error_message[offset] == ' ')
nuclear@1 51 break;
nuclear@1 52 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
nuclear@1 53 {
nuclear@1 54 int i;
nuclear@1 55 for (i = 0; i < offset - 1; i++)
nuclear@1 56 msg[i] = error_message[i + 1];
nuclear@1 57 msg[i - 1] = '\0';
nuclear@1 58 error_message = msg;
nuclear@1 59 }
nuclear@1 60 else
nuclear@1 61 error_message += offset;
nuclear@1 62 }
nuclear@1 63 else
nuclear@1 64 {
nuclear@1 65 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
nuclear@1 66 {
nuclear@1 67 msg[0] = '0';
nuclear@1 68 msg[1] = '\0';
nuclear@1 69 error_message = msg;
nuclear@1 70 }
nuclear@1 71 }
nuclear@1 72 }
nuclear@1 73 }
nuclear@1 74 #endif
nuclear@1 75 if (png_ptr != NULL && png_ptr->error_fn != NULL)
nuclear@1 76 (*(png_ptr->error_fn))(png_ptr, error_message);
nuclear@1 77
nuclear@1 78 /* If the custom handler doesn't exist, or if it returns,
nuclear@1 79 use the default handler, which will not return. */
nuclear@1 80 png_default_error(png_ptr, error_message);
nuclear@1 81 }
nuclear@1 82 #else
nuclear@1 83 void PNGAPI
nuclear@1 84 png_err(png_structp png_ptr)
nuclear@1 85 {
nuclear@1 86 if (png_ptr != NULL && png_ptr->error_fn != NULL)
nuclear@1 87 (*(png_ptr->error_fn))(png_ptr, '\0');
nuclear@1 88
nuclear@1 89 /* If the custom handler doesn't exist, or if it returns,
nuclear@1 90 use the default handler, which will not return. */
nuclear@1 91 png_default_error(png_ptr, '\0');
nuclear@1 92 }
nuclear@1 93 #endif /* PNG_NO_ERROR_TEXT */
nuclear@1 94
nuclear@1 95 #ifndef PNG_NO_WARNINGS
nuclear@1 96 /* This function is called whenever there is a non-fatal error. This function
nuclear@1 97 * should not be changed. If there is a need to handle warnings differently,
nuclear@1 98 * you should supply a replacement warning function and use
nuclear@1 99 * png_set_error_fn() to replace the warning function at run-time.
nuclear@1 100 */
nuclear@1 101 void PNGAPI
nuclear@1 102 png_warning(png_structp png_ptr, png_const_charp warning_message)
nuclear@1 103 {
nuclear@1 104 int offset = 0;
nuclear@1 105 if (png_ptr != NULL)
nuclear@1 106 {
nuclear@1 107 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
nuclear@1 108 if (png_ptr->flags&
nuclear@1 109 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
nuclear@1 110 #endif
nuclear@1 111 {
nuclear@1 112 if (*warning_message == '#')
nuclear@1 113 {
nuclear@1 114 for (offset = 1; offset < 15; offset++)
nuclear@1 115 if (warning_message[offset] == ' ')
nuclear@1 116 break;
nuclear@1 117 }
nuclear@1 118 }
nuclear@1 119 if (png_ptr != NULL && png_ptr->warning_fn != NULL)
nuclear@1 120 (*(png_ptr->warning_fn))(png_ptr, warning_message + offset);
nuclear@1 121 }
nuclear@1 122 else
nuclear@1 123 png_default_warning(png_ptr, warning_message + offset);
nuclear@1 124 }
nuclear@1 125 #endif /* PNG_NO_WARNINGS */
nuclear@1 126
nuclear@1 127
nuclear@1 128 /* These utilities are used internally to build an error message that relates
nuclear@1 129 * to the current chunk. The chunk name comes from png_ptr->chunk_name,
nuclear@1 130 * this is used to prefix the message. The message is limited in length
nuclear@1 131 * to 63 bytes, the name characters are output as hex digits wrapped in []
nuclear@1 132 * if the character is invalid.
nuclear@1 133 */
nuclear@1 134 #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
nuclear@1 135 static PNG_CONST char png_digit[16] = {
nuclear@1 136 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
nuclear@1 137 'A', 'B', 'C', 'D', 'E', 'F'
nuclear@1 138 };
nuclear@1 139
nuclear@1 140 #define PNG_MAX_ERROR_TEXT 64
nuclear@1 141
nuclear@1 142 #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
nuclear@1 143 static void /* PRIVATE */
nuclear@1 144 png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
nuclear@1 145 error_message)
nuclear@1 146 {
nuclear@1 147 int iout = 0, iin = 0;
nuclear@1 148
nuclear@1 149 while (iin < 4)
nuclear@1 150 {
nuclear@1 151 int c = png_ptr->chunk_name[iin++];
nuclear@1 152 if (isnonalpha(c))
nuclear@1 153 {
nuclear@1 154 buffer[iout++] = '[';
nuclear@1 155 buffer[iout++] = png_digit[(c & 0xf0) >> 4];
nuclear@1 156 buffer[iout++] = png_digit[c & 0x0f];
nuclear@1 157 buffer[iout++] = ']';
nuclear@1 158 }
nuclear@1 159 else
nuclear@1 160 {
nuclear@1 161 buffer[iout++] = (png_byte)c;
nuclear@1 162 }
nuclear@1 163 }
nuclear@1 164
nuclear@1 165 if (error_message == NULL)
nuclear@1 166 buffer[iout] = '\0';
nuclear@1 167 else
nuclear@1 168 {
nuclear@1 169 buffer[iout++] = ':';
nuclear@1 170 buffer[iout++] = ' ';
nuclear@1 171 png_memcpy(buffer + iout, error_message, PNG_MAX_ERROR_TEXT);
nuclear@1 172 buffer[iout + PNG_MAX_ERROR_TEXT - 1] = '\0';
nuclear@1 173 }
nuclear@1 174 }
nuclear@1 175
nuclear@1 176 #ifdef PNG_READ_SUPPORTED
nuclear@1 177 void PNGAPI
nuclear@1 178 png_chunk_error(png_structp png_ptr, png_const_charp error_message)
nuclear@1 179 {
nuclear@1 180 char msg[18+PNG_MAX_ERROR_TEXT];
nuclear@1 181 if (png_ptr == NULL)
nuclear@1 182 png_error(png_ptr, error_message);
nuclear@1 183 else
nuclear@1 184 {
nuclear@1 185 png_format_buffer(png_ptr, msg, error_message);
nuclear@1 186 png_error(png_ptr, msg);
nuclear@1 187 }
nuclear@1 188 }
nuclear@1 189 #endif /* PNG_READ_SUPPORTED */
nuclear@1 190 #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
nuclear@1 191
nuclear@1 192 #ifndef PNG_NO_WARNINGS
nuclear@1 193 void PNGAPI
nuclear@1 194 png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
nuclear@1 195 {
nuclear@1 196 char msg[18+PNG_MAX_ERROR_TEXT];
nuclear@1 197 if (png_ptr == NULL)
nuclear@1 198 png_warning(png_ptr, warning_message);
nuclear@1 199 else
nuclear@1 200 {
nuclear@1 201 png_format_buffer(png_ptr, msg, warning_message);
nuclear@1 202 png_warning(png_ptr, msg);
nuclear@1 203 }
nuclear@1 204 }
nuclear@1 205 #endif /* PNG_NO_WARNINGS */
nuclear@1 206
nuclear@1 207
nuclear@1 208 /* This is the default error handling function. Note that replacements for
nuclear@1 209 * this function MUST NOT RETURN, or the program will likely crash. This
nuclear@1 210 * function is used by default, or if the program supplies NULL for the
nuclear@1 211 * error function pointer in png_set_error_fn().
nuclear@1 212 */
nuclear@1 213 static void /* PRIVATE */
nuclear@1 214 png_default_error(png_structp png_ptr, png_const_charp error_message)
nuclear@1 215 {
nuclear@1 216 #ifndef PNG_NO_CONSOLE_IO
nuclear@1 217 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
nuclear@1 218 if (*error_message == '#')
nuclear@1 219 {
nuclear@1 220 /* Strip "#nnnn " from beginning of warning message. */
nuclear@1 221 int offset;
nuclear@1 222 char error_number[16];
nuclear@1 223 for (offset = 0; offset<15; offset++)
nuclear@1 224 {
nuclear@1 225 error_number[offset] = error_message[offset + 1];
nuclear@1 226 if (error_message[offset] == ' ')
nuclear@1 227 break;
nuclear@1 228 }
nuclear@1 229 if ((offset > 1) && (offset < 15))
nuclear@1 230 {
nuclear@1 231 error_number[offset - 1] = '\0';
nuclear@1 232 fprintf(stderr, "libpng error no. %s: %s\n", error_number,
nuclear@1 233 error_message + offset + 1);
nuclear@1 234 }
nuclear@1 235 else
nuclear@1 236 fprintf(stderr, "libpng error: %s, offset=%d\n", error_message, offset);
nuclear@1 237 }
nuclear@1 238 else
nuclear@1 239 #endif
nuclear@1 240 fprintf(stderr, "libpng error: %s\n", error_message);
nuclear@1 241 #endif
nuclear@1 242
nuclear@1 243 #ifdef PNG_SETJMP_SUPPORTED
nuclear@1 244 if (png_ptr)
nuclear@1 245 {
nuclear@1 246 # ifdef USE_FAR_KEYWORD
nuclear@1 247 {
nuclear@1 248 jmp_buf jmpbuf;
nuclear@1 249 png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
nuclear@1 250 longjmp(jmpbuf, 1);
nuclear@1 251 }
nuclear@1 252 # else
nuclear@1 253 longjmp(png_ptr->jmpbuf, 1);
nuclear@1 254 # endif
nuclear@1 255 }
nuclear@1 256 #else
nuclear@1 257 PNG_ABORT();
nuclear@1 258 #endif
nuclear@1 259 #ifdef PNG_NO_CONSOLE_IO
nuclear@1 260 error_message = error_message; /* make compiler happy */
nuclear@1 261 #endif
nuclear@1 262 }
nuclear@1 263
nuclear@1 264 #ifndef PNG_NO_WARNINGS
nuclear@1 265 /* This function is called when there is a warning, but the library thinks
nuclear@1 266 * it can continue anyway. Replacement functions don't have to do anything
nuclear@1 267 * here if you don't want them to. In the default configuration, png_ptr is
nuclear@1 268 * not used, but it is passed in case it may be useful.
nuclear@1 269 */
nuclear@1 270 static void /* PRIVATE */
nuclear@1 271 png_default_warning(png_structp png_ptr, png_const_charp warning_message)
nuclear@1 272 {
nuclear@1 273 #ifndef PNG_NO_CONSOLE_IO
nuclear@1 274 # ifdef PNG_ERROR_NUMBERS_SUPPORTED
nuclear@1 275 if (*warning_message == '#')
nuclear@1 276 {
nuclear@1 277 int offset;
nuclear@1 278 char warning_number[16];
nuclear@1 279 for (offset = 0; offset < 15; offset++)
nuclear@1 280 {
nuclear@1 281 warning_number[offset] = warning_message[offset + 1];
nuclear@1 282 if (warning_message[offset] == ' ')
nuclear@1 283 break;
nuclear@1 284 }
nuclear@1 285 if ((offset > 1) && (offset < 15))
nuclear@1 286 {
nuclear@1 287 warning_number[offset + 1] = '\0';
nuclear@1 288 fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
nuclear@1 289 warning_message + offset);
nuclear@1 290 }
nuclear@1 291 else
nuclear@1 292 fprintf(stderr, "libpng warning: %s\n", warning_message);
nuclear@1 293 }
nuclear@1 294 else
nuclear@1 295 # endif
nuclear@1 296 fprintf(stderr, "libpng warning: %s\n", warning_message);
nuclear@1 297 #else
nuclear@1 298 warning_message = warning_message; /* make compiler happy */
nuclear@1 299 #endif
nuclear@1 300 png_ptr = png_ptr; /* make compiler happy */
nuclear@1 301 }
nuclear@1 302 #endif /* PNG_NO_WARNINGS */
nuclear@1 303
nuclear@1 304 /* This function is called when the application wants to use another method
nuclear@1 305 * of handling errors and warnings. Note that the error function MUST NOT
nuclear@1 306 * return to the calling routine or serious problems will occur. The return
nuclear@1 307 * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
nuclear@1 308 */
nuclear@1 309 void PNGAPI
nuclear@1 310 png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
nuclear@1 311 png_error_ptr error_fn, png_error_ptr warning_fn)
nuclear@1 312 {
nuclear@1 313 if (png_ptr == NULL)
nuclear@1 314 return;
nuclear@1 315 png_ptr->error_ptr = error_ptr;
nuclear@1 316 png_ptr->error_fn = error_fn;
nuclear@1 317 png_ptr->warning_fn = warning_fn;
nuclear@1 318 }
nuclear@1 319
nuclear@1 320
nuclear@1 321 /* This function returns a pointer to the error_ptr associated with the user
nuclear@1 322 * functions. The application should free any memory associated with this
nuclear@1 323 * pointer before png_write_destroy and png_read_destroy are called.
nuclear@1 324 */
nuclear@1 325 png_voidp PNGAPI
nuclear@1 326 png_get_error_ptr(png_structp png_ptr)
nuclear@1 327 {
nuclear@1 328 if (png_ptr == NULL)
nuclear@1 329 return NULL;
nuclear@1 330 return ((png_voidp)png_ptr->error_ptr);
nuclear@1 331 }
nuclear@1 332
nuclear@1 333
nuclear@1 334 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
nuclear@1 335 void PNGAPI
nuclear@1 336 png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
nuclear@1 337 {
nuclear@1 338 if (png_ptr != NULL)
nuclear@1 339 {
nuclear@1 340 png_ptr->flags &=
nuclear@1 341 ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
nuclear@1 342 }
nuclear@1 343 }
nuclear@1 344 #endif
nuclear@1 345 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */