On Fri, Jul 27, 2012 at 2:10 AM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@googlemail.com" target="_blank" class="cremed">benny.kra@googlemail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: d0k<br>
Date: Fri Jul 27 04:10:25 2012<br>
New Revision: 160854<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=160854&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=160854&view=rev</a><br>
Log:<br>
SmallVector::erase: Assert that iterators are actually inside the vector.<br>
<br>
The rationale here is that it's hard to write loops containing vector erases and<br>
it only shows up if the vector contains non-trivial objects leading to crashes<br>
when forming them out of garbage memory.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/ADT/SmallVector.h<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/SmallVector.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=160854&r1=160853&r2=160854&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=160854&r1=160853&r2=160854&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Fri Jul 27 04:10:25 2012<br>
@@ -463,6 +463,7 @@<br>
   }<br>
<br>
   iterator erase(iterator I) {<br>
+    assert(I >= this->begin() && I < this->end() && "Iterator out of bounds");<br></blockquote><div><br></div><div>What do you think about making these separate asserts so that the line number (and message) tell you exactly what went wrong instead of just that something went wrong? It's a bit more code, but not that much...</div>
<div><br></div><div>Also, is it worth factoring these asserts into a generic pair of functions, one to validate a single iterator, one to validate a begin/end pair, and use them more consistently throughout APIs that accept such iterators?</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
     iterator N = I;<br>
     // Shift all elts down one.<br>
     this->move(I+1, this->end(), I);<br>
@@ -472,6 +473,8 @@<br>
   }<br>
<br>
   iterator erase(iterator S, iterator E) {<br>
+    assert(S >= this->begin() && S <= E && E <= this->end() &&<br>
+           "Iterator range out of bounds");<br>
     iterator N = S;<br>
     // Shift all elts down.<br>
     iterator I = this->move(E, this->end(), S);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" class="cremed">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>