diff options
author | Edward Thomson <ethomson@microsoft.com> | 2015-02-11 09:39:38 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-02-12 22:54:47 -0500 |
commit | 2884cc42de8b20a58cec8488d014a853d47c047e (patch) | |
tree | 19dbb80072107fe65c7dd1de5dd849cc6914b154 /src/util.h | |
parent | 4aa664ae3953d99c2ae4cd769f02818bc122eebc (diff) | |
download | libgit2-2884cc42de8b20a58cec8488d014a853d47c047e.tar.gz |
overflow checking: don't make callers set oom
Have the ALLOC_OVERFLOW testing macros also simply set_oom in the
case where a computation would overflow, so that callers don't
need to.
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/util.h b/src/util.h index 7693ef809..40e06976d 100644 --- a/src/util.h +++ b/src/util.h @@ -64,10 +64,8 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n) length = p_strnlen(str, n); - if (GIT_ALLOC_OVERFLOW_ADD(length, 1)) { - giterr_set_oom(); + if (GIT_ALLOC_OVERFLOW_ADD(length, 1)) return NULL; - } ptr = git__malloc(length + 1); @@ -87,10 +85,8 @@ GIT_INLINE(char *) git__substrdup(const char *start, size_t n) { char *ptr; - if (GIT_ALLOC_OVERFLOW_ADD(n, 1) || !(ptr = git__malloc(n+1))) { - giterr_set_oom(); + if (GIT_ALLOC_OVERFLOW_ADD(n, 1) || !(ptr = git__malloc(n+1))) return NULL; - } memcpy(ptr, start, n); ptr[n] = '\0'; @@ -111,11 +107,8 @@ GIT_INLINE(void *) git__realloc(void *ptr, size_t size) */ GIT_INLINE(void *) git__reallocarray(void *ptr, size_t nelem, size_t elsize) { - void *new_ptr = NULL; - if (GIT_ALLOC_OVERFLOW_MULTIPLY(nelem, elsize) || - !(new_ptr = realloc(ptr, nelem * elsize))) - giterr_set_oom(); - return new_ptr; + return GIT_ALLOC_OVERFLOW_MULTIPLY(nelem, elsize) ? + NULL : realloc(ptr, nelem * elsize); } /** |