Skip to content

Commit

Permalink
utils/dynarr: fix dynarr_resize
Browse files Browse the repository at this point in the history
It was reserving wrong number of elements. dynarr_reserve reserves on
top of existing len, not existing cap.

Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Jun 4, 2024
1 parent 5e16eed commit c2cb4df
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/utils/dynarr.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ static inline void dynarr_remove_swap_impl(size_t size, void *arr, size_t idx) {
#define dynarr_resize(arr, newlen, init, dtor) \
do { \
BUG_ON((arr) == NULL); \
if ((newlen) > dynarr_cap(arr)) { \
dynarr_reserve((arr), (newlen)-dynarr_cap(arr)); \
} \
dynarr_reserve((arr), (newlen)-dynarr_len(arr)); \
if ((init) != NULL) { \
for (size_t i = dynarr_len(arr); i < (newlen); i++) { \
(init)((arr) + i); \
Expand Down

0 comments on commit c2cb4df

Please sign in to comment.