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

Side by Side Diff: third_party/libwebp/utils/utils.c

Issue 2584033003: libwebp-0.5.2-rc2 (Closed)
Patch Set: layout tests Created 3 years, 12 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 // Copyright 2012 Google Inc. All Rights Reserved. 1 // Copyright 2012 Google Inc. All Rights Reserved.
2 // 2 //
3 // Use of this source code is governed by a BSD-style license 3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source 4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found 5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may 6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree. 7 // be found in the AUTHORS file in the root of the source tree.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 // 9 //
10 // Misc. common utility functions 10 // Misc. common utility functions
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 const uint64_t total_size = nmemb * size; 168 const uint64_t total_size = nmemb * size;
169 if (nmemb == 0) return 1; 169 if (nmemb == 0) return 1;
170 if ((uint64_t)size > WEBP_MAX_ALLOCABLE_MEMORY / nmemb) return 0; 170 if ((uint64_t)size > WEBP_MAX_ALLOCABLE_MEMORY / nmemb) return 0;
171 if (total_size != (size_t)total_size) return 0; 171 if (total_size != (size_t)total_size) return 0;
172 #if defined(PRINT_MEM_INFO) && defined(MALLOC_FAIL_AT) 172 #if defined(PRINT_MEM_INFO) && defined(MALLOC_FAIL_AT)
173 if (countdown_to_fail > 0 && --countdown_to_fail == 0) { 173 if (countdown_to_fail > 0 && --countdown_to_fail == 0) {
174 return 0; // fake fail! 174 return 0; // fake fail!
175 } 175 }
176 #endif 176 #endif
177 #if defined(MALLOC_LIMIT) 177 #if defined(MALLOC_LIMIT)
178 if (mem_limit > 0 && total_mem + total_size >= mem_limit) { 178 if (mem_limit > 0) {
179 return 0; // fake fail! 179 const uint64_t new_total_mem = (uint64_t)total_mem + total_size;
180 if (new_total_mem != (size_t)new_total_mem ||
181 new_total_mem > mem_limit) {
182 return 0; // fake fail!
183 }
180 } 184 }
181 #endif 185 #endif
182 186
183 return 1; 187 return 1;
184 } 188 }
185 189
186 void* WebPSafeMalloc(uint64_t nmemb, size_t size) { 190 void* WebPSafeMalloc(uint64_t nmemb, size_t size) {
187 void* ptr; 191 void* ptr;
188 Increment(&num_malloc_calls); 192 Increment(&num_malloc_calls);
189 if (!CheckSizeArgumentsOverflow(nmemb, size)) return NULL; 193 if (!CheckSizeArgumentsOverflow(nmemb, size)) return NULL;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 300 }
297 } 301 }
298 return num_colors; 302 return num_colors;
299 } 303 }
300 304
301 #undef MAX_COLOR_COUNT 305 #undef MAX_COLOR_COUNT
302 #undef COLOR_HASH_SIZE 306 #undef COLOR_HASH_SIZE
303 #undef COLOR_HASH_RIGHT_SHIFT 307 #undef COLOR_HASH_RIGHT_SHIFT
304 308
305 //------------------------------------------------------------------------------ 309 //------------------------------------------------------------------------------
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698