1. 7
  1. 3

    Since the article (written in 2010) didn’t call it out: another great tool is the Clang Undefined Behavior Sanitizer. It instruments the code with runtime checks for many types of undefined behavior, and will either log about them or optionally stop with a breakpoint. It has saved me from nasty bugs many times. Nowadays I always enable it in debug builds of anything I write.

    (One of my favorite things is to combine it with Clang’s nullability type modifiers (_Nullable, etc.) Then UBSan will insert null checks on values that are supposed to be non-null, catching null-pointer bugs early.)

    I haven’t tried it, but there is a limited version of UBSan that has minimal impact on performance and can be used in optimized/production code in cases where you can afford to trade some speed for safety.

    Stories with similar links:

    1. A Guide to Undefined Behavior in C and C++, Part 1 – Embedded in Academia via bowyakka 4 years ago | 6 points | no comments