4 ms·
It might be easier to detect a zero value. It might be easier to debug. People used to use hard-coded, human-visible values for debugging for that reason.
by nickpsecurity 1y ago
It might be easier to detect a zero value. It might be easier to debug. People used to use hard-coded, human-visible values for debugging for that reason.
- Tuna-Fish 1y agoSure, and I'm not against belt-and-suspenders here. It's just that "all values are defined to be zero-initialized, and you can use them as such" is a horrible decision. It means that you cannot even get best effort warnings for lack of initialization, because as far as the compiler knows you might have meant to use the zero value.
- fc417fc802 1y agoI suspect it's even worse than UB. At least in that case a sanitizer can prevent optimizations and detect the later usage. If default zero initialization is guaranteed then as you say you lose any chance of an automated system detecting the programmer error.
- fc417fc802 1y agoThat's what sanitizers are for. Why would you do that manually given the tooling that's freely available? When I make a logic error the absolute ideal situation is that the compiler rejects the program. The higher the frequency of that result the better.
- nickpsecurity 1y ago"What I want is a compiler that slaps me when I forget to initialize a proper value, not one that quietly picks a magic value it thinks I might have meant." I believed the claim was about whether a compiler would initialize memory to zero. Whatever I said would be done by the compiler.
- fc417fc802 1y agoI don't see how. In the presence of default initialization the compiler cannot diagnose these things, more or less by definition. Therefore you will be falling back on debugging. UB plus a memory access sanitizer automates the practice that you described.