[BUG] darray_push and darray_insert_at create UB when called on array named "temp"
beewyka819 opened this issue · 1 comments
Describe the bug
When using a darray named "temp", darray_push and darray_insert_at cause UB as the "temp" variable within the macro overrides the darray, resulting in the incorrect memory address being passed to the functions as the array. This causes the memory copies to write to invalid addresses as well as similar problems with the darray_length_set and potential darray_expand calls.
To Reproduce
Steps to reproduce the behavior:
- Create a darray named "temp"
- Call darray_insert_at and/or darray_push
Expected behavior
"temp" is a reasonable name to expect for darray variables. It should not be a special edge case. This should work as any other darray name does.
Fix proposal
A simple way to fix this is to just make the temp variable in the macro. Perhaps something like _darray_insert_at_temp_value
and _darray_push_temp_value
respectively. Either that or obfuscate them as nonsense names, but that's less readable.
Relevant Lines
kohi/engine/src/containers/darray.h
Line 124 in 873e3a9
kohi/engine/src/containers/darray.h
Line 148 in 873e3a9
Maybe replace temp
with _temp ## __LINE__
.