www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4089] New: crash when creating JSON output for incomplete struct

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4089

           Summary: crash when creating JSON output for incomplete struct
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-valid-code, patch
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: r.sagitario gmx.de


--- Comment #0 from Rainer Schuetze <r.sagitario gmx.de> 2010-04-14 00:01:04
PDT ---
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");

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 14 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4089



--- Comment #1 from Rainer Schuetze <r.sagitario gmx.de> 2010-04-14 00:44:11
PDT ---
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");
 }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 14 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4089



--- Comment #2 from Rainer Schuetze <r.sagitario gmx.de> 2010-04-21 11:09:05
PDT ---
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");
 }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 21 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4089


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED


--- Comment #3 from Don <clugdbug yahoo.com.au> 2010-05-05 19:10:18 PDT ---
Fixed DMD2.044

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 05 2010