OLD | NEW |
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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 #if defined(PRINT_MEM_TRAFFIC) | 148 #if defined(PRINT_MEM_TRAFFIC) |
149 fprintf(stderr, "Mem: %u (-%u)\n", | 149 fprintf(stderr, "Mem: %u (-%u)\n", |
150 (uint32_t)total_mem, (uint32_t)block->size_); | 150 (uint32_t)total_mem, (uint32_t)block->size_); |
151 #endif | 151 #endif |
152 free(block); | 152 free(block); |
153 } | 153 } |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 #else | 157 #else |
158 #define Increment(v) do {} while(0) | 158 #define Increment(v) do {} while (0) |
159 #define AddMem(p, s) do {} while(0) | 159 #define AddMem(p, s) do {} while (0) |
160 #define SubMem(p) do {} while(0) | 160 #define SubMem(p) do {} while (0) |
161 #endif | 161 #endif |
162 | 162 |
163 // Returns 0 in case of overflow of nmemb * size. | 163 // Returns 0 in case of overflow of nmemb * size. |
164 static int CheckSizeArgumentsOverflow(uint64_t nmemb, size_t size) { | 164 static int CheckSizeArgumentsOverflow(uint64_t nmemb, size_t size) { |
165 const uint64_t total_size = nmemb * size; | 165 const uint64_t total_size = nmemb * size; |
166 if (nmemb == 0) return 1; | 166 if (nmemb == 0) return 1; |
167 if ((uint64_t)size > WEBP_MAX_ALLOCABLE_MEMORY / nmemb) return 0; | 167 if ((uint64_t)size > WEBP_MAX_ALLOCABLE_MEMORY / nmemb) return 0; |
168 if (total_size != (size_t)total_size) return 0; | 168 if (total_size != (size_t)total_size) return 0; |
169 #if defined(PRINT_MEM_INFO) && defined(MALLOC_FAIL_AT) | 169 #if defined(PRINT_MEM_INFO) && defined(MALLOC_FAIL_AT) |
170 if (countdown_to_fail > 0 && --countdown_to_fail == 0) { | 170 if (countdown_to_fail > 0 && --countdown_to_fail == 0) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 202 |
203 void WebPSafeFree(void* const ptr) { | 203 void WebPSafeFree(void* const ptr) { |
204 if (ptr != NULL) { | 204 if (ptr != NULL) { |
205 Increment(&num_free_calls); | 205 Increment(&num_free_calls); |
206 SubMem(ptr); | 206 SubMem(ptr); |
207 } | 207 } |
208 free(ptr); | 208 free(ptr); |
209 } | 209 } |
210 | 210 |
211 //------------------------------------------------------------------------------ | 211 //------------------------------------------------------------------------------ |
OLD | NEW |