diff options
author | Elliott Hughes <enh@google.com> | 2018-09-18 12:52:42 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2018-09-26 14:24:18 -0700 |
commit | b177085ce7219562eecf77f2e8de49f8f2605005 (patch) | |
tree | 573947a27714273f7d78e9c6f85c9fd30e63dba9 /linker/linker_memory.cpp | |
parent | e4e3de819d05481422f8bb9925486118924bf4a1 (diff) |
Add reallocarray(3).
Originally a BSD extension, now in glibc too. We've used it internally
for a while.
(cherry-pick of e4b13f7e3ca68edfcc5faedc5e7d4e13c4e8edb9.)
Bug: http://b/112163459
Test: ran tests
Change-Id: I813c3a62b13ddb91ba41e32a5a853d09207ea6bc
Merged-In: I813c3a62b13ddb91ba41e32a5a853d09207ea6bc
Diffstat (limited to 'linker/linker_memory.cpp')
-rw-r--r-- | linker/linker_memory.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/linker/linker_memory.cpp b/linker/linker_memory.cpp index 6a54c138f..f2cce01d9 100644 --- a/linker/linker_memory.cpp +++ b/linker/linker_memory.cpp @@ -80,7 +80,15 @@ void* realloc(void* p, size_t byte_count) { return get_allocator().realloc(p, byte_count); } +void* reallocarray(void* p, size_t item_count, size_t item_size) { + size_t byte_count; + if (__builtin_mul_overflow(item_count, item_size, &byte_count)) { + errno = ENOMEM; + return nullptr; + } + return get_allocator().realloc(p, byte_count); +} + void free(void* ptr) { get_allocator().free(ptr); } - |