Range bound in Vec::drain may overflow and fail to drain the vector #74909
Labels
A-collections
Area: `std::collection`
C-bug
Category: This is a bug.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
I tried this code:
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
The text was updated successfully, but these errors were encountered: