blob: ad53ae08822abfad6b66c5ca71bbe5cd4f9f3ca0 [file] [log] [blame]
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001
Guy Schalnat0f716451995-11-28 11:22:13 -06002/* pngmem.c - stub functions for memory allocation
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06003 *
Glenn Randers-Pehrson glennrp@comcast.net11a3c7b2009-05-15 20:33:24 -05004 * Last changed in libpng 1.4.0 [May 15, 2009]
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06005 * For conditions of distribution and use, see copyright notice in png.h
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -06006 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -05007 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06009 *
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -050010 * This file provides a location for all memory allocation. Users who
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -050011 * need special memory handling are expected to supply replacement
12 * functions for png_malloc() and png_free(), and to use
13 * png_create_read_struct_2() and png_create_write_struct_2() to
14 * identify the replacement functions.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060015 */
Guy Schalnat0d580581995-07-20 02:43:20 -050016
Guy Schalnat0d580581995-07-20 02:43:20 -050017#include "png.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060018#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050019#include "pngpriv.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060020
Guy Schalnat4ee97b01996-01-16 01:51:56 -060021/* Borland DOS special memory handler */
22#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
23/* if you change this, be sure to change the one in png.h also */
24
Guy Schalnate5a37791996-06-05 15:50:50 -050025/* Allocate memory for a png_struct. The malloc and memset can be replaced
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060026 by a single call to calloc() if this is thought to improve performance. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050027png_voidp /* PRIVATE */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060028png_create_struct(int type)
Guy Schalnate5a37791996-06-05 15:50:50 -050029{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050030#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050031 return (png_create_struct_2(type, NULL, NULL));
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050032}
33
34/* Alternate version of png_create_struct, for use with user-defined malloc. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050035png_voidp /* PRIVATE */
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -050036png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050037{
38#endif /* PNG_USER_MEM_SUPPORTED */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060039 png_size_t size;
Guy Schalnate5a37791996-06-05 15:50:50 -050040 png_voidp struct_ptr;
41
42 if (type == PNG_STRUCT_INFO)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050043 size = png_sizeof(png_info);
Guy Schalnate5a37791996-06-05 15:50:50 -050044 else if (type == PNG_STRUCT_PNG)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050045 size = png_sizeof(png_struct);
Guy Schalnate5a37791996-06-05 15:50:50 -050046 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050047 return (png_get_copyright(NULL));
Guy Schalnate5a37791996-06-05 15:50:50 -050048
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050049#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050050 if (malloc_fn != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050051 {
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -050052 png_struct dummy_struct;
53 png_structp png_ptr = &dummy_struct;
54 png_ptr->mem_ptr=mem_ptr;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050055 struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050056 }
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -050057 else
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050058#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050059 struct_ptr = (png_voidp)farmalloc(size);
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -050060 if (struct_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -050061 png_memset(struct_ptr, 0, size);
Guy Schalnate5a37791996-06-05 15:50:50 -050062 return (struct_ptr);
63}
64
Guy Schalnate5a37791996-06-05 15:50:50 -050065/* Free memory allocated by a png_create_struct() call */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050066void /* PRIVATE */
Guy Schalnate5a37791996-06-05 15:50:50 -050067png_destroy_struct(png_voidp struct_ptr)
68{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050069#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050070 png_destroy_struct_2(struct_ptr, NULL, NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050071}
72
73/* Free memory allocated by a png_create_struct() call */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050074void /* PRIVATE */
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -050075png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
76 png_voidp mem_ptr)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050077{
78#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -050079 if (struct_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060080 {
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050081#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050082 if (free_fn != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050083 {
84 png_struct dummy_struct;
85 png_structp png_ptr = &dummy_struct;
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -050086 png_ptr->mem_ptr=mem_ptr;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050087 (*(free_fn))(png_ptr, struct_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050088 return;
89 }
90#endif /* PNG_USER_MEM_SUPPORTED */
Guy Schalnate5a37791996-06-05 15:50:50 -050091 farfree (struct_ptr);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060092 }
Guy Schalnate5a37791996-06-05 15:50:50 -050093}
94
Guy Schalnat0d580581995-07-20 02:43:20 -050095/* Allocate memory. For reasonable files, size should never exceed
Andreas Dilger47a0c421997-05-16 02:46:07 -050096 * 64K. However, zlib may allocate more then 64K if you don't tell
97 * it not to. See zconf.h and png.h for more information. zlib does
98 * need to allocate exactly 64K, so whatever you call here must
99 * have the ability to do that.
100 *
101 * Borland seems to have a problem in DOS mode for exactly 64K.
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500102 * It gives you a segment with an offset of 8 (perhaps to store its
Andreas Dilger47a0c421997-05-16 02:46:07 -0500103 * memory stuff). zlib doesn't like this at all, so we have to
104 * detect and deal with it. This code should not be needed in
105 * Windows or OS/2 modes, and only in 16 bit mode. This code has
106 * been updated by Alexander Lehmann for version 0.89 to waste less
107 * memory.
108 *
109 * Note that we can't use png_size_t for the "size" declaration,
110 * since on some systems a png_size_t is a 16-bit quantity, and as a
111 * result, we would be truncating potentially larger memory requests
112 * (which should cause a fatal error) and introducing major problems.
113 */
Glenn Randers-Pehrson0ffb71a2009-02-28 06:08:20 -0600114#ifdef PNG_CALLOC_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500115png_voidp PNGAPI
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -0600116png_calloc(png_structp png_ptr, png_alloc_size_t size)
117{
118 png_voidp ret;
119
120 ret = (png_malloc(png_ptr, size));
121 if (ret != NULL)
122 png_memset(ret,0,(png_size_t)size);
123 return (ret);
124}
Glenn Randers-Pehrson0ffb71a2009-02-28 06:08:20 -0600125#endif
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -0600126
127png_voidp PNGAPI
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500128png_malloc(png_structp png_ptr, png_alloc_size_t size)
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600129{
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600130 png_voidp ret;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500131
Andreas Dilger47a0c421997-05-16 02:46:07 -0500132 if (png_ptr == NULL || size == 0)
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500133 return (NULL);
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600134
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500135#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500136 if (png_ptr->malloc_fn != NULL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500137 ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500138 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500139 ret = (png_malloc_default(png_ptr, size));
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500140 if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500141 png_error(png_ptr, "Out of memory");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500142 return (ret);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500143}
144
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500145png_voidp PNGAPI
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500146png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500147{
148 png_voidp ret;
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600149#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500150
Glenn Randers-Pehrson6b12c082006-11-14 10:53:30 -0600151 if (png_ptr == NULL || size == 0)
152 return (NULL);
153
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600154#ifdef PNG_MAX_MALLOC_64K
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500155 if (size > (png_uint_32)65536L)
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500156 {
157 png_warning(png_ptr, "Cannot Allocate > 64K");
158 ret = NULL;
159 }
160 else
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600161#endif
162
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500163 if (size != (size_t)size)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500164 ret = NULL;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500165 else if (size == (png_uint_32)65536L)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600166 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500167 if (png_ptr->offset_table == NULL)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600168 {
169 /* try to see if we need to do any of this fancy stuff */
170 ret = farmalloc(size);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500171 if (ret == NULL || ((png_size_t)ret & 0xffff))
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600172 {
173 int num_blocks;
174 png_uint_32 total_size;
175 png_bytep table;
176 int i;
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600177 png_byte huge * hptr;
178
Andreas Dilger47a0c421997-05-16 02:46:07 -0500179 if (ret != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600180 {
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600181 farfree(ret);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600182 ret = NULL;
183 }
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600184
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500185 if (png_ptr->zlib_window_bits > 14)
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500186 num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
187 else
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600188 num_blocks = 1;
189 if (png_ptr->zlib_mem_level >= 7)
190 num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
191 else
192 num_blocks++;
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600193
Guy Schalnate5a37791996-06-05 15:50:50 -0500194 total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600195
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600196 table = farmalloc(total_size);
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600197
Andreas Dilger47a0c421997-05-16 02:46:07 -0500198 if (table == NULL)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600199 {
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500200#ifndef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500201 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500202 png_error(png_ptr, "Out Of Memory"); /* Note "O" and "M" */
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600203 else
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500204 png_warning(png_ptr, "Out Of Memory");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500205#endif
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600206 return (NULL);
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600207 }
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600208
Andreas Dilger47a0c421997-05-16 02:46:07 -0500209 if ((png_size_t)table & 0xfff0)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600210 {
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500211#ifndef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500212 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600213 png_error(png_ptr,
214 "Farmalloc didn't return normalized pointer");
215 else
216 png_warning(png_ptr,
217 "Farmalloc didn't return normalized pointer");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500218#endif
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600219 return (NULL);
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600220 }
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600221
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600222 png_ptr->offset_table = table;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500223 png_ptr->offset_table_ptr = farmalloc(num_blocks *
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500224 png_sizeof(png_bytep));
Guy Schalnate5a37791996-06-05 15:50:50 -0500225
Andreas Dilger47a0c421997-05-16 02:46:07 -0500226 if (png_ptr->offset_table_ptr == NULL)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600227 {
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500228#ifndef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500229 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500230 png_error(png_ptr, "Out Of memory"); /* Note "O" and "M" */
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600231 else
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500232 png_warning(png_ptr, "Out Of memory");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500233#endif
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600234 return (NULL);
Guy Schalnate5a37791996-06-05 15:50:50 -0500235 }
236
237 hptr = (png_byte huge *)table;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500238 if ((png_size_t)hptr & 0xf)
Guy Schalnate5a37791996-06-05 15:50:50 -0500239 {
240 hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500241 hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600242 }
243 for (i = 0; i < num_blocks; i++)
244 {
245 png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500246 hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600247 }
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600248
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600249 png_ptr->offset_table_number = num_blocks;
250 png_ptr->offset_table_count = 0;
251 png_ptr->offset_table_count_free = 0;
252 }
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600253 }
Guy Schalnate5a37791996-06-05 15:50:50 -0500254
255 if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600256 {
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500257#ifndef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500258 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500259 png_error(png_ptr, "Out of Memory"); /* Note "o" and "M" */
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600260 else
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500261 png_warning(png_ptr, "Out of Memory");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500262#endif
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600263 return (NULL);
264 }
Guy Schalnate5a37791996-06-05 15:50:50 -0500265
266 ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600267 }
268 else
269 ret = farmalloc(size);
Guy Schalnat0d580581995-07-20 02:43:20 -0500270
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500271#ifndef PNG_USER_MEM_SUPPORTED
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500272 if (ret == NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500273 {
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500274 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500275 png_error(png_ptr, "Out of memory"); /* Note "o" and "m" */
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600276 else
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500277 png_warning(png_ptr, "Out of memory"); /* Note "o" and "m" */
Guy Schalnat0d580581995-07-20 02:43:20 -0500278 }
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500279#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500280
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600281 return (ret);
Guy Schalnat0d580581995-07-20 02:43:20 -0500282}
283
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500284/* free a pointer allocated by png_malloc(). In the default
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500285 * configuration, png_ptr is not used, but is passed in case it
286 * is needed. If ptr is NULL, return without taking any action.
287 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500288void PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500289png_free(png_structp png_ptr, png_voidp ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500290{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500291 if (png_ptr == NULL || ptr == NULL)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600292 return;
293
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500294#ifdef PNG_USER_MEM_SUPPORTED
295 if (png_ptr->free_fn != NULL)
296 {
297 (*(png_ptr->free_fn))(png_ptr, ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500298 return;
299 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500300 else
301 png_free_default(png_ptr, ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500302}
303
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500304void PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500305png_free_default(png_structp png_ptr, png_voidp ptr)
306{
307#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600308
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500309 if (png_ptr == NULL || ptr == NULL)
310 return;
Glenn Randers-Pehrson6b12c082006-11-14 10:53:30 -0600311
Andreas Dilger47a0c421997-05-16 02:46:07 -0500312 if (png_ptr->offset_table != NULL)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600313 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500314 int i;
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600315
Andreas Dilger47a0c421997-05-16 02:46:07 -0500316 for (i = 0; i < png_ptr->offset_table_count; i++)
317 {
318 if (ptr == png_ptr->offset_table_ptr[i])
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600319 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500320 ptr = NULL;
321 png_ptr->offset_table_count_free++;
322 break;
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600323 }
324 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500325 if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
326 {
327 farfree(png_ptr->offset_table);
328 farfree(png_ptr->offset_table_ptr);
329 png_ptr->offset_table = NULL;
330 png_ptr->offset_table_ptr = NULL;
331 }
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600332 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500333
334 if (ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600335 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500336 farfree(ptr);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600337 }
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600338}
339
340#else /* Not the Borland DOS special memory handler */
341
Guy Schalnate5a37791996-06-05 15:50:50 -0500342/* Allocate memory for a png_struct or a png_info. The malloc and
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600343 memset can be replaced by a single call to calloc() if this is thought
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500344 to improve performance noticably. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500345png_voidp /* PRIVATE */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600346png_create_struct(int type)
Guy Schalnate5a37791996-06-05 15:50:50 -0500347{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500348#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500349 return (png_create_struct_2(type, NULL, NULL));
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500350}
351
352/* Allocate memory for a png_struct or a png_info. The malloc and
353 memset can be replaced by a single call to calloc() if this is thought
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500354 to improve performance noticably. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500355png_voidp /* PRIVATE */
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500356png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500357{
358#endif /* PNG_USER_MEM_SUPPORTED */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500359 png_size_t size;
Guy Schalnate5a37791996-06-05 15:50:50 -0500360 png_voidp struct_ptr;
361
362 if (type == PNG_STRUCT_INFO)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500363 size = png_sizeof(png_info);
Guy Schalnate5a37791996-06-05 15:50:50 -0500364 else if (type == PNG_STRUCT_PNG)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500365 size = png_sizeof(png_struct);
Guy Schalnate5a37791996-06-05 15:50:50 -0500366 else
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500367 return (NULL);
Guy Schalnate5a37791996-06-05 15:50:50 -0500368
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500369#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500370 if (malloc_fn != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500371 {
Glenn Randers-Pehrson5cded0b2001-11-07 07:10:08 -0600372 png_struct dummy_struct;
373 png_structp png_ptr = &dummy_struct;
374 png_ptr->mem_ptr=mem_ptr;
Glenn Randers-Pehrsonae498dc2001-11-24 14:53:31 -0600375 struct_ptr = (*(malloc_fn))(png_ptr, size);
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500376 if (struct_ptr != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500377 png_memset(struct_ptr, 0, size);
378 return (struct_ptr);
379 }
380#endif /* PNG_USER_MEM_SUPPORTED */
381
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500382#if defined(__TURBOC__) && !defined(__FLAT__)
383 struct_ptr = (png_voidp)farmalloc(size);
384#else
385# if defined(_MSC_VER) && defined(MAXSEG_64K)
386 struct_ptr = (png_voidp)halloc(size, 1);
387# else
388 struct_ptr = (png_voidp)malloc(size);
389# endif
390#endif
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500391 if (struct_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -0500392 png_memset(struct_ptr, 0, size);
Guy Schalnate5a37791996-06-05 15:50:50 -0500393
394 return (struct_ptr);
395}
396
397
398/* Free memory allocated by a png_create_struct() call */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500399void /* PRIVATE */
Guy Schalnate5a37791996-06-05 15:50:50 -0500400png_destroy_struct(png_voidp struct_ptr)
401{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500402#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500403 png_destroy_struct_2(struct_ptr, NULL, NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500404}
405
406/* Free memory allocated by a png_create_struct() call */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500407void /* PRIVATE */
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500408png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
409 png_voidp mem_ptr)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500410{
411#endif /* PNG_USER_MEM_SUPPORTED */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500412 if (struct_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600413 {
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500414#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500415 if (free_fn != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500416 {
417 png_struct dummy_struct;
418 png_structp png_ptr = &dummy_struct;
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500419 png_ptr->mem_ptr=mem_ptr;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500420 (*(free_fn))(png_ptr, struct_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500421 return;
422 }
423#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500424#if defined(__TURBOC__) && !defined(__FLAT__)
425 farfree(struct_ptr);
426#else
427# if defined(_MSC_VER) && defined(MAXSEG_64K)
428 hfree(struct_ptr);
429# else
430 free(struct_ptr);
431# endif
432#endif
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600433 }
Guy Schalnate5a37791996-06-05 15:50:50 -0500434}
435
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600436/* Allocate memory. For reasonable files, size should never exceed
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500437 * 64K. However, zlib may allocate more then 64K if you don't tell
438 * it not to. See zconf.h and png.h for more information. zlib does
439 * need to allocate exactly 64K, so whatever you call here must
440 * have the ability to do that.
441 */
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600442
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500443png_voidp PNGAPI
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -0600444png_calloc(png_structp png_ptr, png_alloc_size_t size)
445{
446 png_voidp ret;
447
448 ret = (png_malloc(png_ptr, size));
449 if (ret != NULL)
450 png_memset(ret,0,(png_size_t)size);
451 return (ret);
452}
453
454png_voidp PNGAPI
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500455png_malloc(png_structp png_ptr, png_alloc_size_t size)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600456{
457 png_voidp ret;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500458
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500459#ifdef PNG_USER_MEM_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -0500460 if (png_ptr == NULL || size == 0)
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500461 return (NULL);
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600462
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500463 if (png_ptr->malloc_fn != NULL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500464 ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500465 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500466 ret = (png_malloc_default(png_ptr, size));
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500467 if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500468 png_error(png_ptr, "Out of Memory");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500469 return (ret);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500470}
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500471
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -0600472png_voidp PNGAPI
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500473png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500474{
475 png_voidp ret;
476#endif /* PNG_USER_MEM_SUPPORTED */
477
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500478 if (png_ptr == NULL || size == 0)
479 return (NULL);
480
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600481#ifdef PNG_MAX_MALLOC_64K
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500482 if (size > (png_uint_32)65536L)
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600483 {
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500484#ifndef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500485 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600486 png_error(png_ptr, "Cannot Allocate > 64K");
487 else
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500488#endif
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600489 return NULL;
490 }
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600491#endif
492
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500493 /* Check for overflow */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500494#if defined(__TURBOC__) && !defined(__FLAT__)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500495 if (size != (unsigned long)size)
496 ret = NULL;
497 else
498 ret = farmalloc(size);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500499#else
500# if defined(_MSC_VER) && defined(MAXSEG_64K)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500501 if (size != (unsigned long)size)
502 ret = NULL;
503 else
504 ret = halloc(size, 1);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500505# else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500506 if (size != (size_t)size)
507 ret = NULL;
508 else
509 ret = malloc((size_t)size);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500510# endif
511#endif
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600512
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500513#ifndef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600514 if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600515 png_error(png_ptr, "Out of Memory");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500516#endif
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600517
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600518 return (ret);
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600519}
520
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500521/* Free a pointer allocated by png_malloc(). If ptr is NULL, return
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500522 * without taking any action.
523 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500524void PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500525png_free(png_structp png_ptr, png_voidp ptr)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600526{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500527 if (png_ptr == NULL || ptr == NULL)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600528 return;
Guy Schalnat0d580581995-07-20 02:43:20 -0500529
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500530#ifdef PNG_USER_MEM_SUPPORTED
531 if (png_ptr->free_fn != NULL)
532 {
533 (*(png_ptr->free_fn))(png_ptr, ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500534 return;
535 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500536 else
537 png_free_default(png_ptr, ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500538}
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -0600539void PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500540png_free_default(png_structp png_ptr, png_voidp ptr)
541{
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500542 if (png_ptr == NULL || ptr == NULL)
543 return;
544
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500545#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500546
547#if defined(__TURBOC__) && !defined(__FLAT__)
548 farfree(ptr);
549#else
550# if defined(_MSC_VER) && defined(MAXSEG_64K)
551 hfree(ptr);
552# else
553 free(ptr);
554# endif
555#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500556}
557
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600558#endif /* Not Borland DOS special memory handler */
Guy Schalnat6d764711995-12-19 03:22:19 -0600559
Glenn Randers-Pehrson2ae022d2002-07-01 22:23:46 -0500560/* This function was added at libpng version 1.2.3. The png_malloc_warn()
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500561 * function will set up png_malloc() to issue a png_warning and return NULL
562 * instead of issuing a png_error, if it fails to allocate the requested
563 * memory.
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500564 */
565png_voidp PNGAPI
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500566png_malloc_warn(png_structp png_ptr, png_alloc_size_t size)
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500567{
568 png_voidp ptr;
Glenn Randers-Pehrsonae4bd5c2006-11-16 20:35:49 -0600569 png_uint_32 save_flags;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500570 if (png_ptr == NULL)
571 return (NULL);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500572
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500573 save_flags = png_ptr->flags;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500574 png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
575 ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
576 png_ptr->flags=save_flags;
577 return(ptr);
578}
579
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500580
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500581#ifdef PNG_USER_MEM_SUPPORTED
582/* This function is called when the application wants to use another method
583 * of allocating and freeing memory.
584 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500585void PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500586png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
587 malloc_fn, png_free_ptr free_fn)
588{
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500589 if (png_ptr != NULL)
590 {
591 png_ptr->mem_ptr = mem_ptr;
592 png_ptr->malloc_fn = malloc_fn;
593 png_ptr->free_fn = free_fn;
Glenn Randers-Pehrson6b12c082006-11-14 10:53:30 -0600594 }
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500595}
596
597/* This function returns a pointer to the mem_ptr associated with the user
598 * functions. The application should free any memory associated with this
599 * pointer before png_write_destroy and png_read_destroy are called.
600 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500601png_voidp PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500602png_get_mem_ptr(png_structp png_ptr)
603{
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500604 if (png_ptr == NULL)
605 return (NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500606 return ((png_voidp)png_ptr->mem_ptr);
607}
608#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600609#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */