diff options
author | Ted Kremenek <kremenek@apple.com> | 2007-12-10 22:28:35 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2007-12-10 22:28:35 +0000 |
commit | 9a698a1da7b8c3f86e2828544a3f23cc90a1559a (patch) | |
tree | 64ae55508fb2cdcadf82601ed146e1cda86cd2b5 | |
parent | ea9ac34d18e5ebd1037fc8ee8d812628b81c81f1 (diff) | |
download | bcm5719-llvm-9a698a1da7b8c3f86e2828544a3f23cc90a1559a.tar.gz bcm5719-llvm-9a698a1da7b8c3f86e2828544a3f23cc90a1559a.zip |
Added two bounds checks to the BitVector class to detect
out-of-bounds bit accesses. The checks are only performed
in a Debug build.
llvm-svn: 44815
-rw-r--r-- | llvm/include/llvm/ADT/BitVector.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/BitVector.h b/llvm/include/llvm/ADT/BitVector.h index 927cfa9f786..38436993c5e 100644 --- a/llvm/include/llvm/ADT/BitVector.h +++ b/llvm/include/llvm/ADT/BitVector.h @@ -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) { |