fix(lib): avoid possible UB of calling memset on a null ptr when 0 is passed into array_grow_by
This commit is contained in:
parent
1ff40f5571
commit
30fd71f5ac
1 changed files with 6 additions and 3 deletions
|
|
@ -66,9 +66,12 @@ extern "C" {
|
|||
/// Increase the array's size by `count` elements.
|
||||
/// New elements are zero-initialized.
|
||||
#define array_grow_by(self, count) \
|
||||
(_array__grow((Array *)(self), count, array_elem_size(self)), \
|
||||
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)), \
|
||||
(self)->size += (count))
|
||||
do { \
|
||||
if ((count) == 0) break; \
|
||||
_array__grow((Array *)(self), count, array_elem_size(self)); \
|
||||
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
|
||||
(self)->size += (count); \
|
||||
} while (0)
|
||||
|
||||
/// Append all elements from one array to the end of another.
|
||||
#define array_push_all(self, other) \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue