This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/13400] New: Compiled code crashes storing to read-only location
- From: "hebisch at math dot uni dot wroc dot pl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Dec 2003 19:16:34 -0000
- Subject: [Bug middle-end/13400] New: Compiled code crashes storing to read-only location
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following program:
typedef struct {int c, l; char ch[3];} pstr;
const pstr ao = {2, 2, "OK"};
const pstr * const a = &ao;
int main(void)
{
if (a->ch[a->l]) {
((char *)a->ch)[a->l] = 0;
}
return 0;
}
segfaults when compiled using `-O' (or better optimisation).
Without optimisation the store is not executed and the program
runs fine.
I tried CVS gcc (updated DEC 14, 04:28 CET 2003) on Athlon-XP
running Debian Woody (configured using '--enable-languages=c'
as the only option). The problem does not appear in 20031029
snapshot, but is present in 20031105 snapshot.
By the way, my original problem is in GNU Pascal. Constant Pascal
strings are stored in .rodata section and compiler makes sure that
the string is null terminated. On the other hand variable strings
need not be null terminated. When convering Pascal strings to C
strings GPC generates code to null terminate the strings which are
not already null terminated. The C program above tries to reproduce
the code GPC produces.
--
Summary: Compiled code crashes storing to read-only location
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: hebisch at math dot uni dot wroc dot pl
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13400