Sanitizing your code
Today’s compilers are often more than just programs to convert text to binary code. They are complex software suites that have built-in functionality to ensure code quality. The focus on how much compilers are aware of code quality issues has drastically increased, especially with the advent of LLVM and Clang. These quality tools are commonly called sanitizers and are enabled by passing certain flags to the compiler and linker.
Code sanitizers are a way to bring additional quality checks into code by using the compiler to decorate the binary code with annotations and hooks, detecting various runtime issues. When the code is executed, the annotations are checked and confirmed if any violations are reported. Sanitizers are relatively fast, but they obviously have an impact on the runtime behavior of any program. If the sanitizers catch anything, programs are terminated with abort()
and return with non-zero. This is particularly useful with testing because...