I'm not sure msan would catch any error here. If I understand it correctly, msan can only catch uninitialized memory when a branch is involved. I played a bit with this sample code which loops over uninitialized memory and prints a result:
#include <iostream>
struct Foo {
unsigned char bytebuf[1024 * 1024];
};
int main() {
Foo f; // uninitialized
uint64_t x = 0;
for (size_t i = 0; i < 1024 * 1024; ++i) {
// if (f.bytebuf[i]) {
x += f.bytebuf[i];
//}
}
std::cout << x << std::endl;
}
I compiled with clang++ -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls test.cpp && ./a.out.
- Without the
if, clang's memory sanitizer does not detect any uninitialized memory and prints a random number. Even when compiling with -O0.
- With the
if commented in, clang only detect an uninitialized memory error when compiled with -O0.
So I think msan can't really catch much here