Bug 4089 – crash when creating JSON output for incomplete struct

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-04-14T00:01:00Z
Last change time
2015-06-09T05:14:59Z
Keywords
ice-on-valid-code, patch
Assigned to
nobody
Creator
r.sagitario

Comments

Comment #0 by r.sagitario — 2010-04-14T00:01:04Z
This one-line code: /// test.d struct X; causes a crash when executing dmd -c -X test.d Here's a patch Index: json.c =================================================================== --- json.c (revision 432) +++ json.c (working copy) @@ -307,16 +307,19 @@ } } - JsonString(buf, Pmembers); - buf->writestring(" : [\n"); - size_t offset = buf->offset; - for (int i = 0; i < members->dim; i++) - { Dsymbol *s = (Dsymbol *)members->data[i]; - if (offset != buf->offset) - { buf->writestring(",\n"); - offset = buf->offset; + if(members) + { + JsonString(buf, Pmembers); + buf->writestring(" : [\n"); + size_t offset = buf->offset; + for (int i = 0; i < members->dim; i++) + { Dsymbol *s = (Dsymbol *)members->data[i]; + if (offset != buf->offset) + { buf->writestring(",\n"); + offset = buf->offset; + } + s->toJsonBuffer(buf); } - s->toJsonBuffer(buf); } JsonRemoveComma(buf); buf->writestring("]\n");
Comment #1 by r.sagitario — 2010-04-14T00:44:11Z
sorry, the patch produced wrong brackets. Here's a better version: Index: json.c =================================================================== --- json.c (revision 432) +++ json.c (working copy) @@ -307,19 +307,23 @@ } } - JsonString(buf, Pmembers); - buf->writestring(" : [\n"); - size_t offset = buf->offset; - for (int i = 0; i < members->dim; i++) - { Dsymbol *s = (Dsymbol *)members->data[i]; - if (offset != buf->offset) - { buf->writestring(",\n"); - offset = buf->offset; + if(members) + { + JsonString(buf, Pmembers); + buf->writestring(" : [\n"); + size_t offset = buf->offset; + for (int i = 0; i < members->dim; i++) + { Dsymbol *s = (Dsymbol *)members->data[i]; + if (offset != buf->offset) + { buf->writestring(",\n"); + offset = buf->offset; + } + s->toJsonBuffer(buf); } - s->toJsonBuffer(buf); + JsonRemoveComma(buf); + buf->writestring("]\n"); } JsonRemoveComma(buf); - buf->writestring("]\n"); buf->writestring("}\n"); }
Comment #2 by r.sagitario — 2010-04-21T11:09:05Z
An almost identical patch is also needed for incomplete EnumDeclarations: Index: json.c =================================================================== --- json.c (revision 433) +++ json.c (working copy) @@ -386,19 +386,23 @@ if (memtype) JsonProperty(buf, "base", memtype->toChars()); - JsonString(buf, Pmembers); - buf->writestring(" : [\n"); - size_t offset = buf->offset; - for (int i = 0; i < members->dim; i++) - { Dsymbol *s = (Dsymbol *)members->data[i]; - if (offset != buf->offset) - { buf->writestring(",\n"); - offset = buf->offset; + if(members) + { + JsonString(buf, Pmembers); + buf->writestring(" : [\n"); + size_t offset = buf->offset; + for (int i = 0; i < members->dim; i++) + { Dsymbol *s = (Dsymbol *)members->data[i]; + if (offset != buf->offset) + { buf->writestring(",\n"); + offset = buf->offset; + } + s->toJsonBuffer(buf); } - s->toJsonBuffer(buf); + JsonRemoveComma(buf); + buf->writestring("]\n"); } JsonRemoveComma(buf); - buf->writestring("]\n"); buf->writestring("}\n"); }
Comment #3 by clugdbug — 2010-05-05T19:10:18Z
Fixed DMD2.044