summaryrefslogtreecommitdiff
path: root/src/array.h
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-02-10 23:13:49 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2015-02-12 22:54:47 -0500
commit3603cb0978b7ef21ff9cd63693ebd6d27bc2bc53 (patch)
tree20f97cffa9b4f44d3ab90bc1686a64d57223a322 /src/array.h
parent15d54fdd345dadc2854200ce5b9aad0949e3949b (diff)
downloadlibgit2-3603cb0978b7ef21ff9cd63693ebd6d27bc2bc53.tar.gz
git__*allocarray: safer realloc and malloc
Introduce git__reallocarray that checks the product of the number of elements and element size for overflow before allocation. Also introduce git__mallocarray that behaves like calloc, but without the `c`. (It does not zero memory, for those truly worried about every cycle.)
Diffstat (limited to 'src/array.h')
-rw-r--r--src/array.h3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/array.h b/src/array.h
index ca5a35ffe..0d0795370 100644
--- a/src/array.h
+++ b/src/array.h
@@ -57,8 +57,7 @@ GIT_INLINE(void *) git_array_grow(void *_a, size_t item_size)
new_size = a->size * 3 / 2;
}
- if (GIT_ALLOC_OVERFLOW_MULTIPLY(new_size, item_size) ||
- (new_array = git__realloc(a->ptr, new_size * item_size)) == NULL)
+ if ((new_array = git__reallocarray(a->ptr, new_size, item_size)) == NULL)
goto on_oom;
a->ptr = new_array; a->asize = new_size; a->size++;