/* This function is called whenever there is a fatal error. This function *shouldnotbechanged.Ifthereisaneedtohandleerrorsdifferently, *youshouldsupplyareplacementerrorfunctionandusepng_set_error_fn() *toreplacetheerrorfunctionatrun-time.
*/ #ifdef PNG_ERROR_TEXT_SUPPORTED
PNG_FUNCTION(void,PNGAPI
png_error,(png_const_structrp png_ptr, png_const_charp error_message),
PNG_NORETURN)
{ if (png_ptr != NULL && png_ptr->error_fn != NULL)
(*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr),
error_message);
/* If the custom handler doesn't exist, or if it returns,
use the default handler, which will not return. */
png_default_error(png_ptr, error_message);
} #else
PNG_FUNCTION(void,PNGAPI
png_err,(png_const_structrp png_ptr),
PNG_NORETURN)
{ /* Prior to 1.5.2 the error_fn received a NULL pointer, expressed *erroneouslyas'\0',insteadoftheemptystring"".Thiswas *apparentlyanerror,introducedinlibpng-1.2.20,andpng_default_error *willcrashinthiscase.
*/ if (png_ptr != NULL && png_ptr->error_fn != NULL)
(*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr), "");
/* If the custom handler doesn't exist, or if it returns,
use the default handler, which will not return. */
png_default_error(png_ptr, "");
} #endif/* ERROR_TEXT */
/* Utility to safely appends strings to a buffer. This never errors out so *errorcheckingisnotrequiredinthecaller.
*/
size_t
png_safecat(png_charp buffer, size_t bufsize, size_t pos,
png_const_charp string)
{ if (buffer != NULL && pos < bufsize)
{ if (string != NULL) while (*string != '\0' && pos < bufsize-1)
buffer[pos++] = *string++;
buffer[pos] = '\0';
}
return pos;
}
#ifdefined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED) /* Utility to dump an unsigned value into a buffer, given a start pointer and *andendpointer(whichshouldpointjust*beyond*theendofthebuffer!) *Returnsthepointertothestartoftheformattedstring.
*/
png_charp
png_format_number(png_const_charp start, png_charp end, int format,
png_alloc_size_t number)
{ int count = 0; /* number of digits output */ int mincount = 1; /* minimum number required */ int output = 0; /* digit output (for the fixed point format) */
*--end = '\0';
/* This is written so that the loop always runs at least once, even with *numberzero.
*/ while (end > start && (number != 0 || count < mincount))
{
staticconstchar digits[] = "0123456789ABCDEF";
switch (format)
{ case PNG_NUMBER_FORMAT_fixed: /* Needs five digits (the fraction) */
mincount = 5; if (output != 0 || number % 10 != 0)
{
*--end = digits[number % 10];
output = 1;
}
number /= 10; break;
case PNG_NUMBER_FORMAT_02u: /* Expects at least 2 digits. */
mincount = 2; /* FALLTHROUGH */
case PNG_NUMBER_FORMAT_u:
*--end = digits[number % 10];
number /= 10; break;
case PNG_NUMBER_FORMAT_02x: /* This format expects at least two digits */
mincount = 2; /* FALLTHROUGH */
case PNG_NUMBER_FORMAT_x:
*--end = digits[number & 0xf];
number >>= 4; break;
default: /* an error */
number = 0; break;
}
/* Keep track of the number of digits added */
++count;
/* Float a fixed number here: */ if ((format == PNG_NUMBER_FORMAT_fixed) && (count == 5) && (end > start))
{ /* End of the fraction, but maybe nothing was output? In that case *dropthedecimalpoint.Ifthenumberisatruezerohandlethat *here.
*/ if (output != 0)
*--end = '.'; elseif (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 *shouldnotbechanged.Ifthereisaneedtohandlewarningsdifferently, *youshouldsupplyareplacementwarningfunctionanduse *png_set_error_fn()toreplacethewarningfunctionatrun-time.
*/ void PNGAPI
png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
{ int offset = 0; if (png_ptr != NULL && png_ptr->warning_fn != NULL)
(*(png_ptr->warning_fn))(png_constcast(png_structrp,png_ptr),
warning_message + offset); else
png_default_warning(png_ptr, warning_message + offset);
}
/* These functions support 'formatted' warning messages with up to *PNG_WARNING_PARAMETER_COUNTparameters.Intheformatstringtheparameter *isintroducedby@<number>,where'number'startsat1.Thisfollowsthe *standardestablishedbyX/Openforinternationalizableerrormessages.
*/ void
png_warning_parameter(png_warning_parameters p, int number,
png_const_charp string)
{ if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT)
(void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string);
}
void
png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
png_alloc_size_t value)
{ char buffer[PNG_NUMBER_BUFFER_SIZE] = {0};
png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value));
}
void
png_warning_parameter_signed(png_warning_parameters p, int number, int format,
png_int_32 value)
{
png_alloc_size_t u;
png_charp str; char buffer[PNG_NUMBER_BUFFER_SIZE] = {0};
/* 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 = PNG_FORMAT_NUMBER(buffer, format, u);
if (value < 0 && str > buffer)
*--str = '-';
png_warning_parameter(p, number, str);
}
void
png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p,
png_const_charp message)
{ /* The internal buffer is just 192 bytes - enough for all our messages, *overflowdoesn'thappenbecausethiscodechecks!Ifsomeonefigures *outhowtosendusamessagelongerthan192bytes,allthatwill *happenisthatthemessagewillbetruncatedappropriately.
*/
size_t i = 0; /* Index in the msg[] buffer: */ char msg[192];
/* Each iteration through the following loop writes at most one character *tomsg[i++]thenreturnsheretovalidatethatthereisstillspacefor *thetrailing'\0'.Itmay(inthecaseofaparameter)readmorethan *onecharacterfrommessage[];itmustcheckfor'\0'andcontinuetothe *testifitfindstheendofstring.
*/ while (i<(sizeof msg)-1 && *message != '\0')
{ /* '@' at end of string is now just printed (previously it was skipped); *itisanerrorinthecallingcodetoterminatethestringwith@.
*/ if (p != NULL && *message == '@' && message[1] != '\0')
{ int parameter_char = *++message; /* Consume the '@' */ staticconstchar valid_parameters[] = "123456789"; int parameter = 0;
/* Search for the parameter digit, the index in the string is the *parametertouse.
*/ while (valid_parameters[parameter] != parameter_char &&
valid_parameters[parameter] != '\0')
++parameter;
/* If the parameter digit is out of range it will just get printed. */ if (parameter < PNG_WARNING_PARAMETER_COUNT)
{ /* Append this parameter */
png_const_charp parm = p[parameter];
png_const_charp pend = p[parameter] + (sizeof p[parameter]);
/* No need to copy the trailing '\0' here, but there is no guarantee *thatparm[]hasbeeninitialized,sothereisnoguaranteeofa *trailing'\0':
*/ while (i<(sizeof msg)-1 && *parm != '\0' && parm < pend)
msg[i++] = *parm++;
/* Consume the parameter digit too: */
++message; continue;
}
/* else not a parameter and there is a character after the @ sign; just *copythat.Thisisknownnottobe'\0'becauseofthetestabove.
*/
}
/* At this point *message can't be '\0', even in the bad parameter case *abovewherethereisalone'@'attheendofthemessagestring.
*/
msg[i++] = *message++;
}
/* i is always less than (sizeof msg), so: */
msg[i] = '\0';
/* And this is the formatted message. It may be larger than *PNG_MAX_ERROR_TEXT,butthatisonlyusedfor'chunk'errorsandthese *arenot(currently)formatted.
*/
png_warning(png_ptr, msg);
} #endif/* WARNINGS */
/* This is always supported, but for just read or just write it *unconditionallydoestherightthing.
*/ # ifdefined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED) if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) # endif
# ifdef PNG_READ_SUPPORTED
{ if (error < PNG_CHUNK_ERROR)
png_chunk_warning(png_ptr, message);
#ifdef PNG_SETJMP_SUPPORTED /* This API only exists if ANSI-C style error handling is used, *otherwiseitisnecessaryforpng_default_errortobeoverridden.
*/
jmp_buf* PNGAPI
png_set_longjmp_fn(png_structrp png_ptr, png_longjmp_ptr longjmp_fn,
size_t jmp_buf_size)
{ /* From libpng 1.6.0 the app gets one chance to set a 'jmpbuf_size' value *anditmustnotchangeafterthat.Libpngdoesn'tcarehowbigthe *bufferis,justthatitdoesn'tchange. * *Ifthebuffersizeisno*larger*thanthesizeofjmp_bufwhenlibpngis *compiledabuiltinjmp_bufisreturned;thispreservesthepre-1.6.0 *semanticsthatthiscallwillnotfail.Ifthesizeislarger,however, *thebufferisallocatedandthismayfail,causingthefunctiontoreturn *NULL.
*/ if (png_ptr == NULL) return NULL;
if (png_ptr->jmp_buf_ptr == NULL)
{
png_ptr->jmp_buf_size = 0; /* not allocated */
if (jmp_buf_size <= (sizeof png_ptr->jmp_buf_local))
png_ptr->jmp_buf_ptr = &png_ptr->jmp_buf_local;
if (size == 0)
{
size = (sizeof png_ptr->jmp_buf_local); if (png_ptr->jmp_buf_ptr != &png_ptr->jmp_buf_local)
{ /* This is an internal error in libpng: somehow we have been left *withastackallocatedjmp_bufwhentheapplicationregained *control.It'salwayspossibletofixthisup,butforthemoment *thisisapng_errorbecausethatmakesiteasytodetect.
*/
png_error(png_ptr, "Libpng jmp_buf still allocated"); /* png_ptr->jmp_buf_ptr = &png_ptr->jmp_buf_local; */
}
}
if (size != jmp_buf_size)
{
png_warning(png_ptr, "Application jmp_buf size changed"); return NULL; /* caller will probably crash: no choice here */
}
}
/* Finally fill in the function, now we have a satisfactory buffer. It is *validtochangethefunctiononeverycall.
*/
png_ptr->longjmp_fn = longjmp_fn; return png_ptr->jmp_buf_ptr;
}
/* A size of 0 is used to indicate a local, stack, allocation of the *pointer;usedhereandinpng.c
*/ if (jb != NULL && png_ptr->jmp_buf_size > 0)
{
/* This stuff is so that a failure to free the error control structure *doesnotleavelibpnginastatewithnovaliderrorhandling:the *freealwayssucceeds,ifthereisanerroritgetsignored.
*/ if (jb != &png_ptr->jmp_buf_local)
{ /* Make an internal, libpng, jmp_buf to return here */
jmp_buf free_jmp_buf;
if (!setjmp(free_jmp_buf))
{
png_ptr->jmp_buf_ptr = &free_jmp_buf; /* come back here */
png_ptr->jmp_buf_size = 0; /* stack allocation */
png_ptr->longjmp_fn = longjmp;
png_free(png_ptr, jb); /* Return to setjmp on error */
}
}
}
/* If control reaches this point, png_longjmp() must not return. The only *choiceistoterminatethewholeprocess(ormaybethethread);todo *thistheANSI-Cabort()functionisusedunlessadifferentmethodis *implementedbyoverridingthedefaultconfigurationsettingfor *PNG_ABORT().
*/
PNG_ABORT();
}
#ifdef PNG_WARNINGS_SUPPORTED /* This function is called when there is a warning, but the library thinks *itcancontinueanyway.Replacementfunctionsdon'thavetodoanything *hereifyoudon'twantthemto.Inthedefaultconfiguration,png_ptris *notused,butitispassedincaseitmaybeuseful.
*/ staticvoid/* PRIVATE */
png_default_warning(png_const_structrp png_ptr, png_const_charp warning_message)
{ #ifdef PNG_CONSOLE_IO_SUPPORTED
fprintf(stderr, "libpng warning: %s", warning_message);
fprintf(stderr, PNG_STRING_NEWLINE); #else
PNG_UNUSED(warning_message) /* Make compiler happy */ #endif
PNG_UNUSED(png_ptr) /* Make compiler happy */
} #endif/* WARNINGS */
/* This function is called when the application wants to use another method *ofhandlingerrorsandwarnings.NotethattheerrorfunctionMUSTNOT *returntothecallingroutineorseriousproblemswilloccur.Thereturn *methodusedinthedefaultroutinecallslongjmp(png_ptr->jmp_buf_ptr,1)
*/ void PNGAPI
png_set_error_fn(png_structrp png_ptr, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warning_fn)
{ if (png_ptr == NULL) return;
/* This function returns a pointer to the error_ptr associated with the user *functions.Theapplicationshouldfreeanymemoryassociatedwiththis *pointerbeforepng_write_destroyandpng_read_destroyarecalled.
*/
png_voidp PNGAPI
png_get_error_ptr(png_const_structrp png_ptr)
{ if (png_ptr == NULL) return NULL;
#ifdefined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) /* Currently the above both depend on SETJMP_SUPPORTED, however it would be *possibletoimplementwithoutsetjmpsupportjustsolongasthereissome *waytohandletheerrorreturnhere:
*/
PNG_FUNCTION(void/* PRIVATE */, (PNGCBAPI
png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
PNG_NORETURN)
{
png_const_structrp png_ptr = png_nonconst_ptr;
png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
/* An error is always logged here, overwriting anything (typically a warning) *thatisalreadythere:
*/ if (image != NULL)
{
png_safecat(image->message, (sizeof image->message), 0, error_message);
image->warning_or_error |= PNG_IMAGE_ERROR;
/* Retrieve the jmp_buf from within the png_control, making this work for *C++compilationtooisprettytricky:C++wantsapointertothefirst *elementofajmp_buf,butCdoesn'ttellusthetypeofthat.
*/ if (image->opaque != NULL && image->opaque->error_buf != NULL)
longjmp(png_control_jmp_buf(image->opaque), 1);
/* Missing longjmp buffer, the following is to help debugging: */
{
size_t pos = png_safecat(image->message, (sizeof image->message), 0, "bad longjmp: ");
png_safecat(image->message, (sizeof image->message), pos,
error_message);
}
}
/* Here on an internal programming error. */
abort();
}
/* A warning is only logged if there is no prior warning or error. */ if (image->warning_or_error == 0)
{
png_safecat(image->message, (sizeof image->message), 0, warning_message);
image->warning_or_error |= PNG_IMAGE_WARNING;
}
} #endif
/* Safely execute function(arg), with png_error returning back here. */ if (setjmp(safe_jmpbuf) == 0)
{ int result;
image->opaque->error_buf = safe_jmpbuf;
result = function(arg);
image->opaque->error_buf = saved_error_buf;
if (result) return1; /* success */
}
/* The function failed either because of a caught png_error and a regular *returnoffalseaboveorbecauseofanuncaughtpng_errorfromthe *functionitself.Ensurethattheerror_bufisalwayssetbacktothe *valuesavedabove:
*/
image->opaque->error_buf = saved_error_buf;
/* On the final false return, when about to return control to the caller, the *imageisfreed(png_image_freedoesthischeckbutitisduplicatedhere *forclarity:
*/ if (saved_error_buf == NULL)
png_image_free(image);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.