Closed sjkisner closed 2 years ago
Hey Jordan, just to make sure that I understand this correctly. Before this fix, we would observe that random amount of memory gets allocated on M1 machines because the randomness in va_arg. Are we supposed to see compiler errors or visual differences in reconstructed images as well?
Correct, about the random amount of memory.
If the va_arg problem happens, 99% chance the program would crash before getting any output. It's pretty ugly. You may not see any compiler errors or warnings related to this. At least I never have.
This historical multialloc() rears it's head!!!
After 30+ years, critical failure now observed on macOS/arm64 (M1), both with homebrew/gcc-11.3 and clang-13.1.
The issue is with variable arguments usage, va_arg (stdarg.h).
produces indeterminate behavior because the va_arg argument was typed to size_t.
The values returned by va_arg were random, the problem being something like filling 4 bytes of an 8 byte register, and not clearing the remaining bytes.
Applied the minimum necessary fix in commit 32965f0,
But in general multialloc() needs to be used cautiously. For example, recast the variable arguments to 'int' when necessary.