]> git.saurik.com Git - wxWidgets.git/blame - src/png/pngerror.c
Fix harmless warning about NULL in wxStyledTextCtrl code.
[wxWidgets.git] / src / png / pngerror.c
CommitLineData
0272a10d
VZ
1
2/* pngerror.c - stub functions for i/o and memory allocation
3 *
72281370 4 * Last changed in libpng 1.5.7 [December 15, 2011]
9c0d9ce3 5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
0272a10d
VZ
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
b61cc19c
PC
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
0272a10d
VZ
13 * This file provides a location for all error handling. Users who
14 * need special error handling are expected to write replacement functions
15 * and use png_set_error_fn() to use those functions. See the instructions
16 * at each function.
17 */
18
b61cc19c 19#include "pngpriv.h"
970f6abe 20
9c0d9ce3
DS
21#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
22
23static PNG_FUNCTION(void, png_default_error,PNGARG((png_structp png_ptr,
24 png_const_charp error_message)),PNG_NORETURN);
25
b61cc19c 26#ifdef PNG_WARNINGS_SUPPORTED
0272a10d
VZ
27static void /* PRIVATE */
28png_default_warning PNGARG((png_structp png_ptr,
9c0d9ce3 29 png_const_charp warning_message));
b61cc19c 30#endif /* PNG_WARNINGS_SUPPORTED */
0272a10d
VZ
31
32/* This function is called whenever there is a fatal error. This function
33 * should not be changed. If there is a need to handle errors differently,
34 * you should supply a replacement error function and use png_set_error_fn()
35 * to replace the error function at run-time.
36 */
b61cc19c 37#ifdef PNG_ERROR_TEXT_SUPPORTED
9c0d9ce3
DS
38PNG_FUNCTION(void,PNGAPI
39png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN)
0272a10d
VZ
40{
41#ifdef PNG_ERROR_NUMBERS_SUPPORTED
42 char msg[16];
43 if (png_ptr != NULL)
44 {
9c0d9ce3
DS
45 if (png_ptr->flags&
46 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
47 {
48 if (*error_message == PNG_LITERAL_SHARP)
49 {
50 /* Strip "#nnnn " from beginning of error message. */
51 int offset;
52 for (offset = 1; offset<15; offset++)
53 if (error_message[offset] == ' ')
0272a10d 54 break;
9c0d9ce3
DS
55
56 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
57 {
58 int i;
59 for (i = 0; i < offset - 1; i++)
60 msg[i] = error_message[i + 1];
61 msg[i - 1] = '\0';
62 error_message = msg;
63 }
64
65 else
66 error_message += offset;
67 }
68
69 else
70 {
71 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
72 {
73 msg[0] = '0';
74 msg[1] = '\0';
75 error_message = msg;
76 }
0272a10d
VZ
77 }
78 }
79 }
80#endif
81 if (png_ptr != NULL && png_ptr->error_fn != NULL)
82 (*(png_ptr->error_fn))(png_ptr, error_message);
83
84 /* If the custom handler doesn't exist, or if it returns,
85 use the default handler, which will not return. */
86 png_default_error(png_ptr, error_message);
87}
88#else
9c0d9ce3
DS
89PNG_FUNCTION(void,PNGAPI
90png_err,(png_structp png_ptr),PNG_NORETURN)
0272a10d 91{
9c0d9ce3
DS
92 /* Prior to 1.5.2 the error_fn received a NULL pointer, expressed
93 * erroneously as '\0', instead of the empty string "". This was
94 * apparently an error, introduced in libpng-1.2.20, and png_default_error
95 * will crash in this case.
96 */
0272a10d 97 if (png_ptr != NULL && png_ptr->error_fn != NULL)
9c0d9ce3 98 (*(png_ptr->error_fn))(png_ptr, "");
0272a10d
VZ
99
100 /* If the custom handler doesn't exist, or if it returns,
101 use the default handler, which will not return. */
9c0d9ce3 102 png_default_error(png_ptr, "");
0272a10d 103}
b61cc19c 104#endif /* PNG_ERROR_TEXT_SUPPORTED */
0272a10d 105
9c0d9ce3
DS
106/* Utility to safely appends strings to a buffer. This never errors out so
107 * error checking is not required in the caller.
108 */
109size_t
110png_safecat(png_charp buffer, size_t bufsize, size_t pos,
111 png_const_charp string)
112{
113 if (buffer != NULL && pos < bufsize)
114 {
115 if (string != NULL)
116 while (*string != '\0' && pos < bufsize-1)
117 buffer[pos++] = *string++;
118
119 buffer[pos] = '\0';
120 }
121
122 return pos;
123}
124
125#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)
126/* Utility to dump an unsigned value into a buffer, given a start pointer and
127 * and end pointer (which should point just *beyond* the end of the buffer!)
128 * Returns the pointer to the start of the formatted string.
129 */
130png_charp
131png_format_number(png_const_charp start, png_charp end, int format,
132 png_alloc_size_t number)
133{
134 int count = 0; /* number of digits output */
135 int mincount = 1; /* minimum number required */
136 int output = 0; /* digit output (for the fixed point format) */
137
138 *--end = '\0';
139
140 /* This is written so that the loop always runs at least once, even with
141 * number zero.
142 */
143 while (end > start && (number != 0 || count < mincount))
144 {
145
146 static const char digits[] = "0123456789ABCDEF";
147
148 switch (format)
149 {
150 case PNG_NUMBER_FORMAT_fixed:
151 /* Needs five digits (the fraction) */
152 mincount = 5;
153 if (output || number % 10 != 0)
154 {
155 *--end = digits[number % 10];
156 output = 1;
157 }
158 number /= 10;
159 break;
160
161 case PNG_NUMBER_FORMAT_02u:
162 /* Expects at least 2 digits. */
163 mincount = 2;
164 /* fall through */
165
166 case PNG_NUMBER_FORMAT_u:
167 *--end = digits[number % 10];
168 number /= 10;
169 break;
170
171 case PNG_NUMBER_FORMAT_02x:
172 /* This format expects at least two digits */
173 mincount = 2;
174 /* fall through */
175
176 case PNG_NUMBER_FORMAT_x:
177 *--end = digits[number & 0xf];
178 number >>= 4;
179 break;
180
181 default: /* an error */
182 number = 0;
183 break;
184 }
185
186 /* Keep track of the number of digits added */
187 ++count;
188
189 /* Float a fixed number here: */
190 if (format == PNG_NUMBER_FORMAT_fixed) if (count == 5) if (end > start)
191 {
192 /* End of the fraction, but maybe nothing was output? In that case
193 * drop the decimal point. If the number is a true zero handle that
194 * here.
195 */
196 if (output)
197 *--end = '.';
198 else if (number == 0) /* and !output */
199 *--end = '0';
200 }
201 }
202
203 return end;
204}
205#endif
206
b61cc19c 207#ifdef PNG_WARNINGS_SUPPORTED
0272a10d
VZ
208/* This function is called whenever there is a non-fatal error. This function
209 * should not be changed. If there is a need to handle warnings differently,
210 * you should supply a replacement warning function and use
211 * png_set_error_fn() to replace the warning function at run-time.
212 */
213void PNGAPI
214png_warning(png_structp png_ptr, png_const_charp warning_message)
215{
216 int offset = 0;
217 if (png_ptr != NULL)
218 {
219#ifdef PNG_ERROR_NUMBERS_SUPPORTED
220 if (png_ptr->flags&
9c0d9ce3 221 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
0272a10d 222#endif
9c0d9ce3
DS
223 {
224 if (*warning_message == PNG_LITERAL_SHARP)
225 {
226 for (offset = 1; offset < 15; offset++)
227 if (warning_message[offset] == ' ')
0272a10d 228 break;
9c0d9ce3
DS
229 }
230 }
0272a10d 231 }
970f6abe
VZ
232 if (png_ptr != NULL && png_ptr->warning_fn != NULL)
233 (*(png_ptr->warning_fn))(png_ptr, warning_message + offset);
0272a10d 234 else
970f6abe 235 png_default_warning(png_ptr, warning_message + offset);
0272a10d 236}
9c0d9ce3
DS
237
238/* These functions support 'formatted' warning messages with up to
239 * PNG_WARNING_PARAMETER_COUNT parameters. In the format string the parameter
240 * is introduced by @<number>, where 'number' starts at 1. This follows the
241 * standard established by X/Open for internationalizable error messages.
242 */
243void
244png_warning_parameter(png_warning_parameters p, int number,
245 png_const_charp string)
246{
247 if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT)
248 (void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string);
249}
250
251void
252png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
253 png_alloc_size_t value)
254{
255 char buffer[PNG_NUMBER_BUFFER_SIZE];
256 png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value));
257}
258
259void
260png_warning_parameter_signed(png_warning_parameters p, int number, int format,
261 png_int_32 value)
262{
263 png_alloc_size_t u;
264 png_charp str;
265 char buffer[PNG_NUMBER_BUFFER_SIZE];
266
267 /* Avoid overflow by doing the negate in a png_alloc_size_t: */
268 u = (png_alloc_size_t)value;
269 if (value < 0)
270 u = ~u + 1;
271
272 str = PNG_FORMAT_NUMBER(buffer, format, u);
273
274 if (value < 0 && str > buffer)
275 *--str = '-';
276
277 png_warning_parameter(p, number, str);
278}
279
280void
281png_formatted_warning(png_structp png_ptr, png_warning_parameters p,
282 png_const_charp message)
283{
284 /* The internal buffer is just 128 bytes - enough for all our messages,
285 * overflow doesn't happen because this code checks!
286 */
287 size_t i;
288 char msg[128];
289
290 for (i=0; i<(sizeof msg)-1 && *message != '\0'; ++i)
291 {
292 if (*message == '@')
293 {
294 int parameter = -1;
295 switch (*++message)
296 {
297 case '1':
298 parameter = 0;
299 break;
300
301 case '2':
302 parameter = 1;
303 break;
304
305 case '\0':
306 continue; /* To break out of the for loop above. */
307
308 default:
309 break;
310 }
311
312 if (parameter >= 0 && parameter < PNG_WARNING_PARAMETER_COUNT)
313 {
314 /* Append this parameter */
315 png_const_charp parm = p[parameter];
316 png_const_charp pend = p[parameter] + (sizeof p[parameter]);
317
318 /* No need to copy the trailing '\0' here, but there is no guarantee
319 * that parm[] has been initialized, so there is no guarantee of a
320 * trailing '\0':
321 */
322 for (; i<(sizeof msg)-1 && parm != '\0' && parm < pend; ++i)
323 msg[i] = *parm++;
324
325 ++message;
326 continue;
327 }
328
329 /* else not a parameter and there is a character after the @ sign; just
330 * copy that.
331 */
332 }
333
334 /* At this point *message can't be '\0', even in the bad parameter case
335 * above where there is a lone '@' at the end of the message string.
336 */
337 msg[i] = *message++;
338 }
339
340 /* i is always less than (sizeof msg), so: */
341 msg[i] = '\0';
342
343 /* And this is the formatted message: */
344 png_warning(png_ptr, msg);
345}
b61cc19c 346#endif /* PNG_WARNINGS_SUPPORTED */
0272a10d 347
b61cc19c
PC
348#ifdef PNG_BENIGN_ERRORS_SUPPORTED
349void PNGAPI
350png_benign_error(png_structp png_ptr, png_const_charp error_message)
351{
352 if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
9c0d9ce3 353 png_warning(png_ptr, error_message);
b61cc19c 354 else
9c0d9ce3 355 png_error(png_ptr, error_message);
b61cc19c
PC
356}
357#endif
0272a10d
VZ
358
359/* These utilities are used internally to build an error message that relates
360 * to the current chunk. The chunk name comes from png_ptr->chunk_name,
361 * this is used to prefix the message. The message is limited in length
362 * to 63 bytes, the name characters are output as hex digits wrapped in []
363 * if the character is invalid.
364 */
365#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
366static PNG_CONST char png_digit[16] = {
367 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
368 'A', 'B', 'C', 'D', 'E', 'F'
369};
370
970f6abe 371#define PNG_MAX_ERROR_TEXT 64
b61cc19c 372#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
0272a10d
VZ
373static void /* PRIVATE */
374png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
9c0d9ce3 375 error_message)
0272a10d 376{
9c0d9ce3
DS
377 png_uint_32 chunk_name = png_ptr->chunk_name;
378 int iout = 0, ishift = 24;
0272a10d 379
9c0d9ce3 380 while (ishift >= 0)
0272a10d 381 {
9c0d9ce3
DS
382 int c = (int)(chunk_name >> ishift) & 0xff;
383
384 ishift -= 8;
0272a10d
VZ
385 if (isnonalpha(c))
386 {
b61cc19c 387 buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
0272a10d
VZ
388 buffer[iout++] = png_digit[(c & 0xf0) >> 4];
389 buffer[iout++] = png_digit[c & 0x0f];
b61cc19c 390 buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET;
0272a10d 391 }
9c0d9ce3 392
0272a10d
VZ
393 else
394 {
9c0d9ce3 395 buffer[iout++] = (char)c;
0272a10d
VZ
396 }
397 }
398
399 if (error_message == NULL)
970f6abe 400 buffer[iout] = '\0';
9c0d9ce3 401
0272a10d
VZ
402 else
403 {
9c0d9ce3
DS
404 int iin = 0;
405
0272a10d
VZ
406 buffer[iout++] = ':';
407 buffer[iout++] = ' ';
9c0d9ce3
DS
408
409 while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\0')
410 buffer[iout++] = error_message[iin++];
411
412 /* iin < PNG_MAX_ERROR_TEXT, so the following is safe: */
413 buffer[iout] = '\0';
0272a10d
VZ
414 }
415}
9c0d9ce3 416#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */
0272a10d 417
9c0d9ce3
DS
418#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
419PNG_FUNCTION(void,PNGAPI
420png_chunk_error,(png_structp png_ptr, png_const_charp error_message),
421 PNG_NORETURN)
0272a10d 422{
970f6abe 423 char msg[18+PNG_MAX_ERROR_TEXT];
0272a10d 424 if (png_ptr == NULL)
9c0d9ce3
DS
425 png_error(png_ptr, error_message);
426
0272a10d
VZ
427 else
428 {
9c0d9ce3
DS
429 png_format_buffer(png_ptr, msg, error_message);
430 png_error(png_ptr, msg);
0272a10d
VZ
431 }
432}
9c0d9ce3 433#endif /* PNG_READ_SUPPORTED && PNG_ERROR_TEXT_SUPPORTED */
0272a10d 434
b61cc19c 435#ifdef PNG_WARNINGS_SUPPORTED
0272a10d
VZ
436void PNGAPI
437png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
438{
970f6abe 439 char msg[18+PNG_MAX_ERROR_TEXT];
0272a10d 440 if (png_ptr == NULL)
9c0d9ce3
DS
441 png_warning(png_ptr, warning_message);
442
0272a10d
VZ
443 else
444 {
9c0d9ce3
DS
445 png_format_buffer(png_ptr, msg, warning_message);
446 png_warning(png_ptr, msg);
0272a10d
VZ
447 }
448}
b61cc19c
PC
449#endif /* PNG_WARNINGS_SUPPORTED */
450
451#ifdef PNG_READ_SUPPORTED
452#ifdef PNG_BENIGN_ERRORS_SUPPORTED
453void PNGAPI
454png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message)
455{
9c0d9ce3
DS
456 if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
457 png_chunk_warning(png_ptr, error_message);
458
459 else
460 png_chunk_error(png_ptr, error_message);
b61cc19c
PC
461}
462#endif
463#endif /* PNG_READ_SUPPORTED */
464
9c0d9ce3
DS
465#ifdef PNG_ERROR_TEXT_SUPPORTED
466#ifdef PNG_FLOATING_POINT_SUPPORTED
467PNG_FUNCTION(void,
468png_fixed_error,(png_structp png_ptr, png_const_charp name),PNG_NORETURN)
469{
470# define fixed_message "fixed point overflow in "
471# define fixed_message_ln ((sizeof fixed_message)-1)
472 int iin;
473 char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
474 png_memcpy(msg, fixed_message, fixed_message_ln);
475 iin = 0;
476 if (name != NULL) while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
477 {
478 msg[fixed_message_ln + iin] = name[iin];
479 ++iin;
480 }
481 msg[fixed_message_ln + iin] = 0;
482 png_error(png_ptr, msg);
483}
484#endif
485#endif
486
b61cc19c
PC
487#ifdef PNG_SETJMP_SUPPORTED
488/* This API only exists if ANSI-C style error handling is used,
489 * otherwise it is necessary for png_default_error to be overridden.
490 */
491jmp_buf* PNGAPI
492png_set_longjmp_fn(png_structp png_ptr, png_longjmp_ptr longjmp_fn,
493 size_t jmp_buf_size)
494{
495 if (png_ptr == NULL || jmp_buf_size != png_sizeof(jmp_buf))
496 return NULL;
0272a10d 497
b61cc19c 498 png_ptr->longjmp_fn = longjmp_fn;
9c0d9ce3 499 return &png_ptr->longjmp_buffer;
b61cc19c
PC
500}
501#endif
0272a10d
VZ
502
503/* This is the default error handling function. Note that replacements for
504 * this function MUST NOT RETURN, or the program will likely crash. This
505 * function is used by default, or if the program supplies NULL for the
506 * error function pointer in png_set_error_fn().
507 */
9c0d9ce3
DS
508static PNG_FUNCTION(void /* PRIVATE */,
509png_default_error,(png_structp png_ptr, png_const_charp error_message),
510 PNG_NORETURN)
0272a10d 511{
b61cc19c 512#ifdef PNG_CONSOLE_IO_SUPPORTED
0272a10d 513#ifdef PNG_ERROR_NUMBERS_SUPPORTED
9c0d9ce3
DS
514 /* Check on NULL only added in 1.5.4 */
515 if (error_message != NULL && *error_message == PNG_LITERAL_SHARP)
0272a10d 516 {
9c0d9ce3
DS
517 /* Strip "#nnnn " from beginning of error message. */
518 int offset;
519 char error_number[16];
520 for (offset = 0; offset<15; offset++)
521 {
970f6abe
VZ
522 error_number[offset] = error_message[offset + 1];
523 if (error_message[offset] == ' ')
9c0d9ce3
DS
524 break;
525 }
526
527 if ((offset > 1) && (offset < 15))
528 {
529 error_number[offset - 1] = '\0';
530 fprintf(stderr, "libpng error no. %s: %s",
531 error_number, error_message + offset + 1);
532 fprintf(stderr, PNG_STRING_NEWLINE);
533 }
534
535 else
536 {
537 fprintf(stderr, "libpng error: %s, offset=%d",
538 error_message, offset);
539 fprintf(stderr, PNG_STRING_NEWLINE);
540 }
0272a10d
VZ
541 }
542 else
543#endif
b61cc19c 544 {
9c0d9ce3
DS
545 fprintf(stderr, "libpng error: %s", error_message ? error_message :
546 "undefined");
b61cc19c
PC
547 fprintf(stderr, PNG_STRING_NEWLINE);
548 }
9c0d9ce3
DS
549#else
550 PNG_UNUSED(error_message) /* Make compiler happy */
0272a10d 551#endif
9c0d9ce3
DS
552 png_longjmp(png_ptr, 1);
553}
0272a10d 554
9c0d9ce3
DS
555PNG_FUNCTION(void,PNGAPI
556png_longjmp,(png_structp png_ptr, int val),PNG_NORETURN)
557{
0272a10d 558#ifdef PNG_SETJMP_SUPPORTED
b61cc19c 559 if (png_ptr && png_ptr->longjmp_fn)
0272a10d
VZ
560 {
561# ifdef USE_FAR_KEYWORD
9c0d9ce3
DS
562 {
563 jmp_buf tmp_jmpbuf;
564 png_memcpy(tmp_jmpbuf, png_ptr->longjmp_buffer, png_sizeof(jmp_buf));
565 png_ptr->longjmp_fn(tmp_jmpbuf, val);
566 }
567
0272a10d 568# else
9c0d9ce3 569 png_ptr->longjmp_fn(png_ptr->longjmp_buffer, val);
0272a10d
VZ
570# endif
571 }
0272a10d 572#endif
b61cc19c
PC
573 /* Here if not setjmp support or if png_ptr is null. */
574 PNG_ABORT();
0272a10d
VZ
575}
576
b61cc19c 577#ifdef PNG_WARNINGS_SUPPORTED
0272a10d
VZ
578/* This function is called when there is a warning, but the library thinks
579 * it can continue anyway. Replacement functions don't have to do anything
580 * here if you don't want them to. In the default configuration, png_ptr is
581 * not used, but it is passed in case it may be useful.
582 */
583static void /* PRIVATE */
584png_default_warning(png_structp png_ptr, png_const_charp warning_message)
585{
b61cc19c 586#ifdef PNG_CONSOLE_IO_SUPPORTED
0272a10d 587# ifdef PNG_ERROR_NUMBERS_SUPPORTED
b61cc19c 588 if (*warning_message == PNG_LITERAL_SHARP)
0272a10d 589 {
9c0d9ce3
DS
590 int offset;
591 char warning_number[16];
592 for (offset = 0; offset < 15; offset++)
593 {
594 warning_number[offset] = warning_message[offset + 1];
595 if (warning_message[offset] == ' ')
0272a10d 596 break;
9c0d9ce3
DS
597 }
598
599 if ((offset > 1) && (offset < 15))
600 {
601 warning_number[offset + 1] = '\0';
602 fprintf(stderr, "libpng warning no. %s: %s",
603 warning_number, warning_message + offset);
604 fprintf(stderr, PNG_STRING_NEWLINE);
605 }
606
607 else
608 {
609 fprintf(stderr, "libpng warning: %s",
610 warning_message);
611 fprintf(stderr, PNG_STRING_NEWLINE);
612 }
0272a10d
VZ
613 }
614 else
615# endif
9c0d9ce3 616
b61cc19c 617 {
9c0d9ce3
DS
618 fprintf(stderr, "libpng warning: %s", warning_message);
619 fprintf(stderr, PNG_STRING_NEWLINE);
b61cc19c 620 }
0272a10d 621#else
9c0d9ce3 622 PNG_UNUSED(warning_message) /* Make compiler happy */
0272a10d 623#endif
9c0d9ce3 624 PNG_UNUSED(png_ptr) /* Make compiler happy */
0272a10d 625}
b61cc19c 626#endif /* PNG_WARNINGS_SUPPORTED */
0272a10d
VZ
627
628/* This function is called when the application wants to use another method
629 * of handling errors and warnings. Note that the error function MUST NOT
630 * return to the calling routine or serious problems will occur. The return
9c0d9ce3 631 * method used in the default routine calls longjmp(png_ptr->longjmp_buffer, 1)
0272a10d
VZ
632 */
633void PNGAPI
634png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
9c0d9ce3 635 png_error_ptr error_fn, png_error_ptr warning_fn)
0272a10d
VZ
636{
637 if (png_ptr == NULL)
638 return;
9c0d9ce3 639
0272a10d
VZ
640 png_ptr->error_ptr = error_ptr;
641 png_ptr->error_fn = error_fn;
9c0d9ce3 642#ifdef PNG_WARNINGS_SUPPORTED
0272a10d 643 png_ptr->warning_fn = warning_fn;
9c0d9ce3
DS
644#else
645 PNG_UNUSED(warning_fn)
646#endif
0272a10d
VZ
647}
648
649
650/* This function returns a pointer to the error_ptr associated with the user
651 * functions. The application should free any memory associated with this
652 * pointer before png_write_destroy and png_read_destroy are called.
653 */
654png_voidp PNGAPI
9c0d9ce3 655png_get_error_ptr(png_const_structp png_ptr)
0272a10d
VZ
656{
657 if (png_ptr == NULL)
658 return NULL;
9c0d9ce3 659
0272a10d
VZ
660 return ((png_voidp)png_ptr->error_ptr);
661}
662
663
664#ifdef PNG_ERROR_NUMBERS_SUPPORTED
665void PNGAPI
666png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
667{
970f6abe 668 if (png_ptr != NULL)
0272a10d 669 {
9c0d9ce3
DS
670 png_ptr->flags &=
671 ((~(PNG_FLAG_STRIP_ERROR_NUMBERS |
672 PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
0272a10d
VZ
673 }
674}
675#endif
676#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */