-fsanitize=undefined
It would have caught this bug at run-time.I will say that the article isn't a fantastic example, but at the same time it isn't too far off a more common idiom that is also UB as it is usually expressed - type punning. And type punning almost always works, except when it doesn't - http://blog.qt.io/blog/2011/06/10/type-punning-and-strict-al...
[1] In particular, most programmers think pointers are simply numbers that represent memory addresses and that the chief distinguishing thing about null pointers is that accesses through them usually cause a memory page error owing to how the OS has mapped memory.
CppCon 2015, Herb Sutter's talk about writing safe code in C++14, just check how many in the audience use such tools.
https://www.youtube.com/watch?v=hEx5DNLWGgA&feature=youtu.be...
A tiny 1%, this on the conference of with many of the top C++ developers.
Now imagine how little they get used on the typical enterprise environment, specially worse with C, that lacks many of the C++ added safety layers.