Skip to content

Commit

Permalink
array: fix memory overlap when removing from array by index. (#42)
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Whelan <[email protected]>
  • Loading branch information
pwhelan authored Apr 8, 2024
1 parent 0a79b7c commit c86d8f3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cfl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ int cfl_array_remove_by_index(struct cfl_array *array,
cfl_variant_destroy(array->entries[position]);

if (position != array->entry_count - 1) {
memcpy(&array->entries[position],
&array->entries[position + 1],
sizeof(void *) * (array->entry_count - (position + 1)));
memmove(&array->entries[position],
&array->entries[position + 1],
sizeof(void *) * (array->entry_count - (position + 1)));
}
else {
array->entries[position] = NULL;
Expand Down

0 comments on commit c86d8f3

Please sign in to comment.