User account creation filtered due to spam.

Bug 9799 - mismatching structure initializer with nested flexible array member, segfaults
Summary: mismatching structure initializer with nested flexible array member, segfaults
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.1
: P3 normal
Target Milestone: ---
Assignee: Eric Botcazou
URL:
Keywords: ice-on-invalid-code
: 9800 10006 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-02-22 02:56 UTC by corey.minter
Modified: 2003-07-25 17:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description corey.minter 2003-02-22 02:56:00 UTC
Error message is...
  gcc_seg_fault.c:14: internal error: Segmentation fault
  Please submit a full bug report...

The following illegal code caused a segfault instead of being flagged as an illegal structure initializer.  Of course I stripped this down and changed the data and identifier names from my original code :).

There are actually two errors in my code which I suppose "aligned" to trigger the segfault.

Here is the code...

// gcc_seg_fault.c

typedef struct {
    int aaa;
} s1_t;

typedef struct {
    int bbb;
    s1_t s1_array[];  // <-- oops, array has no size
} s2_t;

static s2_t s2_array[]= {
    { 1, 4}, // <-- 4 should really be inside { }
    { 2, 5},
    { 3, 6}
};

The following code does work...

// gcc_ok1.c

typedef struct {
    int aaa;
} s1_t;

typedef struct {
    int bbb;
    s1_t s1_array[]; 
} s2_t;

static s2_t s2_array[]= {
    { 1, {4}},
    { 2, {5}},
    { 3, {6}}
};

and this works also...

// gcc_ok2.c

typedef struct {
    int aaa;
} s1_t;

typedef struct {
    int bbb;
    s1_t s1_array[2];
} s2_t;

static s2_t s2_array[]= {
    { 1, 4},  
    { 2, 5},  
    { 3, 6}  
};

Release:
3.1

Environment:
linux 2.4

How-To-Repeat:
gcc -c gcc_seg_fault.c
Comment 1 Eric Botcazou 2003-02-22 20:57:34 UTC
Responsible-Changed-From-To: unassigned->ebotcazou
Responsible-Changed-Why: Patching.
Comment 2 Eric Botcazou 2003-02-22 20:57:34 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Lack of sanity check.
Comment 3 Eric Botcazou 2003-03-05 08:37:57 UTC
From: ebotcazou@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/9799
Date: 5 Mar 2003 08:37:57 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	ebotcazou@gcc.gnu.org	2003-03-05 08:37:57
 
 Modified files:
 	gcc            : ChangeLog c-typeck.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/gcc.c-torture/compile: 20030305-1.c 
 
 Log message:
 	PR c/9799
 	* c-typeck.c (push_init_level): Add sanity check.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.16944&r2=1.16945
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.222&r2=1.223
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2468&r2=1.2469
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/20030305-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
 

Comment 6 Eric Botcazou 2003-03-05 09:06:40 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed.