aboutsummaryrefslogtreecommitdiff
path: root/malloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'malloc.c')
-rw-r--r--malloc.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/malloc.c b/malloc.c
index 7e5b87e..39bcfac 100644
--- a/malloc.c
+++ b/malloc.c
@@ -2,6 +2,9 @@
* malloc.c: safe wrappers around malloc, realloc, free, strdup
*/
+#ifndef NO_STDINT_H
+#include <stdint.h>
+#endif
#include <stdlib.h>
#include <string.h>
#include "puzzles.h"
@@ -12,6 +15,10 @@
*/
void *smalloc(size_t size) {
void *p;
+#ifdef PTRDIFF_MAX
+ if (size > PTRDIFF_MAX)
+ fatal("allocation too large");
+#endif
p = malloc(size);
if (!p)
fatal("out of memory");
@@ -32,6 +39,10 @@ void sfree(void *p) {
*/
void *srealloc(void *p, size_t size) {
void *q;
+#ifdef PTRDIFF_MAX
+ if (size > PTRDIFF_MAX)
+ fatal("allocation too large");
+#endif
if (p) {
q = realloc(p, size);
} else {