Ryan-rsm-McKenzie / CommonLibF4

A reverse-engineered resource for Fallout 4
MIT License
70 stars 37 forks source link

initialize BaseExtraList flags to 0 #9

Closed hxef closed 1 year ago

hxef commented 1 year ago

calloc appears to return random data instead of initializing the flag list with zeros.

This results in inconsistent behavior when modifying the extra data list. Given that methods such as HasType or MarkType check these flags to verify if an extra data type is part of the list.

Ryan-rsm-McKenzie commented 1 year ago

Thanks for the pr!

clayne commented 1 year ago

BTW: Is this the real issue? From MemoryManager.h (same thing in CommonLibSSE btw):

        [[nodiscard]] inline void* calloc(std::size_t a_num, std::size_t a_size)
        {
                return malloc(a_num * a_size);
        }
hxef commented 1 year ago

@clayne correct, I think the real fix should've been in the calloc function, something like this:

    [[nodiscard]] inline void* calloc(std::size_t a_num, std::size_t a_size)
    {
        auto ret = malloc(a_num * a_size);
        memset(ret, 0, a_num * a_size);
        return ret;
    }
hxef commented 1 year ago

@Ryan-rsm-McKenzie could you revert this PR? As per discord discussion in the fallout channel, I got a suggestion to create another one that handles it at the source of the problem, namely in the calloc() function.