K
Kelsey Bjarnason
Guillaume said:Bounds checking is nice and all, but it certainly is no panacea.
It may even not be *that* useful IMO. Here is why:
1. No bounds checking. You read or write data outside bounds. It
generates an exception.
NO, in most cases writing beyond a variable's specified length doesn't
produce any exception.
Consider this program:
int fn(int *p,int c)
{
return p[c];
}
int main(void)
{
int tab[3];
int s = fn(tab,3);
}
Please tell me a compiler system where this program generates an
exception.
$gcc -fmudflap -lmudflap test.c
$./a.out
*******
mudflap violation 1 (check/read): time=1185910311.158143 ptr=0xbfe5f050 size=4
pc=0xb7e9f20d location=`test.c:3 (fn)'
/usr/lib/libmudflap.so.0(__mf_check+0x3d) [0xb7e9f20d]
./a.out(fn+0x80) [0x80487d4]
./a.out(main+0x47) [0x8048826]
Nearby object 1: checked region begins 1B after and ends 4B after
mudflap object 0x80cb110: name=`test.c:8 (main) tab'
bounds=[0xbfe5f044,0xbfe5f04f] size=12 area=stack check=0r/0w liveness=0
alloc time=1185910311.158136 pc=0xb7e9ec4d
number of nearby objects: 1
$