On Wed, 2 Nov 2011 11:56:58 +0100, Julian Seward wrote: 

> On
Wednesday, November 02, 2011 09:31:18 am Peter Toft wrote:
> 
>>
#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; }
> 
>> I cannot see exp-sgcheck catching
anything (compiled from the SVN version) :/
> Yeah. That's because of
the limitations of how sgcheck works. Have a look at
http://www.valgrind.org/docs/manual/pc-manual.html#pc-manual.limitations
[1] and specifically at the 4th bullet point ("Stack checks: It follows
...") If you change your test program so that each memory referencing
insn iterates over an array and goes out of bounds, then it should get
spotted. But that's not the case here: each memory referencing insn (for
the various arrays) is only used once and so there's no opportunity for
the tool to infer which array each instruction is probably "supposed" to
access. (That probably won't make much sense until you read the URL
above ..) J

Naturally I can easily redo that code so valgrind catches
the bug-type I show you e.g. by declaring the arrays via pointers and
allocating those with malloc/free, however I often find code from
Joe-average-designer or random-X-program, that the code style can
contain a mix of the errors valgrind currently is good at catching and
the ones I try to high-light in this mail-thread. 

I would really like
to have an extended valgrind-workmode where the user can augment even
the compile process and/or link process, so the flow of valgrind could
also catch the mentioned kind of error. 

Best 

-- 
Peter Toft,
PhD
http://petertoft.dk
  

Links:
------
[1]
http://www.valgrind.org/docs/manual/pc-manual.html#pc-manual.limitations
------------------------------------------------------------------------------
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