Skip to content

Commit

Permalink
Fix 'last bug' in quantizer prompted by Timon Gehr
Browse files Browse the repository at this point in the history
  • Loading branch information
andralex committed May 12, 2015
1 parent 124a81d commit 18d5cd9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions std/experimental/allocator/quantizer.d
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,17 @@ struct Quantizer(ParentAllocator, alias roundingFunction)
*/
bool reallocate(ref void[] b, size_t s)
{
if (s >= b.length && expand(b, s - b.length)) return true;
if (s >= b.length)
{
if (expand(b, s - b.length)) return true;
if (!b.ptr) return false; // memory exhausted
}
assert(b.ptr); // code above took care of it
immutable toAllocate = goodAllocSize(s),
allocated = goodAllocSize(b.length);
// Are the lengths within the same quantum?
if (allocated == toAllocate)
{
assert(b.ptr); // expand() must have caught this
// Reallocation (whether up or down) will be done in place
b = b.ptr[0 .. s];
return true;
Expand Down

0 comments on commit 18d5cd9

Please sign in to comment.