[llvm-commits] [llvm] r44815 - /llvm/trunk/include/llvm/ADT/BitVector.h

Ted Kremenek kremenek at apple.com
Mon Dec 10 14:28:35 PST 2007


Author: kremenek
Date: Mon Dec 10 16:28:35 2007
New Revision: 44815

URL: http://llvm.org/viewvc/llvm-project?rev=44815&view=rev
Log:
Added two bounds checks to the BitVector class to detect
out-of-bounds bit accesses.  The checks are only performed
in a Debug build.

Modified:
    llvm/trunk/include/llvm/ADT/BitVector.h

Modified: llvm/trunk/include/llvm/ADT/BitVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/BitVector.h?rev=44815&r1=44814&r2=44815&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/BitVector.h (original)
+++ llvm/trunk/include/llvm/ADT/BitVector.h Mon Dec 10 16:28:35 2007
@@ -245,10 +245,12 @@
 
   // 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 @@
     // Destroy the old bits.
     delete[] Bits;
     Bits = NewBits;
+    
+    clear_unused_bits();
   }
 
   void init_words(BitWord *B, unsigned NumWords, bool t) {





More information about the llvm-commits mailing list