summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--alloc.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/alloc.c b/alloc.c
index 48a109b..11fe431 100644
--- a/alloc.c
+++ b/alloc.c
@@ -1,3 +1,4 @@
1#include <limits.h>
1#include "alloc.h" 2#include "alloc.h"
2#include "error.h" 3#include "error.h"
3#include <stdlib.h> 4#include <stdlib.h>
@@ -14,6 +15,10 @@ static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */
14unsigned int n; 15unsigned int n;
15{ 16{
16 char *x; 17 char *x;
18 if (n >= (INT_MAX >> 3)) {
19 errno = error_nomem;
20 return 0;
21 }
17 n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */ 22 n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */
18 if (n <= avail) { avail -= n; return space + avail; } 23 if (n <= avail) { avail -= n; return space + avail; }
19 x = malloc(n); 24 x = malloc(n);