<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 - Unsigned Integer Overflow when comparing strings (|s1|<|s2|)"
href="https://bugs.llvm.org/show_bug.cgi?id=48189">48189</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Unsigned Integer Overflow when comparing strings (|s1|<|s2|)
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</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>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jerryc443@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Sample code:
```cpp
bool b = std::string() < "1";
```
Run this with UBSAN enabled, I got the following output: (`clang 11 using
libstdc++, -std=c++20`)
```
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h:403:51:
runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type
'unsigned long'
#0 0x428a8e in std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::_S_compare(unsigned long, unsigned long)
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h:403:51
#1 0x42870c in std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::compare(char const*) const
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.tcc:1429:8
#2 0x4273b7 in
decltype(__detail::__char_traits_cmp_cat<std::char_traits<char> >(0))
std::operator<=><char, std::char_traits<char>, std::allocator<char>
<span class="quote">>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>
> const&, char const*)</span >
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h:6216:61
#3 0x4271f5 in main ***
#4 0x7f13e917dcc9 in __libc_start_main csu/../csu/libc-start.c:308:16
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h:403:51
in
```
See:
<a href="https://github.com/google/sanitizers/issues/1346">https://github.com/google/sanitizers/issues/1346</a>
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97844">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97844</a></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>