diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2014-10-25 13:45:05 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-10-25 13:45:05 -0400 |
commit | d51b1d3cb936c8390a34ed87d81303efbb7df533 (patch) | |
tree | 92df64b74d6eb98203fba5173ba0d0a21e29bcde /src/shared/util.h | |
parent | 1b6c7e7255cf5d03d049f63dfdea24f6f64328d1 (diff) |
src/shared/util.h: import realloc_multiply() from upstream
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared/util.h')
-rw-r--r-- | src/shared/util.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/shared/util.h b/src/shared/util.h index 60ea971dc3..805cf29920 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -341,6 +341,13 @@ _malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) return malloc(a * b); } +_alloc_(2, 3) static inline void *realloc_multiply(void *p, size_t a, size_t b) { + if (_unlikely_(b != 0 && a > ((size_t) -1) / b)) + return NULL; + + return realloc(p, a * b); +} + /** * Check if a string contains any glob patterns. */ |