<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - crash in search_n"
href="http://llvm.org/bugs/show_bug.cgi?id=15667">15667</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>crash in search_n
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>hhinnant@apple.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dlorenz@mac.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>See
<a href="http://stackoverflow.com/questions/15809929/is-this-crash-in-libc-stdsearch-n-a-bug">http://stackoverflow.com/questions/15809929/is-this-crash-in-libc-stdsearch-n-a-bug</a>
This code crashes in Xcode 4.6.1:
int main(int argc, char *argv[])
{
// Crashes
std::vector<uint8_t> bs{1, 0, 0};
std::search_n(bs.begin(), bs.end(), 3, 1);
// Does not crash
std::vector<uint8_t> bs{1, 0};
std::search_n(bs.begin(), bs.end(), 2, 1);
return 0;
}
The problem lies in __search_n, when a partial match is made, __first will be
beyond __s and the check for equality will fail, so there is no early exit;
eventually it will crash.
if (__first == __s) // return __last if no element matches __value_
needs to be replaced by
if (__first >= __s) // return __last if no element matches __value_</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>