Bounds-check APInt's operator[].
authorDan Gohman <gohman@apple.com>
Thu, 18 Nov 2010 17:14:56 +0000 (17:14 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 18 Nov 2010 17:14:56 +0000 (17:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119708 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/APInt.cpp

index 88f9ac63f7e99e9ff9ac07aabd27e1d0be6d56df..6bbe9ab46324a8fb46ea58c56c28bfad1808a7d9 100644 (file)
@@ -483,6 +483,7 @@ APInt APInt::operator-(const APInt& RHS) const {
 }
 
 bool APInt::operator[](unsigned bitPosition) const {
+  assert(bitPosition < getBitWidth() && "Bit position out of bounds!");
   return (maskBit(bitPosition) &
           (isSingleWord() ?  VAL : pVal[whichWord(bitPosition)])) != 0;
 }