3 ms·
I don't see how this particular case could ever be hard to deal with. Using uninitialized memory is UB, so initialize every byte of memory allocated to NULL. D
by dale_glass 3y ago
I don't see how this particular case could ever be hard to deal with.
Using uninitialized memory is UB, so initialize every byte of memory allocated to NULL. Dereference NULL pointers as-is. Done.
I'd be quite happy with a best effort approach. If you can't be perfect in every case, at least handle the low handling fruit.
- layer8 3y agoThis approach would also impact UB-free code that initializes the memory later. C compilers don’t want to pessimize such code. The difficulty lies in identifying only code with actual UB.
- dale_glass 3y agoThat's perfectly fine with me. If the compiler can prove the code is initialized twice, then it's free to deduplicate it. Otherwise I'll happily eat the cost and preserve more of my sanity when debugging.
- layer8 3y agoYou’ll happily eat the cost, but the target audience of C compilers traditionally doesn’t. That’s the point made by TFA. C prioritizes performance over safety.