From 9e524b9dedeeea7f5d5e39edb80c588b161deed4 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 14 May 2017 00:23:52 +0200 Subject: Add gaussian blur and unshaping kernels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/util/emalloc.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/util') diff --git a/src/util/emalloc.h b/src/util/emalloc.h index 214a773..39efcea 100644 --- a/src/util/emalloc.h +++ b/src/util/emalloc.h @@ -4,12 +4,14 @@ #define emalloc(...) enmalloc(1, __VA_ARGS__) #define emalloc2(...) enmalloc2(1, __VA_ARGS__) +#define emalloc3(...) enmalloc3(1, __VA_ARGS__) #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 malloc3(n1, n2, n3) malloc(n1 * n2 * n3); #define realloc2(p, n, m) realloc(p, n * m); #define realloc3(p, n1, n2, n3) realloc(p, n1 * n2 * n3); @@ -31,6 +33,18 @@ enmalloc2(int status, size_t n, size_t m) return ptr; } +static inline void * +enmalloc3(int status, size_t n1, size_t n2, size_t n3) +{ + void *ptr; + size_t n = n1; + if (n2 > SIZE_MAX / n || + n3 > SIZE_MAX / (n *= n2) || + !(ptr = malloc(n * n3))) + enprintf(status, "malloc: out of memory\n"); + return ptr; +} + static inline void * encalloc(int status, size_t n, size_t m) { -- cgit v1.2.3-70-g09d2