Add bound checks in SmallVector
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 22 Sep 2008 10:06:26 +0000 (10:06 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 22 Sep 2008 10:06:26 +0000 (10:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56432 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/SmallVector.h

index fdecb6c44812dc25266a68548e59b29d979eac7c..a1373e2de7557516a6a6f775a91861ceb3bbecf0 100644 (file)
@@ -19,6 +19,7 @@
 #include <algorithm>
 #include <cstring>
 #include <memory>
+#include <cassert>
 
 #ifdef _MSC_VER
 namespace std {
@@ -116,10 +117,14 @@ public:
   const_reverse_iterator rend() const { return const_reverse_iterator(begin());}
   
   
+  /* These asserts could be "Begin + idx < End", but there are lots of places
+     in llvm where we use &v[v.size()] instead of v.end(). */
   reference operator[](unsigned idx) {
+    assert (Begin + idx <= End);
     return Begin[idx];
   }
   const_reference operator[](unsigned idx) const {
+    assert (Begin + idx <= End);
     return Begin[idx];
   }