diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-07-13 16:23:31 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-07-13 16:23:31 -0400 |
commit | 563a22c512e81a24c2dcc9562ca668b1162c94bd (patch) | |
tree | 418d16d7ec6bbd4fcd4eb454ec9bc12fadce2fe0 /src | |
parent | b4c3201ccceb9c73dd7751d7f9937b4afe78966f (diff) | |
download | bfs-563a22c512e81a24c2dcc9562ca668b1162c94bd.tar.xz |
alloc: Use a different error code for size overflows
This should help debuggability, and also squelches a GCC warning.
Diffstat (limited to 'src')
-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); } |