diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-11-02 11:48:08 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-11-02 11:54:42 -0500 |
commit | ded33cb2c73151e2f02a8a1d520b54e4f1c14072 (patch) | |
tree | b1ed5aa41e851830d442a861e2dac30159ad1c0b /src/common | |
parent | 0d8abf5365cc39e7ea91bddfeb207e8d4d233544 (diff) | |
download | tor-ded33cb2c73151e2f02a8a1d520b54e4f1c14072.tar.gz tor-ded33cb2c73151e2f02a8a1d520b54e4f1c14072.zip |
Use the | trick to save a comparison in our calloc check.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/common/util.c b/src/common/util.c index 006fd804b1..3d81f2b530 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -206,8 +206,15 @@ tor_malloc_zero_(size_t size DMALLOC_PARAMS) static INLINE int size_mul_check(const size_t x, const size_t y) { - return ((x < SQRT_SIZE_MAX_P1 && y < SQRT_SIZE_MAX_P1) || - y == 0 || x <= SIZE_MAX / y); + /* This first check is equivalent to + (x < SQRT_SIZE_MAX_P1 && y < SQRT_SIZE_MAX_P1) + + Rationale: if either one of x or y is >= SQRT_SIZE_MAX_P1, then it + will have some bit set in its most significant half. + */ + return ((x|y) < SQRT_SIZE_MAX_P1 || + y == 0 || + x <= SIZE_MAX / y); } /** Allocate a chunk of <b>nmemb</b>*<b>size</b> bytes of memory, fill |