diff options
-rw-r--r-- | src/alloc.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c index a6910ce..56d8763 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -28,6 +28,11 @@ void *alloc(size_t align, size_t size) { bfs_assert(has_single_bit(align)); bfs_assert((size & (align - 1)) == 0); + if (size >> (SIZE_WIDTH - 1)) { + errno = EOVERFLOW; + return NULL; + } + if (align <= alignof(max_align_t)) { return malloc(size); } else { @@ -39,6 +44,11 @@ void *zalloc(size_t align, size_t size) { bfs_assert(has_single_bit(align)); bfs_assert((size & (align - 1)) == 0); + if (size >> (SIZE_WIDTH - 1)) { + errno = EOVERFLOW; + return NULL; + } + if (align <= alignof(max_align_t)) { return calloc(1, size); } |