[llvm-commits] [llvm] r173321 - /llvm/trunk/include/llvm/ADT/SmallVector.h

Richard Trieu rtrieu at google.com
Wed Jan 23 20:29:24 PST 2013


Author: rtrieu
Date: Wed Jan 23 22:29:24 2013
New Revision: 173321

URL: http://llvm.org/viewvc/llvm-project?rev=173321&view=rev
Log:
Add asserts to SmallVector so that calls to front() and back() only succeed
if the vector is not empty.  This will ensure that calls to these functions
will reference elements in the vector.

Modified:
    llvm/trunk/include/llvm/ADT/SmallVector.h

Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=173321&r1=173320&r2=173321&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Wed Jan 23 22:29:24 2013
@@ -145,16 +145,20 @@
   }
 
   reference front() {
+    assert(!empty());
     return begin()[0];
   }
   const_reference front() const {
+    assert(!empty());
     return begin()[0];
   }
 
   reference back() {
+    assert(!empty());
     return end()[-1];
   }
   const_reference back() const {
+    assert(!empty());
     return end()[-1];
   }
 };





More information about the llvm-commits mailing list