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

Side by Side Diff: flac/src/libFLAC/alloc.c

Issue 6122009: Add FLAC to trunk/deps/third_party/.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « flac/include/share/alloc.h ('k') | flac/src/libFLAC/bitmath.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <limits.h>
6 #if !defined _MSC_VER
7 #include <stdint.h>
8 #endif
9 #include <stdlib.h>
10 #include "share/alloc.h"
11
12 void *safe_malloc_(size_t size) {
13 return malloc(size ? size : 1);
14 }
15
16 void *safe_calloc_(size_t num_items, size_t size) {
17 if (num_items && size)
18 return calloc(num_items, size);
19 return malloc(1);
20 }
21
22 void *safe_malloc_add_2op_(size_t size1, size_t size2) {
23 size_t size = size1 + size2;
24 if (size < size1)
25 return NULL;
26
27 return safe_malloc_(size);
28 }
29
30 void *safe_malloc_mul_2op_(size_t size1, size_t size2) {
31 if (!size1 || !size2)
32 return malloc(1);
33
34 if (size1 > SIZE_MAX / size2)
35 return NULL;
36
37 return malloc(size1 * size2);
38 }
39
40 void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3) {
41 size_t size = size2 + size3;
42 if (size < size3)
43 return 0;
44
45 if (!size1 || !size)
46 return malloc(1);
47
48 return safe_malloc_mul_2op_(size1, size2);
49 }
50
51 void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2) {
52 if (!size1 || !size2)
53 return realloc(ptr, 0);
54
55 if (size1 > SIZE_MAX / size2)
56 return 0;
57
58 return realloc(ptr, size1 * size2);
59 }
OLDNEW
« no previous file with comments | « flac/include/share/alloc.h ('k') | flac/src/libFLAC/bitmath.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698