summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/malloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/puzzles/src/malloc.c')
-rw-r--r--apps/plugins/puzzles/src/malloc.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/apps/plugins/puzzles/src/malloc.c b/apps/plugins/puzzles/src/malloc.c
index a7fa7c5adc..39bcfac25b 100644
--- a/apps/plugins/puzzles/src/malloc.c
+++ b/apps/plugins/puzzles/src/malloc.c
@@ -2,16 +2,23 @@
2 * malloc.c: safe wrappers around malloc, realloc, free, strdup 2 * malloc.c: safe wrappers around malloc, realloc, free, strdup
3 */ 3 */
4 4
5#ifndef NO_STDINT_H
6#include <stdint.h>
7#endif
5#include <stdlib.h> 8#include <stdlib.h>
6#include <string.h> 9#include <string.h>
7#include "puzzles.h" 10#include "puzzles.h"
8 11
9/* 12/*
10 * smalloc should guarantee to return a useful pointer - Halibut 13 * smalloc should guarantee to return a useful pointer - we
11 * can do nothing except die when it's out of memory anyway. 14 * can do nothing except die when it's out of memory anyway.
12 */ 15 */
13void *smalloc(size_t size) { 16void *smalloc(size_t size) {
14 void *p; 17 void *p;
18#ifdef PTRDIFF_MAX
19 if (size > PTRDIFF_MAX)
20 fatal("allocation too large");
21#endif
15 p = malloc(size); 22 p = malloc(size);
16 if (!p) 23 if (!p)
17 fatal("out of memory"); 24 fatal("out of memory");
@@ -32,6 +39,10 @@ void sfree(void *p) {
32 */ 39 */
33void *srealloc(void *p, size_t size) { 40void *srealloc(void *p, size_t size) {
34 void *q; 41 void *q;
42#ifdef PTRDIFF_MAX
43 if (size > PTRDIFF_MAX)
44 fatal("allocation too large");
45#endif
35 if (p) { 46 if (p) {
36 q = realloc(p, size); 47 q = realloc(p, size);
37 } else { 48 } else {