diff options
Diffstat (limited to '')
| -rw-r--r-- | src/util/emalloc.h | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/util/emalloc.h b/src/util/emalloc.h index f4a7f12..214a773 100644 --- a/src/util/emalloc.h +++ b/src/util/emalloc.h @@ -7,9 +7,11 @@ #define ecalloc(...) encalloc(1, __VA_ARGS__) #define erealloc(...) enrealloc(1, __VA_ARGS__) #define erealloc2(...) enrealloc2(1, __VA_ARGS__) +#define erealloc3(...) enrealloc3(1, __VA_ARGS__) -#define malloc2(n, m) malloc(n * m); -#define realloc3(p, n, m) realloc(p, n * m); +#define malloc2(n, m) malloc(n * m); +#define realloc2(p, n, m) realloc(p, n * m); +#define realloc3(p, n1, n2, n3) realloc(p, n1 * n2 * n3); static inline void * enmalloc(int status, size_t n) @@ -54,3 +56,14 @@ enrealloc2(int status, void *ptr, size_t n, size_t m) enprintf(status, "realloc: out of memory\n"); return ptr; } + +static inline void * +enrealloc3(int status, void *ptr, size_t n1, size_t n2, size_t n3) +{ + size_t n = n1; + if (n2 > SIZE_MAX / n || + n3 > SIZE_MAX / (n *= n2) || + !(ptr = realloc(ptr, n * n3))) + enprintf(status, "realloc: out of memory\n"); + return ptr; +} |
