Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Fix extra case where goto skips initialization of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuclaw committed Sep 24, 2014
1 parent ece2cdd commit ac97a48
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/rt/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ extern (C) void[] _d_newarrayU(const TypeInfo ti, size_t length) pure nothrow
mov EAX,size ;
mul EAX,length ;
mov size,EAX ;
jc Loverflow ;
jnc Lcontinue ;
}
}
else version(D_InlineAsm_X86_64)
Expand All @@ -800,36 +800,35 @@ extern (C) void[] _d_newarrayU(const TypeInfo ti, size_t length) pure nothrow
mov RAX,size ;
mul RAX,length ;
mov size,RAX ;
jc Loverflow ;
jnc Lcontinue ;
}
}
else
{
auto newsize = size * length;
if (newsize / length != size)
goto Loverflow;

size = newsize;
if (newsize / length == size)
{
size = newsize;
goto Lcontinue;
}
}
Loverflow:
onOutOfMemoryError();
assert(0);
Lcontinue:

// increase the size by the array pad.
auto pad = __arrayPad(size);
if (size + pad < size)
goto Loverflow;

{
auto info = GC.qalloc(size + pad, !(ti.next.flags & 1) ? BlkAttr.NO_SCAN | BlkAttr.APPENDABLE : BlkAttr.APPENDABLE);
debug(PRINTF) printf(" p = %p\n", info.base);
// update the length of the array
auto arrstart = __arrayStart(info);
auto isshared = typeid(ti) is typeid(TypeInfo_Shared);
__setArrayAllocLength(info, size, isshared);
return arrstart[0..length];
}

Loverflow:
onOutOfMemoryError();
assert(0);
}

/**
Expand Down

0 comments on commit ac97a48

Please sign in to comment.