3 ms·
Valgrind 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
by klodolph 9y ago
Valgrind 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.