6 ms·
If you have ub then you have a bug and there is some system that will show it. It isn't hard to write code without ub.
by bluGill 2y ago
If you have ub then you have a bug and there is some system that will show it. It isn't hard to write code without ub.
- bigstrat2003 2y agoIt is, in fact, pretty hard as evidenced by how often programmers fail at it. The macho attitude of "it's not hard, just write good code" is divorced from observable reality.
- bluGill 2y agoPeople write buffer overflows because and memory leaks they are not coreful. The rest of ub are things I have never seen despite running sanitizers and a large codebase.
- tbrownaw 2y agoStaying under the speed limit is, in fact, pretty hard as evidenced by how often drivers fail at it.
- kevingadd 2y agoIt's more complex than that for the example of car speed limits. Depending on where you live, the law also says that driving too slow is illegal because it creates an unsafe environment by forcing other drivers on i.e. the freeway to pass you. But yeah, seeing how virtually everyone on every road is constantly speeding, that doesn't give me a lot of faith in my fellow programmers' ability to avoid UB...
- deathanatos 2y agoSome jurisdictions also set the speed limit at, e.g., the 85th percentile of drivers' speed (https://en.wikipedia.org/wiki/Speed_limit#Method https://en.wikipedia.org/wiki/Speed_limit#Method) so some drivers are always going to be speeding. (I'm one of those speeders, too; I drive with a mentality of safety > following the strict letter of the law; I'll prefer speed of traffic if that's safer than strict adherence to the limit. That said, I know not all of my peers have the same priorities on the road, too.)
- account42 2y agoAnd to be specific, some kinds of UB are painfully easy to avoid. A good example of that is strict aliasing. Simply don't do any type punning. Yet people still complain about it being the compiler's fault when their wanton casting leads to problems.
- pjmlp 2y agoOnly if developers act as grown ups and use all static analysers they can get hold of, instead of acting as they know better. The tone of my answer is a reflection of what most surveys state, related to the actual use of such tooling.
- epcoa 2y agoDo you know what UBSAN is? Have you used it?
- bluGill 2y agoyes, my ci system runs it with a comprehensive test suite.