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

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

Issue 10832153: libwebp: update snapshot to v0.2.0-rc1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2012 Google Inc. All Rights Reserved.
2 //
3 // This code is licensed under the same terms as WebM:
4 // Software License Agreement: http://www.webmproject.org/license/software/
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/
6 // -----------------------------------------------------------------------------
7 //
8 // Misc. common utility functions
9 //
10 // Author: Skal (pascal.massimino@gmail.com)
11
12 #include <stdlib.h>
13 #include "./utils.h"
14
15 #if defined(__cplusplus) || defined(c_plusplus)
16 extern "C" {
17 #endif
18
19 //------------------------------------------------------------------------------
20 // Checked memory allocation
21
22 static int CheckSizeArguments(uint64_t nmemb, size_t size) {
23 const uint64_t total_size = nmemb * size;
24 if (nmemb == 0) return 1;
25 if ((uint64_t)size > WEBP_MAX_ALLOCABLE_MEMORY / nmemb) return 0;
26 if (total_size != (size_t)total_size) return 0;
27 return 1;
28 }
29
30 void* WebPSafeMalloc(uint64_t nmemb, size_t size) {
31 if (!CheckSizeArguments(nmemb, size)) return NULL;
32 return malloc((size_t)(nmemb * size));
33 }
34
35 void* WebPSafeCalloc(uint64_t nmemb, size_t size) {
36 if (!CheckSizeArguments(nmemb, size)) return NULL;
37 return calloc((size_t)nmemb, size);
38 }
39
40 //------------------------------------------------------------------------------
41
42 #if defined(__cplusplus) || defined(c_plusplus)
43 } // extern "C"
44 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698