For small alignments (less than four), realloc copied too many bytes
from the previous reallocation when growing a struct. This was caused
by the allocator storing the requested size aligned to the next 4 bytes,
and using that to decide how many bytes to copy to the new location.
This patch fixes this by removing the aligment 4 bytes for the requested
allocation size. The consensus was that this alignment is not necessary,
and conflicts/is redundant with other alignments based on the type size.
Here is a simplified version of the code that lead to the error:
/* Any type smaller than four bytes will cause a problem. */ int8_t *data = (int8_t *)MEM_calloc_arrayN(54, sizeof(int8_t), __func__); memset(data, 0, sizeof(int8_t) * 54); data = (int8_t* )MEM_recallocN(data, sizeof(int8_t) * 72); for (int i = 0; i < 72; i++) { BLI_assert(data[i] == 0); }
The change is co-authored by Jacques Lucke.