aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/ADT
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-02 03:06:26 +0000
committerChris Lattner <sabre@nondot.org>2009-04-02 03:06:26 +0000
commitec5ef8924136c3e156080e214d0490318b373d08 (patch)
treec10940af4f42a3088efef5a3b4e72d7069950c68 /include/llvm/ADT
parent292bf3aa763842f824edcb2adaa1bf5e5d9dac15 (diff)
downloadexternal_llvm-ec5ef8924136c3e156080e214d0490318b373d08.zip
external_llvm-ec5ef8924136c3e156080e214d0490318b373d08.tar.gz
external_llvm-ec5ef8924136c3e156080e214d0490318b373d08.tar.bz2
fix overflow checks in SmallVector:
"The code was doing "if (End+NumInputs > Capacity) ...". If End is close to 0xFFFFFFFF and NumInputs is large, it'll overflow, the condition will come out false, and the vector won't grow to accommodate the new elements, and the program will crash in memmove." Patch by Jeffrey Yasskin! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68277 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r--include/llvm/ADT/SmallVector.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h
index 445f991..d5fef48 100644
--- a/include/llvm/ADT/SmallVector.h
+++ b/include/llvm/ADT/SmallVector.h
@@ -210,7 +210,7 @@ public:
void append(in_iter in_start, in_iter in_end) {
size_type NumInputs = std::distance(in_start, in_end);
// Grow allocated space if needed.
- if (End+NumInputs > Capacity)
+ if (NumInputs > size_type(Capacity-End))
grow(size()+NumInputs);
// Copy the new elements over.
@@ -222,7 +222,7 @@ public:
///
void append(size_type NumInputs, const T &Elt) {
// Grow allocated space if needed.
- if (End+NumInputs > Capacity)
+ if (NumInputs > size_type(Capacity-End))
grow(size()+NumInputs);
// Copy the new elements over.
@@ -456,9 +456,9 @@ void SmallVectorImpl<T>::swap(SmallVectorImpl<T> &RHS) {
std::swap(Capacity, RHS.Capacity);
return;
}
- if (Begin+RHS.size() > Capacity)
+ if (RHS.size() > size_type(Capacity-Begin))
grow(RHS.size());
- if (RHS.begin()+size() > RHS.Capacity)
+ if (size() > size_type(RHS.Capacity-RHS.begin()))
RHS.grow(size());
// Swap the shared elements.