On Wed, 02 Nov 2011 00:32:44 +0000, Tom Hughes wrote: 

> On
01/11/11 22:33, Peter Toft wrote:
> 
>> Try to find the errors in this
C/C++ snippet using valgrind: #include /* Save as code.c */ int
main(void) { int i=-1,a[2],b[2],c[2]; a[0] = 1; a[1] = 2; b[0] = 3; b[1]
= 4; c[0] = 5; c[1] = 6; printf("%i %in",b[i],a[i]); return 0; } Compile
using "gcc -o bla code.c -Wall" and check the code using "valgrind
./bla". Valgrind finds nothing even though I index a[-1] and b[-1] - not
good...
> That's because you're using the wrong tool. You're using the
default memcheck tool, which will tell you about any use of
uninitialised data, but because you are dealing with stack variables you
have no gaps between your variables (with heap memory valgrind would
ensure there was a gap) so an out of bounds access is likely to just
access an adjacent (and defined) variable. This should all be explained
in the manual, which you probably want to read to understand what
memcheck will and won't find. The tool that might find this problem is
exp-ptrcheck (in the released version) or exp-sgcheck (in the svn code).
That specifically looks for out of bounds access to stack variables by
using the debug information to discover the bounds. Tom

He he - I knew
perfectly well, that I could not find this problem with the memcheck
tool, but wanted your input on how to cope with those problems.


Actually in the future I would wish that memcheck could be extended so
it could catch it - even if it would cost compile-time changes.


Valgrind is a great tool, but its user-value would increase quite a
bit, if it could catch a bit more (e.g. like my example). 

Would it
possible to make this? 

I will check exp-sgcheck in a sec - thanx Tom!


Best 

/pto 

-- 
Peter Toft, PhD
http://petertoft.dk
  
------------------------------------------------------------------------------
RSA® Conference 2012
Save $700 by Nov 18
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to