Added two bounds checks to the BitVector class to detect
authorTed Kremenek <kremenek@apple.com>
Mon, 10 Dec 2007 22:28:35 +0000 (22:28 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 10 Dec 2007 22:28:35 +0000 (22:28 +0000)
out-of-bounds bit accesses.  The checks are only performed
in a Debug build.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44815 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/BitVector.h

index 927cfa9f7869ab83645e78d1ed85cc8c4a1eb95b..38436993c5e87591fd2b9a50a32e9398f03333df 100644 (file)
@@ -245,10 +245,12 @@ public:
 
   // Indexing.
   reference operator[](unsigned Idx) {
+    assert (Idx < Size && "Out-of-bounds Bit access.");
     return reference(*this, Idx);
   }
 
   bool operator[](unsigned Idx) const {
+    assert (Idx < Size && "Out-of-bounds Bit access.");   
     BitWord Mask = 1L << (Idx % BITWORD_SIZE);
     return (Bits[Idx / BITWORD_SIZE] & Mask) != 0;
   }
@@ -375,6 +377,8 @@ private:
     // Destroy the old bits.
     delete[] Bits;
     Bits = NewBits;
+    
+    clear_unused_bits();
   }
 
   void init_words(BitWord *B, unsigned NumWords, bool t) {