From 0c06925ff24b2f5c62872f26d3e882cb1d5ae7e1 Mon Sep 17 00:00:00 2001 From: Alexander Lopez Date: Sun, 4 Jan 2026 08:46:04 -0800 Subject: [PATCH 1/2] ensure reserving zero capacity dynamic container is well defined --- ccc/private/private_buffer.h | 10 +--------- source/flat_hash_map.c | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/ccc/private/private_buffer.h b/ccc/private/private_buffer.h index 9a3c429f..2fcd8fa8 100644 --- a/ccc/private/private_buffer.h +++ b/ccc/private/private_buffer.h @@ -46,14 +46,6 @@ struct CCC_Buffer void *context; }; -/** @internal */ -#define CCC_private_buf_non_CCC_private_buf_default_size(...) __VA_ARGS__ -/** @internal */ -#define CCC_private_buf_default_size(...) 0 -/** @internal */ -#define CCC_private_buf_optional_size(...) \ - __VA_OPT__(CCC_private_buf_non_)##CCC_private_buf_default_size(__VA_ARGS__) - /** @internal Initializes the Buffer with a default size of 0. However the user can specify that the Buffer has some count of elements from index `[0, capacity - 1)` at initialization time. The Buffer assumes these elements @@ -175,4 +167,4 @@ of memory in one step. */ /* NOLINTEND(readability-identifier-naming) */ -#endif /* CCC_PRIVATE_BUF_H */ +#endif /* CCC_PRIVATE_BUFFER_H */ diff --git a/source/flat_hash_map.c b/source/flat_hash_map.c index d1397ecf..c8e124cd 100644 --- a/source/flat_hash_map.c +++ b/source/flat_hash_map.c @@ -877,7 +877,7 @@ CCC_Result CCC_flat_hash_map_reserve(CCC_Flat_hash_map *const map, size_t const to_add, CCC_Allocator *const allocate) { - if (unlikely(!map || !to_add || !allocate)) + if (unlikely(!map || !to_add || !allocate || !to_add)) { return CCC_RESULT_ARGUMENT_ERROR; } From e5b8a047d554e4d136d3e9f1cce7974a30672b81 Mon Sep 17 00:00:00 2001 From: Alexander Lopez Date: Sun, 4 Jan 2026 08:49:29 -0800 Subject: [PATCH 2/2] ensure adding 0 with reserve is well defined and returns argument error --- source/bitset.c | 2 +- source/buffer.c | 2 +- source/flat_double_ended_queue.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/bitset.c b/source/bitset.c index 531263a3..75cf3fa8 100644 --- a/source/bitset.c +++ b/source/bitset.c @@ -1029,7 +1029,7 @@ CCC_Result CCC_bitset_reserve(CCC_Bitset *const bitset, size_t const to_add, CCC_Allocator *const allocate) { - if (!bitset || !allocate) + if (!bitset || !allocate || !to_add) { return CCC_RESULT_ARGUMENT_ERROR; } diff --git a/source/buffer.c b/source/buffer.c index 8eb91250..0816788c 100644 --- a/source/buffer.c +++ b/source/buffer.c @@ -60,7 +60,7 @@ CCC_Result CCC_buffer_reserve(CCC_Buffer *const buffer, size_t const to_add, CCC_Allocator *const allocate) { - if (!buffer || !allocate) + if (!buffer || !allocate || !to_add) { return CCC_RESULT_ARGUMENT_ERROR; } diff --git a/source/flat_double_ended_queue.c b/source/flat_double_ended_queue.c index 6e52c0c3..610047c3 100644 --- a/source/flat_double_ended_queue.c +++ b/source/flat_double_ended_queue.c @@ -360,7 +360,7 @@ CCC_flat_double_ended_queue_reserve(CCC_Flat_double_ended_queue *const queue, size_t const to_add, CCC_Allocator *const allocate) { - if (!queue || !allocate) + if (!queue || !allocate || !to_add) { return CCC_RESULT_ARGUMENT_ERROR; }