From df7c5d4137fd5cf63d9a9b0f09c9d7255895908c Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 27 Jul 2012 09:10:25 +0000 Subject: [PATCH] SmallVector::erase: Assert that iterators are actually inside the vector. The rationale here is that it's hard to write loops containing vector erases and it only shows up if the vector contains non-trivial objects leading to crashes when forming them out of garbage memory. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160854 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/SmallVector.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index d1240913434..9ca089877c7 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -463,6 +463,7 @@ public: } iterator erase(iterator I) { + assert(I >= this->begin() && I < this->end() && "Iterator out of bounds"); iterator N = I; // Shift all elts down one. this->move(I+1, this->end(), I); @@ -472,6 +473,8 @@ public: } iterator erase(iterator S, iterator E) { + assert(S >= this->begin() && S <= E && E <= this->end() && + "Iterator range out of bounds"); iterator N = S; // Shift all elts down. iterator I = this->move(E, this->end(), S); -- 2.34.1