4 ms·
Valgrind will only catch such indexing errors when you read/write out of bounds when running Valgrind. There is a huge difference between out-of-bounds indexin
by danieldk 9y ago
Valgrind will only catch such indexing errors when you read/write out of bounds when running Valgrind.
There is a huge difference between out-of-bounds indexing leading to undefined behavior or an exception/panic.
- klodolph 9y agoValgrind won't catch certain indexing errors even if you exercise them. Valgrind only checks that the address is valid, not that the address was derived from a pointer to the object you are accessing. int main() { int x[16]; int y[16]; int z[16]; x[0] = 0; y[0] = 0; z[0] = 0; y[18] = 3; // Valgrind thinks this is OK. return 0; }
- jcelerier 9y agohttps://i.imgur.com/fgufyE1.png https://i.imgur.com/fgufyE1.png
- klodolph 9y agoI think you may have missed the part of the conversation where we were talking about Valgrind, specifically, and not talking about the address sanitizer.
- 2trill2spill 9y agoBut clang complains, it's not about just one tool. test.c:8:9: warning: array index 18 is past the end of the array (which contains 16 elements) [-Warray-bounds] y[18] = 3; // Valgrind thinks this is OK. ^ ~~
- klodolph 9y agoThe snippet is a demonstration of the limitations of Valgrind, specifically. It would be trivial to change the code so it has the same behavior but doesn't trigger the Clang warning.