Skip to content

Commit

Permalink
Merge pull request #24 from ibuclaw/issue5817
Browse files Browse the repository at this point in the history
Add generic overflow catching code - fixes 5817
  • Loading branch information
andralex committed Jun 15, 2011
2 parents cea2569 + 1f5b387 commit 0a78837
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/rt/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,13 @@ extern (C) void[] _d_newarrayT(TypeInfo ti, size_t length)
}
}
else
size *= length;
{
auto newsize = size * length;
if (newsize / length != size)
goto Loverflow;

size = newsize;
}

// increase the size by the array pad.
auto info = gc_qalloc(size + __arrayPad(size), !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN | BlkAttr.APPENDABLE : BlkAttr.APPENDABLE);
Expand Down Expand Up @@ -810,7 +816,13 @@ extern (C) void[] _d_newarrayiT(TypeInfo ti, size_t length)
}
}
else
size *= length;
{
auto newsize = size * length;
if (newsize / length != size)
goto Loverflow;

size = newsize;
}

auto info = gc_qalloc(size + __arrayPad(size), !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN | BlkAttr.APPENDABLE : BlkAttr.APPENDABLE);
debug(PRINTF) printf(" p = %p\n", info.base);
Expand Down

0 comments on commit 0a78837

Please sign in to comment.