We make heavy use of sanitizers and memory checkers to catch memory related issues that are inherent to the C++ programming language as early as possible.
One example is uninitialized reads. They come in many forms, but one of them is
0int foo;
1if (!Parse("-1", foo)) return
2std::cout << foo << std::endl; // Can be uninitialized read, depending on implementation of Parse
Sometimes programmers initialize foo
to a constant like 0
or -1
, but such practice is defeating the whole purpose of memory sanitizers. That is, for a memory sanitizer it is now impossible to detect an uninitialized read.
However, I suspect that no one is running with sanitizers enabled in production and it would be nice to not expose production systems to undefined behaviour. So I was wondering if anyone would object compiling and shipping the release binaries with -ftrivial-auto-var-init=zero
?