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

Side by Side Diff: third_party/brotli/dec/safe_malloc.c

Issue 1433383003: Remove //third_party/brotli and //third_party/ots. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month 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 | « third_party/brotli/dec/safe_malloc.h ('k') | third_party/brotli/dec/streams.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /* Copyright 2013 Google Inc. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14
15 Size-checked memory allocation.
16 */
17
18 #include <stdlib.h>
19 #include "./safe_malloc.h"
20
21 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24
25 /* Returns 0 in case of overflow of nmemb * size. */
26 static int CheckSizeArgumentsOverflow(uint64_t nmemb, size_t size) {
27 const uint64_t total_size = nmemb * size;
28 if (nmemb == 0) return 1;
29 if ((uint64_t)size > BROTLI_MAX_ALLOCABLE_MEMORY / nmemb) return 0;
30 if (total_size != (size_t)total_size) return 0;
31 return 1;
32 }
33
34 void* BrotliSafeMalloc(uint64_t nmemb, size_t size) {
35 if (!CheckSizeArgumentsOverflow(nmemb, size)) return NULL;
36 assert(nmemb * size > 0);
37 return malloc((size_t)(nmemb * size));
38 }
39
40 #if defined(__cplusplus) || defined(c_plusplus)
41 } /* extern "C" */
42 #endif
OLDNEW
« no previous file with comments | « third_party/brotli/dec/safe_malloc.h ('k') | third_party/brotli/dec/streams.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698