diff options
| -rw-r--r-- | alloc.c | 5 |
1 files changed, 5 insertions, 0 deletions
| @@ -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 */ | |||
| 14 | unsigned int n; | 15 | unsigned 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); |
