Protect against copying undefined memory.
@@ -19,7 +19,12 @@ PartialBitVector::PartialBitVector(const BitVector & org, Index start, Index end
_alloc(allocatePaddedAndAligned(start, end))
{
init(_alloc.get(), start, end);
- memcpy(_alloc.get(), org.getWordIndex(start), numActiveBytes(start, end));
+ const Word * startWord = org.getWordIndex(start);
+ size_t numBytes2Copy = numActiveBytes(start, std::min(org.size(), end));
+ memcpy(_alloc.get(), startWord, numBytes2Copy);
+ if (org.size() < end) {
+ clearInterval(org.size(), end);
+ }
setBit(size());
}
