[Issue 14699] ICE: segfaults on array with zero size

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jun 15 03:45:49 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14699

--- Comment #6 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Ketmar Dark from comment #5)
> or a patch for those who prefers `ubyte[0]` to be valid (phobos using such
> thing, hehe):
[snip]

When tsa->size() == 0, toDtElem can return a dummy zero as the dt.

diff --git a/src/todt.c b/src/todt.c
index cd45664..6d5a476 100644
--- a/src/todt.c
+++ b/src/todt.c
@@ -773,10 +773,15 @@ dt_t **Type_toDt(Type *t, dt_t **pdt)

 dt_t **toDtElem(TypeSArray *tsa, dt_t **pdt, Expression *e)
 {
-    //printf("TypeSArray::toDtElem()\n");
-    size_t len = tsa->dim->toInteger();
-    if (len)
+    //printf("TypeSArray::toDtElem() tsa = %s\n", tsa->toChars());
+    if (tsa->size(Loc()) == 0)
     {
+        pdt = dtnzeros(pdt, 0);
+    }
+    else
+    {
+        size_t len = tsa->dim->toInteger();
+        assert(len);
         pdt = dtend(pdt);
         Type *tnext = tsa->next;
         Type *tbn = tnext->toBasetype();

--


More information about the Digitalmars-d-bugs mailing list