Skip to content

Commit

Permalink
1914+3198
Browse files Browse the repository at this point in the history
1914 Array initialisation from const array yields memory trample
3198 wrong initializer for structs arrays

This is the actual compiler change. (Wasn't included in the previous
commit due to my inexperience with Git).
  • Loading branch information
Don Clugston committed Jan 27, 2011
1 parent bf1d0d9 commit 0c7bd71
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/todt.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ dt_t **TypeSArray::toDtElem(dt_t **pdt, Expression *e)
pdt = &((*pdt)->DTnext);
Type *tnext = next;
Type *tbn = tnext->toBasetype();
while (tbn->ty == Tsarray)
while (tbn->ty == Tsarray && (!e || tbn != e->type->nextOf()))
{ TypeSArray *tsa = (TypeSArray *)tbn;

len *= tsa->dim->toInteger();
Expand All @@ -994,11 +994,12 @@ dt_t **TypeSArray::toDtElem(dt_t **pdt, Expression *e)
}
if (!e) // if not already supplied
e = tnext->defaultInit(); // use default initializer
if (tbn->ty == Tstruct)
tnext->toDt(pdt);
else
e->toDt(pdt);
e->toDt(pdt);
dt_optimize(*pdt);
if (e->op == TOKstring)
len /= ((StringExp *)e)->len;
if (e->op == TOKarrayliteral)
len /= ((ArrayLiteralExp *)e)->elements->dim;
if ((*pdt)->dt == DT_azeros && !(*pdt)->DTnext)
{
(*pdt)->DTazeros *= len;
Expand All @@ -1010,7 +1011,7 @@ dt_t **TypeSArray::toDtElem(dt_t **pdt, Expression *e)
(*pdt)->DTazeros = len;
pdt = &((*pdt)->DTnext);
}
else if (e->op != TOKstring && e->op != TOKarrayliteral)
else
{
for (i = 1; i < len; i++)
{
Expand Down

0 comments on commit 0c7bd71

Please sign in to comment.