I tried this code:
fn main() {
let mut v = vec![1,2,3];
v.drain(..=usize::MAX);
}
According to the documentation this should panic, since usize::MAX is greater than the length of the vector. Instead, no panic happens and no elements are removed from the vector.
Upon investigation it appears that the increment of the upper range bound silently overflows and the range is interpreted as 0..0.
I believe using .saturating_add(1) instead of +1 should make this panic, which is what I'd expect to happen.
Meta
rustc --version --verbose:
Found through fuzzing via https://github.com/jakubadamw/rutenspitz
I tried this code:
According to the documentation this should panic, since
usize::MAXis greater than the length of the vector. Instead, no panic happens and no elements are removed from the vector.Upon investigation it appears that the increment of the upper range bound silently overflows and the range is interpreted as
0..0.I believe using
.saturating_add(1)instead of+1should make this panic, which is what I'd expect to happen.Meta
rustc --version --verbose:Found through fuzzing via https://github.com/jakubadamw/rutenspitz