5 ms·
> The best way to prevent a divergent representation is to avoid including undefined behavior in a program. That’s not particularly actionable advice, though.
by Diggsey 4y ago
> The best way to prevent a divergent representation is to avoid including undefined behavior in a program. That’s not particularly actionable advice, though.
I mean... It is pretty actionable TBH. There are sanitizers you can use to detect UB. You could use a memory safe language. You could use a fuzzer. You could improve your test coverage. You could use static analysis tools. All of these can help reduce the chance of UB in your program.
- fulafel 4y agoI assume you know this but to clarify, it's important to distinguish between tools like fuzzers or UB sanitizers which can detect some cases when UB is triggered under heavy testing, from more sound languages which give you strong assurance against it. UB in C is a dynamic behaviour, not something that can be detected by static analysis. A lot of it is triggered for example by certain values in passed-in parameters or other implicit state consumed by functions. And flagging any potential UB that might be caused by bad inputs is would yield so many positives that it's unworkable. See eg "There is No Reliable Way to Determine if a Large Codebase Contains Undefined Behavior" section in http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html http://blog.llvm.org/2011/05/what-every-c-programmer-should-...