This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -Warray-bounds issue
- From: Diego Novillo <dnovillo at google dot com>
- To: Matt Hargett <matt at use dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 23 Jul 2007 14:54:58 -0400
- Subject: Re: -Warray-bounds issue
- References: <200707231144.57063.matt@use.net>
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.