aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/emalloc.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-05-13 20:35:26 +0200
committerMattias Andrée <maandree@kth.se>2017-05-13 20:35:26 +0200
commitf69ec5134ffc1fc27764ca70d10be92517ec4498 (patch)
treece6aa54fd5d43dc32e88ba3afaa204ea8a7f24cb /src/util/emalloc.h
parentAdd man pages for blind-{to,from}-portable and make -s the default (and invert it's meaning) (diff)
downloadblind-f69ec5134ffc1fc27764ca70d10be92517ec4498.tar.gz
blind-f69ec5134ffc1fc27764ca70d10be92517ec4498.tar.bz2
blind-f69ec5134ffc1fc27764ca70d10be92517ec4498.tar.xz
Add blind-make-kernel
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/util/emalloc.h')
-rw-r--r--src/util/emalloc.h17
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;
+}