Olivier Galibert <galibert(a)pobox.com> writes:
On Wed, Oct 15, 2003 at 07:49:39PM +0200, Hrvoje Niksic wrote:
> How can valgrind detect that the code is faulty if it writes into
> otherwise valid regions of the stack?
By putting guard space between the stack slots.
But how can it distinguish "slots" without analyzing source code
which, as far as I know, valgrind doesn't do? It works for the heap
because valgrind intercepts calls to malloc, but there are no
comparable calls on the stack, at least there shouldn't be in
optimized code. For example:
int a;
int b;
int c[10];
int d;
int e;
How can valgrind know that writing to c[-1] is not a legitimate way to
modify b or d? It doesn't control how a/b/c/d/e are allocated on the
stack, the compiler does.