travisvroman / kohi

A game engine made as part of the Kohi Game Engine series on YouTube (and Twitch!), where we make a game engine from the ground up using C and Vulkan.
https://kohiengine.com
Apache License 2.0
1.04k stars 99 forks source link

[BUG] Moves wrong length in darray_pop_at. #238

Open NoRines opened 2 months ago

NoRines commented 2 months ago

When popping from a darray by index there is an issue when moving the data.

    // If not on the last element, snip out the entry and copy the rest inward.
    if (index != length - 1) {
        kcopy_memory(
            (void*)(addr + (index * stride)),
            (void*)(addr + ((index + 1) * stride)),
            stride * (length - (index - 1)));
    }

The size of stride * (length - (index - 1)) will be too large, the correct value should be stride * (length - (index + 1)). This has the potential to lead to memory corruption if not fixed.

dmitry-skliar commented 1 month ago

I agree, I also tested this part once, corrected it, and then forgot to write it.