|
From: Milian W. <ma...@mi...> - 2013-04-11 19:36:48
Attachments:
signature.asc
|
Hey there,
a friend of mine is starting C++ and asked me this apparently simple question:
Why does the following program not show me an error?
~~~~~~~
#include <iostream>
using namespace std;
int main () {
int billy[2];
billy[4] = 42;
cout << billy[4] << endl;
return 0;
}
~~~~~~~
My first reaction was of course to fire up valgrind and wanted to show him how
memcheck helps in finding such errors. But apparently memcheck does _not_ find
this error? How come? Is this a bug or a limitation that cannot be overcome?
I'm running:
64Bit intel core i3
gcc (GCC) 4.8.0
valgrind-3.8.1
Compiled the above with g++ -g -O0 -Wall
Is it b/c this is referencing a non-existing stack space? If I change the code
to read
int* billy = new int[2];
Valgrind can find the error...
Cheers
--
Milian Wolff
ma...@mi...
http://milianw.de |
|
From: Paul F. <pa...@fr...> - 2013-04-11 20:20:09
|
On 11 Apr 2013, at 21:20, Milian Wolff wrote: > Hey there, > > a friend of mine is starting C++ and asked me this apparently simple question: > > Why does the following program not show me an error? Hi memcheck is a heap checker, not a stack checker. Try --tool=exp-sgcheck (where sg is stack and global) A+ Paul |