[Bug c/33024] gcc allows negatively-sized arrays

2007-08-08 Thread drow at false dot org
--- Comment #10 from drow at gcc dot gnu dot org 2007-08-08 18:51 --- Subject: Re: gcc allows negatively-sized arrays On Wed, Aug 08, 2007 at 05:34:47PM -, sdyoung at miranda dot org wrote: > main() { > int y = 0xFFFD; > int x[y]; > } This is roughly equivalent to malloc (

[Bug c/33024] gcc allows negatively-sized arrays

2007-08-08 Thread pinskia at gcc dot gnu dot org
--- Comment #9 from pinskia at gcc dot gnu dot org 2007-08-08 18:42 --- > fails to compile (array too large). One is runtime undefined (VLAs) and the other is compile time undefined (constant size). -- pinskia at gcc dot gnu dot org changed: What|Removed

[Bug c/33024] gcc allows negatively-sized arrays

2007-08-08 Thread sdyoung at miranda dot org
--- Comment #8 from sdyoung at miranda dot org 2007-08-08 17:34 --- Consider: main() { int x[0xFFFD]; } fails to compile (array too large). main() { int y = 0xFFFD; int x[y]; } does compile. Somewhere, your error checking (or lack thereof) for VLAs is broken. Unless I

[Bug c/33024] gcc allows negatively-sized arrays

2007-08-08 Thread pinskia at gcc dot gnu dot org
--- Comment #7 from pinskia at gcc dot gnu dot org 2007-08-08 17:29 --- We can warn if we get a VLA with a "large" unsigned number but that requires dataflow which means you don't get the warning at -O0. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33024

[Bug c/33024] gcc allows negatively-sized arrays

2007-08-08 Thread pinskia at gcc dot gnu dot org
--- Comment #6 from pinskia at gcc dot gnu dot org 2007-08-08 17:27 --- >should not segfault (which it does). Not when you consider the stack pointer will wrap and increase (instead of decrease) by 8. Again this is only undefined C99. (this code is invalid C90 and C++98 anyways as var

[Bug c/33024] gcc allows negatively-sized arrays

2007-08-08 Thread pinskia at gcc dot gnu dot org
--- Comment #5 from pinskia at gcc dot gnu dot org 2007-08-08 17:25 --- On i686-apple-darwin, I get the following warning: t.c:8: warning: format '%d' expects type 'int', but argument 2 has type 'long unsigned int' -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33024

[Bug c/33024] gcc allows negatively-sized arrays

2007-08-08 Thread sdyoung at miranda dot org
--- Comment #4 from sdyoung at miranda dot org 2007-08-08 17:18 --- I should clarify that the assembly below is generated from exactly the code I included in my original bug report. Furthermore, if it is being converted to 0xFFFD, then #include int main(int argc, char **argv) {

[Bug c/33024] gcc allows negatively-sized arrays

2007-08-08 Thread sdyoung at miranda dot org
--- Comment #3 from sdyoung at miranda dot org 2007-08-08 17:14 --- Subject: Re: gcc allows negatively-sized arrays On Wed, Aug 08, 2007 at 04:55:08PM -, pinskia at gcc dot gnu dot org wrote: > --- Comment #2 from pinskia at gcc dot gnu dot org 2007-08-08 16:55 > --- > Th

[Bug c/33024] gcc allows negatively-sized arrays

2007-08-08 Thread pinskia at gcc dot gnu dot org
--- Comment #2 from pinskia at gcc dot gnu dot org 2007-08-08 16:55 --- This is not a bug, VLA's size is unsigned so -2 is converted over to 0xFFFD. also sizeof gives back an unsigned type. This is only undefined behavior anyways. -- pinskia at gcc dot gnu dot org changed: