[llvm] r197647 - Fix a buffer overrun detected by AddressSanitizer.
Anna Zaks
ganna at apple.com
Wed Dec 18 18:35:26 PST 2013
Author: zaks
Date: Wed Dec 18 20:35:26 2013
New Revision: 197647
URL: http://llvm.org/viewvc/llvm-project?rev=197647&view=rev
Log:
Fix a buffer overrun detected by AddressSanitizer.
Modified:
llvm/trunk/include/llvm/ADT/BitVector.h
llvm/trunk/unittests/ADT/BitVectorTest.cpp
Modified: llvm/trunk/include/llvm/ADT/BitVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/BitVector.h?rev=197647&r1=197646&r2=197647&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/BitVector.h (original)
+++ llvm/trunk/include/llvm/ADT/BitVector.h Wed Dec 18 20:35:26 2013
@@ -267,7 +267,8 @@ public:
Bits[I / BITWORD_SIZE] = ~0UL;
BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1;
- Bits[I / BITWORD_SIZE] |= PostfixMask;
+ if (I < E)
+ Bits[I / BITWORD_SIZE] |= PostfixMask;
return *this;
}
@@ -305,7 +306,8 @@ public:
Bits[I / BITWORD_SIZE] = 0UL;
BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1;
- Bits[I / BITWORD_SIZE] &= ~PostfixMask;
+ if (I < E)
+ Bits[I / BITWORD_SIZE] &= ~PostfixMask;
return *this;
}
Modified: llvm/trunk/unittests/ADT/BitVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/BitVectorTest.cpp?rev=197647&r1=197646&r2=197647&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/BitVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/BitVectorTest.cpp Wed Dec 18 20:35:26 2013
@@ -356,6 +356,12 @@ TYPED_TEST(BitVectorTest, RangeOps) {
EXPECT_TRUE( E.test(1));
EXPECT_TRUE( E.test(32));
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) {
More information about the llvm-commits
mailing list