<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - off-by-one error in check for vector::size() exceeding max_size()"
href="https://bugs.llvm.org/show_bug.cgi?id=41618">41618</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>off-by-one error in check for vector::size() exceeding max_size()
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>richard-llvm@metafoo.co.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>Testcase:
#include <vector>
size_t e() {
std::vector<T> vb;
return vb.max_size();
}
size_t f() {
std::vector<T> vb(e());
vb.push_back({});
return vb.size();
}
size_t g() {
std::vector<T> vb(e());
vb.push_back({});
vb.push_back({});
return vb.size();
}
Compiling with -m32, we find:
* when T = bool, e() returns 0x7fffffff, f() does not throw and returns
0x80000000, and g() throws length_error
* when T = int, e() returns 0x3fffffff, f() does not throw and returns 0 (!),
and g() calls 'operator new(0xfffffffd)' which presumably throws bad_alloc()
I've not tested other container types.</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>