#ifdefined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) /* Free a png_struct */ void/* PRIVATE */
png_destroy_png_struct(png_structrp png_ptr)
{ if (png_ptr != NULL)
{ /* png_free might call png_error and may certainly call *png_get_mem_ptr,sofakeatemporarypng_structtosupportthis.
*/
png_struct dummy_struct = *png_ptr;
memset(png_ptr, 0, (sizeof *png_ptr));
png_free(&dummy_struct, png_ptr);
# ifdef PNG_SETJMP_SUPPORTED /* We may have a jmp_buf left to deallocate. */
png_free_jmpbuf(&dummy_struct); # endif
}
}
/* Allocate memory. For reasonable files, size should never exceed *64K.However,zlibmayallocatemorethan64Kifyoudon'ttell *itnotto.Seezconf.handpng.hformoreinformation.zlibdoes *needtoallocateexactly64K,sowhateveryoucallheremust *havetheabilitytodothat.
*/
PNG_FUNCTION(png_voidp,PNGAPI
png_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),
PNG_ALLOCATED)
{
png_voidp ret;
ret = png_malloc(png_ptr, size);
if (ret != NULL)
memset(ret, 0, size);
return ret;
}
/* png_malloc_base, an internal function added at libpng 1.6.0, does the work of *allocatingmemory,takingintoaccountlimitsandPNG_USER_MEM_SUPPORTED. *Checkinganderrorhandlingmusthappenoutsidethisroutine;itreturnsNULL *iftheallocationcannotbedone(foranyreason.)
*/
PNG_FUNCTION(png_voidp /* PRIVATE */,
png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
PNG_ALLOCATED)
{ /* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS *allocatorshavealsobeenremovedin1.6.0,soany16-bitsystemnowhas *toimplementausermemoryhandler.Thischeckstobesureitisn't *calledwithbignumbers.
*/ # ifdef PNG_MAX_MALLOC_64K /* This is support for legacy systems which had segmented addressing *limitingthemaximumallocationsizeto65536.Ittakesprecedence *overPNG_SIZE_MAXwhichissetto65535ontrue16-bitsystems. * *TODO:libpng-1.8:finallyremovebothcases.
*/ if (size > 65536U) return NULL; # endif
/* This is checked too because the system malloc call below takes a (size_t).
*/ if (size > PNG_SIZE_MAX) return NULL;
/* Use the system malloc */ return malloc((size_t)/*SAFE*/size); /* checked for truncation above */
}
#ifdefined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\ defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) /* This is really here only to work round a spurious warning in GCC 4.6 and 4.7 *thatarisesbecauseofthechecksinpng_realloc_arraythatarerepeatedin *png_malloc_array.
*/ static png_voidp
png_malloc_array_checked(png_const_structrp png_ptr, int nelements,
size_t element_size)
{
png_alloc_size_t req = (png_alloc_size_t)nelements; /* known to be > 0 */
if (req <= PNG_SIZE_MAX/element_size) return png_malloc_base(png_ptr, req * element_size);
/* The failure case when the request is too large */ return NULL;
}
PNG_FUNCTION(png_voidp /* PRIVATE */,
png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array, int old_elements, int add_elements, size_t element_size),
PNG_ALLOCATED)
{ /* These are internal errors: */ if (add_elements <= 0 || element_size == 0 || old_elements < 0 ||
(old_array == NULL && old_elements > 0))
png_error(png_ptr, "internal error: array realloc");
/* Check for overflow on the elements count (so the caller does not have to *check.)
*/ if (add_elements <= INT_MAX - old_elements)
{
png_voidp new_array = png_malloc_array_checked(png_ptr,
old_elements+add_elements, element_size);
if (new_array != NULL)
{ /* Because png_malloc_array worked the size calculations below cannot *overflow.
*/ if (old_elements > 0)
memcpy(new_array, old_array, element_size*(unsigned)old_elements);
/* Various functions that have different error handling are derived from this. *png_mallocalwaysexists,butifPNG_USER_MEM_SUPPORTEDisdefinedaseparate *functionpng_malloc_defaultisalsoprovided.
*/
PNG_FUNCTION(png_voidp,PNGAPI
png_malloc,(png_const_structrp png_ptr, png_alloc_size_t size),
PNG_ALLOCATED)
{
png_voidp ret;
if (png_ptr == NULL) return NULL;
ret = png_malloc_base(png_ptr, size);
if (ret == NULL)
png_error(png_ptr, "Out of memory"); /* 'm' means png_malloc */
/* Passing 'NULL' here bypasses the application provided memory handler. */
ret = png_malloc_base(NULL/*use malloc*/, size);
if (ret == NULL)
png_error(png_ptr, "Out of Memory"); /* 'M' means png_malloc_default */
return ret;
} #endif/* USER_MEM */
/* This function was added at libpng version 1.2.3. The png_malloc_warn() *functionwillissueapng_warningandreturnNULLinsteadofissuinga *png_error,ifitfailstoallocatetherequestedmemory.
*/
PNG_FUNCTION(png_voidp,PNGAPI
png_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size),
PNG_ALLOCATED)
{ if (png_ptr != NULL)
{
png_voidp ret = png_malloc_base(png_ptr, size);
if (ret != NULL) return ret;
png_warning(png_ptr, "Out of memory");
}
return NULL;
}
/* Free a pointer allocated by png_malloc(). If ptr is NULL, return *withouttakinganyaction.
*/ void PNGAPI
png_free(png_const_structrp png_ptr, png_voidp ptr)
{ if (png_ptr == NULL || ptr == NULL) return;
#ifdef PNG_USER_MEM_SUPPORTED if (png_ptr->free_fn != NULL)
png_ptr->free_fn(png_constcast(png_structrp,png_ptr), ptr);
#ifdef PNG_USER_MEM_SUPPORTED /* This function is called when the application wants to use another method *ofallocatingandfreeingmemory.
*/ void PNGAPI
png_set_mem_fn(png_structrp png_ptr, png_voidp mem_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn)
{ if (png_ptr != NULL)
{
png_ptr->mem_ptr = mem_ptr;
png_ptr->malloc_fn = malloc_fn;
png_ptr->free_fn = free_fn;
}
}
/* This function returns a pointer to the mem_ptr associated with the user *functions.Theapplicationshouldfreeanymemoryassociatedwiththis *pointerbeforepng_write_destroyandpng_read_destroyarecalled.
*/
png_voidp PNGAPI
png_get_mem_ptr(png_const_structrp png_ptr)
{ if (png_ptr == NULL) return NULL;
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.