Skip to content

Commit 73f7c03

Browse files
With Capacity Zero (#143)
* ensure reserving zero capacity dynamic container is well defined * ensure adding 0 with reserve is well defined and returns argument error
1 parent 0b6a151 commit 73f7c03

File tree

5 files changed

+5
-13
lines changed

5 files changed

+5
-13
lines changed

ccc/private/private_buffer.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ struct CCC_Buffer
4646
void *context;
4747
};
4848

49-
/** @internal */
50-
#define CCC_private_buf_non_CCC_private_buf_default_size(...) __VA_ARGS__
51-
/** @internal */
52-
#define CCC_private_buf_default_size(...) 0
53-
/** @internal */
54-
#define CCC_private_buf_optional_size(...) \
55-
__VA_OPT__(CCC_private_buf_non_)##CCC_private_buf_default_size(__VA_ARGS__)
56-
5749
/** @internal Initializes the Buffer with a default size of 0. However the user
5850
can specify that the Buffer has some count of elements from index
5951
`[0, capacity - 1)` at initialization time. The Buffer assumes these elements
@@ -175,4 +167,4 @@ of memory in one step. */
175167

176168
/* NOLINTEND(readability-identifier-naming) */
177169

178-
#endif /* CCC_PRIVATE_BUF_H */
170+
#endif /* CCC_PRIVATE_BUFFER_H */

source/bitset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ CCC_Result
10291029
CCC_bitset_reserve(CCC_Bitset *const bitset, size_t const to_add,
10301030
CCC_Allocator *const allocate)
10311031
{
1032-
if (!bitset || !allocate)
1032+
if (!bitset || !allocate || !to_add)
10331033
{
10341034
return CCC_RESULT_ARGUMENT_ERROR;
10351035
}

source/buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ CCC_Result
6060
CCC_buffer_reserve(CCC_Buffer *const buffer, size_t const to_add,
6161
CCC_Allocator *const allocate)
6262
{
63-
if (!buffer || !allocate)
63+
if (!buffer || !allocate || !to_add)
6464
{
6565
return CCC_RESULT_ARGUMENT_ERROR;
6666
}

source/flat_double_ended_queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ CCC_flat_double_ended_queue_reserve(CCC_Flat_double_ended_queue *const queue,
360360
size_t const to_add,
361361
CCC_Allocator *const allocate)
362362
{
363-
if (!queue || !allocate)
363+
if (!queue || !allocate || !to_add)
364364
{
365365
return CCC_RESULT_ARGUMENT_ERROR;
366366
}

source/flat_hash_map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ CCC_Result
877877
CCC_flat_hash_map_reserve(CCC_Flat_hash_map *const map, size_t const to_add,
878878
CCC_Allocator *const allocate)
879879
{
880-
if (unlikely(!map || !to_add || !allocate))
880+
if (unlikely(!map || !to_add || !allocate || !to_add))
881881
{
882882
return CCC_RESULT_ARGUMENT_ERROR;
883883
}

0 commit comments

Comments
 (0)