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 | 844fad5f440c7a69112c2f8f17bbc488232a6893 (patch) | |
tree | 9bfdd4aaec2eef9bae13cab40a3beb22873a1cd7 /include/llvm/ADT | |
parent | 6c103906d25a02f9c1afda92f9ad133dffeeeb3a (diff) | |
download | external_llvm-844fad5f440c7a69112c2f8f17bbc488232a6893.zip external_llvm-844fad5f440c7a69112c2f8f17bbc488232a6893.tar.gz external_llvm-844fad5f440c7a69112c2f8f17bbc488232a6893.tar.bz2 |
Added two bounds checks to the BitVector class to detect
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
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r-- | include/llvm/ADT/BitVector.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/include/llvm/ADT/BitVector.h b/include/llvm/ADT/BitVector.h index 927cfa9..3843699 100644 --- a/include/llvm/ADT/BitVector.h +++ b/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) { |