From 563a22c512e81a24c2dcc9562ca668b1162c94bd Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 13 Jul 2023 16:23:31 -0400 Subject: alloc: Use a different error code for size overflows This should help debuggability, and also squelches a GCC warning. --- src/alloc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') 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); } -- cgit v1.2.3