Hello,
why don't you tyr with BugFighter from www.bugfighter-soft.com ?
It is compiler and plattform indipendent.
You can find error on single an multidimensional arrays, for example:
int x[10];
int y[10][10][10];
int ii;
...
ii = 10;
x[ii] = 9;
y[0][ii][0] = 7;
It works also on arrays inside structs:
typedef struct ex_s {
int x[10];
int y[10][10][10];
} EX;
...
EX sEX;
ii = 10;
sEX.x[ii] = 9;
sEX.y[0][ii][0] = 7;
VALGRIND
Valgrind doesn't do it, see:
http://valgrind.org/docs/manual/faq.html
5.2. Why doesn't Memcheck find the array overruns in this program?
int static[5];
int main(void)
{
int stack[5];
static[5] = 0;
stack [5] = 0;
return 0;
}
Unfortunately, Memcheck doesn't do bounds checking on static or stack arrays. We'd like to, but it's just not possible to do in a reasonable way that fits with how Memcheck works. Sorry.
PURIFY
Also Purify doesn't check static memory, it only works on intere structure, see:
http://
system.nada.kth.se/unix/software/rational/purify/html/ht_how_p_finds_memacc_errs.htm
How Purify checks statically allocated memory
In addition to detecting access errors in dynamic memory, Purify detects references beyond the boundaries of data in global variables and static variables, that is, data allocated statically at link-time as opposed to dynamically at run time.
Here is an example of data that is handled by the static checking feature:
int array[10];
main() {
array[11] = 1;
}
In this example, Purify reports an array bounds write (ABW) error at the assignment to array[11] because it is 4 bytes beyond the end of the array.
Purify inserts red guard zones around each variable in your program's static-data area. If the program attempts to read from or write to one of these guard zones, Purify reports an array bounds error (ABR or ABW).
Purify inserts guard zones into the data section only if all data references are to known data variables. If Purify finds a data reference that is relative to the start of the data section as opposed to a known data variable, Purify is unable to determine which variable the reference involves. In this case, Purify inserts guard zones at the beginning and end of the data section only, not between data variables.
Purify provides several command line static checking options and directives to aid in maximizing the benefits of static checking.
Notes:
*
Purify does not detect array bounds errors between individual local (stack) variables. On Solaris, Purify inserts guard zones between stack frames, causing stack array bounds read (SBR) and stack array bounds write (SBW) errors on accesses that extend beyond all the local variables in a function. Purify detects accesses beyond the end of the stack (BSR and BSW errors) on all platforms, as well as UMR errors on all stack variables.
*
Due to the flexibility of manipulating pointers in C and C++ programs, a pointer can accidentally access a legally allocated block of memory that is in fact beyond the block that you are attempting to access. In this case, Purify does not signal illegal memory access errors because the memory is properly allocated and initialized. Purify monitors memory accesses and the blocks of memory accessed, not pointer arithmetic. You can use the -static-checking-guardzone option to adjust the size of red zones to find these types of errors.
*
Purify detects array bounds errors in arrays within C structures only when the access extends beyond the entire structure.
Best Regards