Fix a buffer overrun detected by AddressSanitizer.

llvm-svn: 197647
This commit is contained in:
Anna Zaks 2013-12-19 02:35:26 +00:00
parent 2fc7101e3c
commit 386328f96f
2 changed files with 10 additions and 2 deletions

View File

@ -267,7 +267,8 @@ public:
Bits[I / BITWORD_SIZE] = ~0UL; Bits[I / BITWORD_SIZE] = ~0UL;
BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1; BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1;
Bits[I / BITWORD_SIZE] |= PostfixMask; if (I < E)
Bits[I / BITWORD_SIZE] |= PostfixMask;
return *this; return *this;
} }
@ -305,7 +306,8 @@ public:
Bits[I / BITWORD_SIZE] = 0UL; Bits[I / BITWORD_SIZE] = 0UL;
BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1; BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1;
Bits[I / BITWORD_SIZE] &= ~PostfixMask; if (I < E)
Bits[I / BITWORD_SIZE] &= ~PostfixMask;
return *this; return *this;
} }

View File

@ -356,6 +356,12 @@ TYPED_TEST(BitVectorTest, RangeOps) {
EXPECT_TRUE( E.test(1)); EXPECT_TRUE( E.test(1));
EXPECT_TRUE( E.test(32)); EXPECT_TRUE( E.test(32));
EXPECT_FALSE(E.test(33)); EXPECT_FALSE(E.test(33));
TypeParam BufferOverrun;
unsigned size = sizeof(unsigned long) * 8;
BufferOverrun.resize(size);
BufferOverrun.reset(0, size);
BufferOverrun.set(0, size);
} }
TYPED_TEST(BitVectorTest, CompoundTestReset) { TYPED_TEST(BitVectorTest, CompoundTestReset) {