-Warray-bounds issue

Diego Novillo dnovillo@google.com
Mon Jul 23 18:55:00 GMT 2007


On 7/23/07 2:44 PM, Matt Hargett wrote:

> #include <stdlib.h>
> 
> int main(int argc, char **argv)
> {
>         size_t size = 16;
>         char p[size];
>         p[16] = 0;
> }
> 
> 
> --
> 
> #include <stdlib.h>
> 
> int main(int argc, char **argv)
> {
>         char p[16];
>         p[16] = 0;
> }
> 
> --

In the first case, it fails because the warning does not really work
with alloca'd objects (dynamic arrays).  It could probably be made to
understand them, but it doesn't right now.  It only works on static arrays.

The second case probably fails because all that code is dead and removed
before the warning machinery has a chance to examine the code.  Try
adding something like 'return p[3];' before the end of the function.



More information about the Gcc mailing list