On 11/01/2011 06:33 PM, Peter Toft wrote: > Hi all > > Try to find the errors in this C/C++ snippet using valgrind: > > #include <stdio.h> > /* 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... >
Not good. But expected. Memcheck, the default valgrind tool, does not find array overruns on variables allocated on the stack. You might want to try ptrcheck: http://valgrind.org/docs/manual/pc-manual.html#pc-manual.how-works.sg-checks > Insure++ would for sure find the negative index, but GCC nor Valgrind > will get it... > It's lame that GCC does not find it. Try clang. I wouldn't be surprised, if it catches this error but I haven't tried it. Florian ------------------------------------------------------------------------------ RSA® Conference 2012 Save $700 by Nov 18 Register now! http://p.sf.net/sfu/rsa-sfdev2dev1 _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users