Bug 2851 – Segfault(expression.c) using C-style struct initializer with too few arguments
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2009-04-18T01:48:00Z
Last change time
2014-04-18T09:12:05Z
Keywords
accepts-invalid, ice-on-invalid-code, patch
Assigned to
bugzilla
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2009-04-18T01:48:16Z
The bug is that it doesn't check that the number of members in the initializer is correct. It's silently accepted as long as you don't access an uninitialised member; if you do, the compiler segfaults.
----
struct Test{
int foo;
}
enum Test test = {};
enum q = test.foo;
Comment #1 by clugdbug — 2009-05-14T01:34:55Z
Fixed in DMD2.030, NOT FIXED in DMD1.045.
struct Test{
int foo;
}
const Test test = {};
const q = test.foo;
Comment #2 by bugzilla — 2009-05-15T12:19:00Z
Fixed dmd 2.030
Comment #3 by gide — 2009-05-15T16:13:17Z
Re-opened because DMD 1.045 segfaults.
Comment #4 by clugdbug — 2009-08-13T00:00:52Z
Seems like this was just missed in copying from D2 to D1.
Segfaulting in StructLiteralExp::getFieldIndex() in expression.c.
PATCH:
Just copy int StructLiteralExp::getFieldIndex(Type *type, unsigned offset)
(line 3197) from D2 to D1. (Needs if(elements->dim){ ... } around the for loop).