Detecting Overflows, Undefined Behaviour and Other Nasties
Coming up in a future release of clang is a collection of sanitisers that insert runtime checks for the things described above. If you’re the kind of person who writes assertions like the above in your code, you can swap all that for sanitisers enabled in your debug builds. If you’re not the kind of person who writes those assertions, you probably should enable these sanitisers, then go and find out where else you should be adding assertions.
For example, -fsanitize=integer
will print a runtime error if you add two integers and the result would overflow int
.