summaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-07-13 16:23:31 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-07-13 16:23:31 -0400
commit563a22c512e81a24c2dcc9562ca668b1162c94bd (patch)
tree418d16d7ec6bbd4fcd4eb454ec9bc12fadce2fe0 /src/alloc.c
parentb4c3201ccceb9c73dd7751d7f9937b4afe78966f (diff)
downloadbfs-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/alloc.c')
-rw-r--r--src/alloc.c10
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);
}