Closed
Description
Code:
pub fn foo(buf: &[u8]) -> Option<&[u8]> {
// guard against potential overflow
if buf.len() > usize::MAX/3 {
return None;
}
let n = (3*buf.len())/4;
Some(&buf[..n])
}
Even replacing usize::MAX/3
with any non-zero small number (even 1) does not result in removal of the bound check.
This behavior can be reproduced on current Nightly and previous stable compiler versions.