views:

131

answers:

2

Having tried this

int main(void) {

int a[10]; a[20]=5;

}

gcc -Wall -O2 main.c

It gives me no warning...

It's gcc within windows (mingw) and I am not able to detect this kind of boundary limit bug

how to tell compiler to check it? can mingw do it?

thanks

+2  A: 

There are attempts to deal with array bounds checking. By default, the santdard C99 says nothing about enforcing array bounds, I believe largely because it has more overhead.

That being said you can look at sites like this where people have tried to deal with it:

http://williambader.com/bounds/example.html

jim mcnamara
Good this project http://sourceforge.net/projects/boundschecking/ have "patches" for gcc, to add -fbounds-checking flag, I think they are only for linux, but it's a start..
Hernán Eche
A: 

There are other non-compiler tools that can use static analysis to find errors like array boundary violations. A previous SO question discusses some of them. Mind you, if you're needing to run in a mingw environment that may limit your choices.

torak