Imported from libpng-1.4.0beta11.tar

This commit is contained in:
Glenn Randers-Pehrson
2006-08-19 13:59:24 -05:00
parent 3424ee7354
commit beb572e616
90 changed files with 2151 additions and 2040 deletions

105
pngmem.c
View File

@@ -1,7 +1,7 @@
/* pngmem.c - stub functions for memory allocation
*
* Last changed in libpng 1.4.0 April 20, 2006
* Last changed in libpng 1.4.0 July 13, 2006
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -15,7 +15,7 @@
*/
#include "png.h"
#include "pngintrn.h"
#include "pngpriv.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
@@ -29,7 +29,7 @@ png_voidp /* PRIVATE */
png_create_struct(int type)
{
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
return (png_create_struct_2(type, NULL, NULL));
}
/* Alternate version of png_create_struct, for use with user-defined malloc. */
@@ -41,9 +41,9 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
png_voidp struct_ptr;
if (type == PNG_STRUCT_INFO)
size = png_sizeof(png_info);
size = sizeof(png_info);
else if (type == PNG_STRUCT_PNG)
size = png_sizeof(png_struct);
size = sizeof(png_struct);
else
return (png_get_copyright(NULL));
@@ -53,7 +53,7 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
struct_ptr = (*(malloc_fn))(png_ptr, size);
}
else
#endif /* PNG_USER_MEM_SUPPORTED */
@@ -68,7 +68,7 @@ void /* PRIVATE */
png_destroy_struct(png_voidp struct_ptr)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
png_destroy_struct_2(struct_ptr, NULL, NULL);
}
/* Free memory allocated by a png_create_struct() call */
@@ -114,7 +114,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
*/
png_voidp PNGAPI
png_malloc(png_structp png_ptr, png_uint_32 size)
png_malloc(png_structp png_ptr, png_alloc_size_t size)
{
png_voidp ret;
@@ -123,22 +123,22 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
#ifdef PNG_USER_MEM_SUPPORTED
if(png_ptr->malloc_fn != NULL)
ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
ret = (*(png_ptr->malloc_fn))(png_ptr, size);
else
ret = (png_malloc_default(png_ptr, size));
ret = png_malloc_default(png_ptr, size);
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out of memory!");
return (ret);
}
png_voidp PNGAPI
png_malloc_default(png_structp png_ptr, png_uint_32 size)
png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
{
png_voidp ret;
#endif /* PNG_USER_MEM_SUPPORTED */
#ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
if (size > (png_alloc_size_t)65536L)
{
png_warning(png_ptr, "Cannot Allocate > 64K");
ret = NULL;
@@ -146,9 +146,12 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
else
#endif
#if !defined(INT_MAX) || (INT_MAX <= 0x7ffffffeL)
if (size != (size_t)size)
ret = NULL;
else if (size == (png_uint_32)65536L)
ret = NULL;
else
#endif
if (size == (png_alloc_size_t)65536L)
{
if (png_ptr->offset_table == NULL)
{
@@ -185,9 +188,9 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
{
#ifndef PNG_USER_MEM_SUPPORTED
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
png_error(png_ptr, "Out Of Memory"); /* Note "O" and "M" */
else
png_warning(png_ptr, "Out Of Memory.");
png_warning(png_ptr, "Out Of Memory");
#endif
return (NULL);
}
@@ -207,15 +210,15 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
png_ptr->offset_table = table;
png_ptr->offset_table_ptr = farmalloc(num_blocks *
png_sizeof (png_bytep));
sizeof(png_bytep));
if (png_ptr->offset_table_ptr == NULL)
{
#ifndef PNG_USER_MEM_SUPPORTED
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
png_error(png_ptr, "Out Of memory"); /* Note "O" and "M" */
else
png_warning(png_ptr, "Out Of memory.");
png_warning(png_ptr, "Out Of memory");
#endif
return (NULL);
}
@@ -242,9 +245,9 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
{
#ifndef PNG_USER_MEM_SUPPORTED
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
png_error(png_ptr, "Out of Memory"); /* Note "o" and "M" */
else
png_warning(png_ptr, "Out of Memory.");
png_warning(png_ptr, "Out of Memory");
#endif
return (NULL);
}
@@ -258,9 +261,9 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
if (ret == NULL)
{
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
png_error(png_ptr, "Out of memory"); /* Note "o" and "m" */
else
png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
png_warning(png_ptr, "Out of memory"); /* Note "o" and "m" */
}
#endif
@@ -327,7 +330,7 @@ png_voidp /* PRIVATE */
png_create_struct(int type)
{
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
return (png_create_struct_2(type, NULL, NULL));
}
/* Allocate memory for a png_struct or a png_info. The malloc and
@@ -341,14 +344,14 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
png_voidp struct_ptr;
if (type == PNG_STRUCT_INFO)
size = png_sizeof(png_info);
size = sizeof(png_info);
else if (type == PNG_STRUCT_PNG)
size = png_sizeof(png_struct);
size = sizeof(png_struct);
else
return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if(malloc_fn != NULL)
if (malloc_fn != NULL)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
@@ -373,7 +376,7 @@ void /* PRIVATE */
png_destroy_struct(png_voidp struct_ptr)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
png_destroy_struct_2(struct_ptr, NULL, NULL);
}
/* Free memory allocated by a png_create_struct() call */
@@ -405,7 +408,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
have the ability to do that. */
png_voidp PNGAPI
png_malloc(png_structp png_ptr, png_uint_32 size)
png_malloc(png_structp png_ptr, png_alloc_size_t size)
{
png_voidp ret;
@@ -413,17 +416,17 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
if (png_ptr == NULL || size == 0)
return (NULL);
if(png_ptr->malloc_fn != NULL)
ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
if (png_ptr->malloc_fn != NULL)
ret = (*(png_ptr->malloc_fn))(png_ptr, size);
else
ret = (png_malloc_default(png_ptr, size));
ret = png_malloc_default(png_ptr, size);
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out of Memory!");
return (ret);
}
png_voidp PNGAPI
png_malloc_default(png_structp png_ptr, png_uint_32 size)
png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
{
png_voidp ret;
#endif /* PNG_USER_MEM_SUPPORTED */
@@ -432,7 +435,7 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
return (NULL);
#ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
if (size > (png_alloc_size_t)65536L)
{
#ifndef PNG_USER_MEM_SUPPORTED
if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
@@ -443,10 +446,6 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
}
#endif
/* Check for overflow */
if (size != (png_mem_size_t)size)
ret = NULL;
else
ret = png_mem_alloc(size);
#ifndef PNG_USER_MEM_SUPPORTED
@@ -491,7 +490,7 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
* memory.
*/
png_voidp PNGAPI
png_malloc_warn(png_structp png_ptr, png_uint_32 size)
png_malloc_warn(png_structp png_ptr, png_alloc_size_t size)
{
png_voidp ptr;
png_uint_32 save_flags=png_ptr->flags;
@@ -502,33 +501,6 @@ png_malloc_warn(png_structp png_ptr, png_uint_32 size)
return(ptr);
}
png_voidp PNGAPI
png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
png_uint_32 length)
{
png_size_t size;
size = (png_size_t)length;
if ((png_uint_32)size != length)
png_error(png_ptr,"Overflow in png_memcpy_check.");
return(png_memcpy (s1, s2, size));
}
png_voidp PNGAPI
png_memset_check (png_structp png_ptr, png_voidp s1, int value,
png_uint_32 length)
{
png_size_t size;
size = (png_size_t)length;
if ((png_uint_32)size != length)
png_error(png_ptr,"Overflow in png_memset_check.");
return (png_memset (s1, value, size));
}
#ifdef PNG_USER_MEM_SUPPORTED
/* This function is called when the application wants to use another method
* of allocating and freeing memory.
@@ -552,4 +524,5 @@ png_get_mem_ptr(png_structp png_ptr)
return ((png_voidp)png_ptr->mem_ptr);
}
#endif /* PNG_USER_MEM_SUPPORTED */
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */