Skip to content

Commit

Permalink
Fix Issue 17467 - BitArray are broken with <<= 64
Browse files Browse the repository at this point in the history
  • Loading branch information
Darredevil committed Nov 7, 2017
1 parent 0d5f0c4 commit 997eb62
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions std/bitmanip.d
Expand Up @@ -1979,6 +1979,8 @@ public:
}
body
{
if (nbits == 0)
return lower;
return (upper << (bitsPerSizeT - nbits)) | (lower >> nbits);
}

Expand Down Expand Up @@ -2014,6 +2016,8 @@ public:
}
body
{
if (nbits == 0)
return upper;
return (upper << nbits) | (lower >> (bitsPerSizeT - nbits));
}

Expand Down Expand Up @@ -2101,8 +2105,11 @@ public:
// end of the array.
if (wordsToShift < dim)
{
_ptr[dim - wordsToShift - 1] = rollRight(0, _ptr[dim - 1] & endMask,
bitsToShift);
if (bitsToShift == 0)
_ptr[dim - wordsToShift - 1] = _ptr[dim - 1];
else
_ptr[dim - wordsToShift - 1] = rollRight(0, _ptr[dim - 1] & endMask,
bitsToShift);
}

import std.algorithm.comparison : min;
Expand All @@ -2112,6 +2119,27 @@ public:
}
}

// Issue 17467
@system unittest
{
import std.algorithm.comparison : equal;
import std.range : iota;

bool[] buf = new bool[64*3];
buf[0 .. 64] = true;
BitArray b = BitArray(buf);
assert(equal(b.bitsSet, iota(0, 64)));
b <<= 64;
assert(equal(b.bitsSet, iota(64, 128)));

buf = new bool[64*3];
buf[64*2 .. 64*3] = true;
b = BitArray(buf);
assert(equal(b.bitsSet, iota(64*2, 64*3)));
b >>= 64;
assert(equal(b.bitsSet, iota(64, 128)));
}

@system unittest
{
import std.format : format;
Expand Down

0 comments on commit 997eb62

Please sign in to comment.