<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/70406>70406</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Rust overflow check is not removed from naive strlen
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
saethlin
</td>
</tr>
</table>
<pre>
The overflow check for the addition here is not removed. If we overflow the length then we have wrapped around address space, and the use of `ptr::add` guarantees that we didn't.
```rust
pub unsafe fn strlen(mut s: *const core::ffi::c_char) -> usize {
let mut n = 0;
while *s != 0 {
n += 1;
s = s.add(1);
}
n
}
```
Godbolt: https://godbolt.org/z/dGYWKfeeP
Alive2: https://alive2.llvm.org/ce/z/T7yFbc
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxkk8-OmzAQxp9muIw2MkMS4MAh25RV1UtVrVT1VBk8BLeOjWyTaPfpK0O6_2ohYebz7xuPGcsQ9MkyN7C7h90xk3McnW-C5DgabbPOqafmcWR0F_aDcVfsR-7_4OA8xpFRKqWjdhZH9ow6oHURPZ_dhdUGvwx4fYMmwLA9xTFNbdJGeWG8ejlNrFB6N1uVPD2HgGGSPQN9QmnVws6B0Q0IezFFD8UBioNUCvYCT7P00kbmgHGUMTkrrSxQGTcgjiAOsBfr4-cQ19A0dzjbIAfGwWKI3rAFqs5zxADFAYEOvbMhYu88r-mGQa-T_lc_Sg9U4x0Un3EO-pkRyvvVGRHRcMRkZRGKIwoo3mjXURtO_gGB8kV_D6dhEeg-afk7No2weIZNqp6qHKh-XQLl8XWxvRX_L_ZyCuvng1OdMzEVO8Y4paqBWqD2tAob509A7TNQqx5-_vg6MH9byYPRF6b_QbnEN8Zczjc4_cLF4bF8ars-U02h6qKWGTf5vq6KsqxFlY3Nvqp3pFiKQlWdzLu8J2Lu9321HXLuRKYbElTkgkpRFBVVmyovd9tC9bTdUVnVOWwFn6U2L9kzHcLMTSm2Yp8Z2bEJS58TWb7iIgJRanvfJOaum08BtsLoEMOrS9TRcPN9DvHjLXjf7zh4d0Yr9YVv3ZTN3jQfTlbHce42vTsDtSnF7XU3efeb-wjULhsLQO2y8b8BAAD__ys1GhI">