This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/32490] New: gcc does not make the difference between pointers and arrays at all
- From: "ftwilliam at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 25 Jun 2007 07:17:33 -0000
- Subject: [Bug c/32490] New: gcc does not make the difference between pointers and arrays at all
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I believe this is not what gcc was supposed to do.
The code below produces a segmentation fault. I have written the reason of the
segmentation fault in a comment block toward the end of the code below.
And I don't think this is how gcc is supposed to behave.
#include <unistd.h>
#include <stdio.h>
typedef struct ch {
char flag;
union {
int size;
struct ch *next;
} option;
} chunk;
main() {
chunk *b;
b=1+sbrk(4096 + 2*sizeof(chunk));
/*
the code below will produce a segmentation fault
because gcc is threating b as if I was writting b[sizeof(chunk)+4096]
but I only need to add sizeof(chunk)+4096 to the address saved in b
and access the resulting calculated address.
Is it really what gcc is supposed to do ???
*/
(*(b+sizeof(chunk)+4096)).option.next=0;
}
--
Summary: gcc does not make the difference between pointers and
arrays at all
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: blocker
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ftwilliam at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32490