This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c/9799: mismatching structure initializer with nested flexible array member, segfaults


>Number:         9799
>Category:       c
>Synopsis:       mismatching structure initializer with nested flexible array member, segfaults
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          ice-on-illegal-code
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 22 02:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Corey Minter
>Release:        3.1
>Organization:
>Environment:
linux 2.4
>Description:
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}  
};

>How-To-Repeat:
gcc -c gcc_seg_fault.c
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]