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/common.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/common.h')
| -rw-r--r-- | src/common.h | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/common.h b/src/common.h index b53798eaf..8b7d6936d 100644 --- a/src/common.h +++ b/src/common.h @@ -176,25 +176,19 @@ GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int v /** Check for integer overflow from addition or multiplication */ #define GIT_ALLOC_OVERFLOW_ADD(one, two) \ - ((one) + (two) < (one)) + (((one) + (two) < (one)) ? (giterr_set_oom(), 1) : 0) /** Check for integer overflow from multiplication */ #define GIT_ALLOC_OVERFLOW_MULTIPLY(one, two) \ - (one && ((one) * (two)) / (one) != (two)) + ((one && ((one) * (two)) / (one) != (two)) ? (giterr_set_oom(), 1) : 0) /** Check for additive overflow, failing if it would occur. */ #define GITERR_CHECK_ALLOC_ADD(one, two) \ - if (GIT_ALLOC_OVERFLOW_ADD(one, two)) { \ - giterr_set_oom(); \ - return -1; \ - } + if (GIT_ALLOC_OVERFLOW_ADD(one, two)) { return -1; } /** Check for multiplicative overflow, failing if it would occur. */ #define GITERR_CHECK_ALLOC_MULTIPLY(nelem, elsize) \ - if (GIT_ALLOC_OVERFLOW_MULTIPLY(nelem, elsize)) { \ - giterr_set_oom(); \ - return -1; \ - } + if (GIT_ALLOC_OVERFLOW_MULTIPLY(nelem, elsize)) { return -1; } /* NOTE: other giterr functions are in the public errors.h header file */ |
