19 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
22 #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
30 #ifdef PNG_USER_MEM_SUPPORTED
42 if (
type == PNG_STRUCT_INFO)
44 else if (
type == PNG_STRUCT_PNG)
49 #ifdef PNG_USER_MEM_SUPPORTED
60 if (struct_ptr != NULL)
69 #ifdef PNG_USER_MEM_SUPPORTED
79 if (struct_ptr != NULL)
81 #ifdef PNG_USER_MEM_SUPPORTED
87 (*(
free_fn))(png_ptr, struct_ptr);
120 if (png_ptr == NULL ||
size == 0)
123 #ifdef PNG_USER_MEM_SUPPORTED
124 if (png_ptr->malloc_fn != NULL)
128 if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
139 if (png_ptr == NULL ||
size == 0)
142 #ifdef PNG_MAX_MALLOC_64K
155 if (png_ptr->offset_table == NULL)
158 ret = farmalloc(
size);
159 if (ret == NULL || ((
png_size_t)ret & 0xffff))
173 if (png_ptr->zlib_window_bits > 14)
177 if (png_ptr->zlib_mem_level >= 7)
184 table = farmalloc(total_size);
188 #ifndef PNG_USER_MEM_SUPPORTED
189 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
199 #ifndef PNG_USER_MEM_SUPPORTED
200 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
202 "Farmalloc didn't return normalized pointer");
205 "Farmalloc didn't return normalized pointer");
210 png_ptr->offset_table = table;
211 png_ptr->offset_table_ptr = farmalloc(
num_blocks *
214 if (png_ptr->offset_table_ptr == NULL)
216 #ifndef PNG_USER_MEM_SUPPORTED
217 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
228 hptr = (
png_byte huge *)((
long)(hptr) & 0xfffffff0L);
233 png_ptr->offset_table_ptr[
i] = (
png_bytep)hptr;
238 png_ptr->offset_table_count = 0;
239 png_ptr->offset_table_count_free = 0;
243 if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
245 #ifndef PNG_USER_MEM_SUPPORTED
246 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
254 ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
257 ret = farmalloc(
size);
259 #ifndef PNG_USER_MEM_SUPPORTED
262 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
279 if (png_ptr == NULL ||
ptr == NULL)
282 #ifdef PNG_USER_MEM_SUPPORTED
283 if (png_ptr->free_fn != NULL)
285 (*(png_ptr->free_fn))(png_ptr,
ptr);
296 if (png_ptr == NULL ||
ptr == NULL)
return;
298 if (png_ptr->offset_table != NULL)
302 for (
i = 0;
i < png_ptr->offset_table_count;
i++)
304 if (
ptr == png_ptr->offset_table_ptr[
i])
307 png_ptr->offset_table_count_free++;
311 if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
313 farfree(png_ptr->offset_table);
314 farfree(png_ptr->offset_table_ptr);
315 png_ptr->offset_table = NULL;
316 png_ptr->offset_table_ptr = NULL;
334 #ifdef PNG_USER_MEM_SUPPORTED
348 if (
type == PNG_STRUCT_INFO)
350 else if (
type == PNG_STRUCT_PNG)
355 #ifdef PNG_USER_MEM_SUPPORTED
362 if (struct_ptr != NULL)
368 #if defined(__TURBOC__) && !defined(__FLAT__)
371 # if defined(_MSC_VER) && defined(MAXSEG_64K)
377 if (struct_ptr != NULL)
388 #ifdef PNG_USER_MEM_SUPPORTED
398 if (struct_ptr != NULL)
400 #ifdef PNG_USER_MEM_SUPPORTED
406 (*(
free_fn))(png_ptr, struct_ptr);
410 #if defined(__TURBOC__) && !defined(__FLAT__)
413 # if defined(_MSC_VER) && defined(MAXSEG_64K)
433 #ifdef PNG_USER_MEM_SUPPORTED
434 if (png_ptr == NULL ||
size == 0)
437 if (png_ptr->malloc_fn != NULL)
441 if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
452 if (png_ptr == NULL ||
size == 0)
455 #ifdef PNG_MAX_MALLOC_64K
458 #ifndef PNG_USER_MEM_SUPPORTED
459 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
460 png_error(png_ptr,
"Cannot Allocate > 64K");
468 #if defined(__TURBOC__) && !defined(__FLAT__)
472 ret = farmalloc(
size);
474 # if defined(_MSC_VER) && defined(MAXSEG_64K)
478 ret = halloc(
size, 1);
487 #ifndef PNG_USER_MEM_SUPPORTED
488 if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
500 if (png_ptr == NULL ||
ptr == NULL)
503 #ifdef PNG_USER_MEM_SUPPORTED
504 if (png_ptr->free_fn != NULL)
506 (*(png_ptr->free_fn))(png_ptr,
ptr);
514 if (png_ptr == NULL ||
ptr == NULL)
519 #if defined(__TURBOC__) && !defined(__FLAT__)
522 # if defined(_MSC_VER) && defined(MAXSEG_64K)
532 #if defined(PNG_1_0_X)
533 # define png_malloc_warn png_malloc
545 if (png_ptr == NULL)
return (NULL);
547 save_flags = png_ptr->flags;
548 png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
550 png_ptr->flags=save_flags;
563 png_error(png_ptr,
"Overflow in png_memcpy_check.");
576 png_error(png_ptr,
"Overflow in png_memset_check.");
582 #ifdef PNG_USER_MEM_SUPPORTED
605 if (png_ptr == NULL)
return (NULL);