Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@pwhelan
Copy link
Contributor

@pwhelan pwhelan commented Apr 3, 2024

This code will fail, at the very least when using ASAn:

    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)));
    }
    else {
        array->entries[position] = NULL;

This is because you will inevitably be copying over the remaining values on top of the value being removed.

This fix just replaces memcpy for memmove which allows for src and dst to overlap.

@edsiper edsiper merged commit c86d8f3 into master Apr 8, 2024
@edsiper edsiper deleted the pwhelan-cfl-array-fix-mem-overlap-remove-by-index branch April 8, 2024 00:10
@edsiper
Copy link
Member

edsiper commented Apr 8, 2024

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants