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

Side by Side Diff: src/base/ftutil.c

Issue 89753003: Update freetype to latest version of ASOP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src/third_party/freetype.git@master
Patch Set: Created 7 years 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
« no previous file with comments | « src/base/fttype1.c ('k') | src/base/ftwinfnt.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /***************************************************************************/ 1 /***************************************************************************/
2 /* */ 2 /* */
3 /* ftutil.c */ 3 /* ftutil.c */
4 /* */ 4 /* */
5 /* FreeType utility file for memory and list management (body). */ 5 /* FreeType utility file for memory and list management (body). */
6 /* */ 6 /* */
7 /* Copyright 2002, 2004, 2005, 2006, 2007 by */ 7 /* Copyright 2002, 2004-2007, 2013 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */ 9 /* */
10 /* This file is part of the FreeType project, and may only be used, */ 10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */ 11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */ 13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */ 14 /* understand and accept it fully. */
15 /* */ 15 /* */
16 /***************************************************************************/ 16 /***************************************************************************/
17 17
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 FT_Error *p_error ) 68 FT_Error *p_error )
69 { 69 {
70 FT_Error error = FT_Err_Ok; 70 FT_Error error = FT_Err_Ok;
71 FT_Pointer block = NULL; 71 FT_Pointer block = NULL;
72 72
73 73
74 if ( size > 0 ) 74 if ( size > 0 )
75 { 75 {
76 block = memory->alloc( memory, size ); 76 block = memory->alloc( memory, size );
77 if ( block == NULL ) 77 if ( block == NULL )
78 error = FT_Err_Out_Of_Memory; 78 error = FT_THROW( Out_Of_Memory );
79 } 79 }
80 else if ( size < 0 ) 80 else if ( size < 0 )
81 { 81 {
82 /* may help catch/prevent security issues */ 82 /* may help catch/prevent security issues */
83 error = FT_Err_Invalid_Argument; 83 error = FT_THROW( Invalid_Argument );
84 } 84 }
85 85
86 *p_error = error; 86 *p_error = error;
87 return block; 87 return block;
88 } 88 }
89 89
90 90
91 FT_BASE_DEF( FT_Pointer ) 91 FT_BASE_DEF( FT_Pointer )
92 ft_mem_realloc( FT_Memory memory, 92 ft_mem_realloc( FT_Memory memory,
93 FT_Long item_size, 93 FT_Long item_size,
94 FT_Long cur_count, 94 FT_Long cur_count,
95 FT_Long new_count, 95 FT_Long new_count,
96 void* block, 96 void* block,
97 FT_Error *p_error ) 97 FT_Error *p_error )
98 { 98 {
99 FT_Error error = FT_Err_Ok; 99 FT_Error error = FT_Err_Ok;
100 100
101
101 block = ft_mem_qrealloc( memory, item_size, 102 block = ft_mem_qrealloc( memory, item_size,
102 cur_count, new_count, block, &error ); 103 cur_count, new_count, block, &error );
103 if ( !error && new_count > cur_count ) 104 if ( !error && new_count > cur_count )
104 FT_MEM_ZERO( (char*)block + cur_count * item_size, 105 FT_MEM_ZERO( (char*)block + cur_count * item_size,
105 ( new_count - cur_count ) * item_size ); 106 ( new_count - cur_count ) * item_size );
106 107
107 *p_error = error; 108 *p_error = error;
108 return block; 109 return block;
109 } 110 }
110 111
111 112
112 FT_BASE_DEF( FT_Pointer ) 113 FT_BASE_DEF( FT_Pointer )
113 ft_mem_qrealloc( FT_Memory memory, 114 ft_mem_qrealloc( FT_Memory memory,
114 FT_Long item_size, 115 FT_Long item_size,
115 FT_Long cur_count, 116 FT_Long cur_count,
116 FT_Long new_count, 117 FT_Long new_count,
117 void* block, 118 void* block,
118 FT_Error *p_error ) 119 FT_Error *p_error )
119 { 120 {
120 FT_Error error = FT_Err_Ok; 121 FT_Error error = FT_Err_Ok;
121 122
122 123
123 /* Note that we now accept `item_size == 0' as a valid parameter, in 124 /* Note that we now accept `item_size == 0' as a valid parameter, in
124 * order to cover very weird cases where an ALLOC_MULT macro would be 125 * order to cover very weird cases where an ALLOC_MULT macro would be
125 * called. 126 * called.
126 */ 127 */
127 if ( cur_count < 0 || new_count < 0 || item_size < 0 ) 128 if ( cur_count < 0 || new_count < 0 || item_size < 0 )
128 { 129 {
129 /* may help catch/prevent nasty security issues */ 130 /* may help catch/prevent nasty security issues */
130 error = FT_Err_Invalid_Argument; 131 error = FT_THROW( Invalid_Argument );
131 } 132 }
132 else if ( new_count == 0 || item_size == 0 ) 133 else if ( new_count == 0 || item_size == 0 )
133 { 134 {
134 ft_mem_free( memory, block ); 135 ft_mem_free( memory, block );
135 block = NULL; 136 block = NULL;
136 } 137 }
137 else if ( new_count > FT_INT_MAX/item_size ) 138 else if ( new_count > FT_INT_MAX/item_size )
138 { 139 {
139 error = FT_Err_Array_Too_Large; 140 error = FT_THROW( Array_Too_Large );
140 } 141 }
141 else if ( cur_count == 0 ) 142 else if ( cur_count == 0 )
142 { 143 {
143 FT_ASSERT( block == NULL ); 144 FT_ASSERT( block == NULL );
144 145
145 block = ft_mem_alloc( memory, new_count*item_size, &error ); 146 block = ft_mem_alloc( memory, new_count*item_size, &error );
146 } 147 }
147 else 148 else
148 { 149 {
149 FT_Pointer block2; 150 FT_Pointer block2;
150 FT_Long cur_size = cur_count*item_size; 151 FT_Long cur_size = cur_count*item_size;
151 FT_Long new_size = new_count*item_size; 152 FT_Long new_size = new_count*item_size;
152 153
153 154
154 block2 = memory->realloc( memory, cur_size, new_size, block ); 155 block2 = memory->realloc( memory, cur_size, new_size, block );
155 if ( block2 == NULL ) 156 if ( block2 == NULL )
156 error = FT_Err_Out_Of_Memory; 157 error = FT_THROW( Out_Of_Memory );
157 else 158 else
158 block = block2; 159 block = block2;
159 } 160 }
160 161
161 *p_error = error; 162 *p_error = error;
162 return block; 163 return block;
163 } 164 }
164 165
165 166
166 FT_BASE_DEF( void ) 167 FT_BASE_DEF( void )
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 value2 = value & (value - 1); /* clear lowest bit */ 426 value2 = value & (value - 1); /* clear lowest bit */
426 if ( value2 == 0 ) 427 if ( value2 == 0 )
427 break; 428 break;
428 429
429 value = value2; 430 value = value2;
430 } 431 }
431 return value; 432 return value;
432 } 433 }
433 434
434 435
435 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
436
437 FT_BASE_DEF( FT_Error )
438 FT_Alloc( FT_Memory memory,
439 FT_Long size,
440 void* *P )
441 {
442 FT_Error error;
443
444
445 (void)FT_ALLOC( *P, size );
446 return error;
447 }
448
449
450 FT_BASE_DEF( FT_Error )
451 FT_QAlloc( FT_Memory memory,
452 FT_Long size,
453 void* *p )
454 {
455 FT_Error error;
456
457
458 (void)FT_QALLOC( *p, size );
459 return error;
460 }
461
462
463 FT_BASE_DEF( FT_Error )
464 FT_Realloc( FT_Memory memory,
465 FT_Long current,
466 FT_Long size,
467 void* *P )
468 {
469 FT_Error error;
470
471
472 (void)FT_REALLOC( *P, current, size );
473 return error;
474 }
475
476
477 FT_BASE_DEF( FT_Error )
478 FT_QRealloc( FT_Memory memory,
479 FT_Long current,
480 FT_Long size,
481 void* *p )
482 {
483 FT_Error error;
484
485
486 (void)FT_QREALLOC( *p, current, size );
487 return error;
488 }
489
490
491 FT_BASE_DEF( void )
492 FT_Free( FT_Memory memory,
493 void* *P )
494 {
495 if ( *P )
496 FT_MEM_FREE( *P );
497 }
498
499 #endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
500
501 /* END */ 436 /* END */
OLDNEW
« no previous file with comments | « src/base/fttype1.c ('k') | src/base/ftwinfnt.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698