Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: third_party/libpng/pngmem.c

Issue 1118002: libpng: update to 1.2.43 (Closed)
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* pngmem.c - stub functions for memory allocation 2 /* pngmem.c - stub functions for memory allocation
3 * 3 *
4 * Last changed in libpng 1.2.37 [June 4, 2009] 4 * Last changed in libpng 1.2.41 [February 25, 2010]
5 * For conditions of distribution and use, see copyright notice in png.h 5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9 * 8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
10 * This file provides a location for all memory allocation. Users who 13 * This file provides a location for all memory allocation. Users who
11 * need special memory handling are expected to supply replacement 14 * need special memory handling are expected to supply replacement
12 * functions for png_malloc() and png_free(), and to use 15 * functions for png_malloc() and png_free(), and to use
13 * png_create_read_struct_2() and png_create_write_struct_2() to 16 * png_create_read_struct_2() and png_create_write_struct_2() to
14 * identify the replacement functions. 17 * identify the replacement functions.
15 */ 18 */
16 19
17 #define PNG_INTERNAL 20 #define PNG_INTERNAL
21 #define PNG_NO_PEDANTIC_WARNINGS
18 #include "png.h" 22 #include "png.h"
19 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) 23 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
20 24
21 /* Borland DOS special memory handler */ 25 /* Borland DOS special memory handler */
22 #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) 26 #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
23 /* If you change this, be sure to change the one in png.h also */ 27 /* If you change this, be sure to change the one in png.h also */
24 28
25 /* Allocate memory for a png_struct. The malloc and memset can be replaced 29 /* Allocate memory for a png_struct. The malloc and memset can be replaced
26 by a single call to calloc() if this is thought to improve performance. */ 30 by a single call to calloc() if this is thought to improve performance. */
27 png_voidp /* PRIVATE */ 31 png_voidp /* PRIVATE */
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 * detect and deal with it. This code should not be needed in 108 * 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 109 * 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 110 * been updated by Alexander Lehmann for version 0.89 to waste less
107 * memory. 111 * memory.
108 * 112 *
109 * Note that we can't use png_size_t for the "size" declaration, 113 * 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 114 * 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 115 * result, we would be truncating potentially larger memory requests
112 * (which should cause a fatal error) and introducing major problems. 116 * (which should cause a fatal error) and introducing major problems.
113 */ 117 */
118 png_voidp /* PRIVATE */
119 png_calloc(png_structp png_ptr, png_uint_32 size)
120 {
121 png_voidp ret;
122
123 ret = (png_malloc(png_ptr, size));
124 if (ret != NULL)
125 png_memset(ret,0,(png_size_t)size);
126 return (ret);
127 }
114 128
115 png_voidp PNGAPI 129 png_voidp PNGAPI
116 png_malloc(png_structp png_ptr, png_uint_32 size) 130 png_malloc(png_structp png_ptr, png_uint_32 size)
117 { 131 {
118 png_voidp ret; 132 png_voidp ret;
119 133
120 if (png_ptr == NULL || size == 0) 134 if (png_ptr == NULL || size == 0)
121 return (NULL); 135 return (NULL);
122 136
123 #ifdef PNG_USER_MEM_SUPPORTED 137 #ifdef PNG_USER_MEM_SUPPORTED
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 num_blocks++; 194 num_blocks++;
181 195
182 total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16; 196 total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
183 197
184 table = farmalloc(total_size); 198 table = farmalloc(total_size);
185 199
186 if (table == NULL) 200 if (table == NULL)
187 { 201 {
188 #ifndef PNG_USER_MEM_SUPPORTED 202 #ifndef PNG_USER_MEM_SUPPORTED
189 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) 203 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
190 png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */ 204 png_error(png_ptr, "Out Of Memory."); /* Note "O", "M" */
191 else 205 else
192 png_warning(png_ptr, "Out Of Memory."); 206 png_warning(png_ptr, "Out Of Memory.");
193 #endif 207 #endif
194 return (NULL); 208 return (NULL);
195 } 209 }
196 210
197 if ((png_size_t)table & 0xfff0) 211 if ((png_size_t)table & 0xfff0)
198 { 212 {
199 #ifndef PNG_USER_MEM_SUPPORTED 213 #ifndef PNG_USER_MEM_SUPPORTED
200 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) 214 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
201 png_error(png_ptr, 215 png_error(png_ptr,
202 "Farmalloc didn't return normalized pointer"); 216 "Farmalloc didn't return normalized pointer");
203 else 217 else
204 png_warning(png_ptr, 218 png_warning(png_ptr,
205 "Farmalloc didn't return normalized pointer"); 219 "Farmalloc didn't return normalized pointer");
206 #endif 220 #endif
207 return (NULL); 221 return (NULL);
208 } 222 }
209 223
210 png_ptr->offset_table = table; 224 png_ptr->offset_table = table;
211 png_ptr->offset_table_ptr = farmalloc(num_blocks * 225 png_ptr->offset_table_ptr = farmalloc(num_blocks *
212 png_sizeof(png_bytep)); 226 png_sizeof(png_bytep));
213 227
214 if (png_ptr->offset_table_ptr == NULL) 228 if (png_ptr->offset_table_ptr == NULL)
215 { 229 {
216 #ifndef PNG_USER_MEM_SUPPORTED 230 #ifndef PNG_USER_MEM_SUPPORTED
217 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) 231 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
218 png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */ 232 png_error(png_ptr, "Out Of memory."); /* Note "O", "m" */
219 else 233 else
220 png_warning(png_ptr, "Out Of memory."); 234 png_warning(png_ptr, "Out Of memory.");
221 #endif 235 #endif
222 return (NULL); 236 return (NULL);
223 } 237 }
224 238
225 hptr = (png_byte huge *)table; 239 hptr = (png_byte huge *)table;
226 if ((png_size_t)hptr & 0xf) 240 if ((png_size_t)hptr & 0xf)
227 { 241 {
228 hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L); 242 hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 435 }
422 } 436 }
423 437
424 /* Allocate memory. For reasonable files, size should never exceed 438 /* Allocate memory. For reasonable files, size should never exceed
425 * 64K. However, zlib may allocate more then 64K if you don't tell 439 * 64K. However, zlib may allocate more then 64K if you don't tell
426 * it not to. See zconf.h and png.h for more information. zlib does 440 * it not to. See zconf.h and png.h for more information. zlib does
427 * need to allocate exactly 64K, so whatever you call here must 441 * need to allocate exactly 64K, so whatever you call here must
428 * have the ability to do that. 442 * have the ability to do that.
429 */ 443 */
430 444
445 png_voidp PNGAPI
446 png_calloc(png_structp png_ptr, png_uint_32 size)
447 {
448 png_voidp ret;
449
450 ret = (png_malloc(png_ptr, size));
451 if (ret != NULL)
452 png_memset(ret,0,(png_size_t)size);
453 return (ret);
454 }
431 455
432 png_voidp PNGAPI 456 png_voidp PNGAPI
433 png_malloc(png_structp png_ptr, png_uint_32 size) 457 png_malloc(png_structp png_ptr, png_uint_32 size)
434 { 458 {
435 png_voidp ret; 459 png_voidp ret;
436 460
437 #ifdef PNG_USER_MEM_SUPPORTED 461 #ifdef PNG_USER_MEM_SUPPORTED
438 if (png_ptr == NULL || size == 0) 462 if (png_ptr == NULL || size == 0)
439 return (NULL); 463 return (NULL);
440 464
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 # if defined(_MSC_VER) && defined(MAXSEG_64K) 552 # if defined(_MSC_VER) && defined(MAXSEG_64K)
529 hfree(ptr); 553 hfree(ptr);
530 # else 554 # else
531 free(ptr); 555 free(ptr);
532 # endif 556 # endif
533 #endif 557 #endif
534 } 558 }
535 559
536 #endif /* Not Borland DOS special memory handler */ 560 #endif /* Not Borland DOS special memory handler */
537 561
538 #if defined(PNG_1_0_X) 562 #ifdef PNG_1_0_X
539 # define png_malloc_warn png_malloc 563 # define png_malloc_warn png_malloc
540 #else 564 #else
541 /* This function was added at libpng version 1.2.3. The png_malloc_warn() 565 /* This function was added at libpng version 1.2.3. The png_malloc_warn()
542 * function will set up png_malloc() to issue a png_warning and return NULL 566 * function will set up png_malloc() to issue a png_warning and return NULL
543 * instead of issuing a png_error, if it fails to allocate the requested 567 * instead of issuing a png_error, if it fails to allocate the requested
544 * memory. 568 * memory.
545 */ 569 */
546 png_voidp PNGAPI 570 png_voidp PNGAPI
547 png_malloc_warn(png_structp png_ptr, png_uint_32 size) 571 png_malloc_warn(png_structp png_ptr, png_uint_32 size)
548 { 572 {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 */ 632 */
609 png_voidp PNGAPI 633 png_voidp PNGAPI
610 png_get_mem_ptr(png_structp png_ptr) 634 png_get_mem_ptr(png_structp png_ptr)
611 { 635 {
612 if (png_ptr == NULL) 636 if (png_ptr == NULL)
613 return (NULL); 637 return (NULL);
614 return ((png_voidp)png_ptr->mem_ptr); 638 return ((png_voidp)png_ptr->mem_ptr);
615 } 639 }
616 #endif /* PNG_USER_MEM_SUPPORTED */ 640 #endif /* PNG_USER_MEM_SUPPORTED */
617 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ 641 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698