-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Hazards on uint overflow in std::vec #8742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It seems these can/should be solved by using |
I think we should add helper methods for "reserve space for N more elements". That way we solve this problem for user code too (is it needed?)
|
|
Life would be easier if vectors were |
flip1995
pushed a commit
to flip1995/rust
that referenced
this issue
May 5, 2022
…=llogiq mistyped_literal_suffix: improve integer suggestions, avoid wrong float suggestions This PR fixes 2 things: - The known problem that integer types are always suggested as signed, by suggesting an unsigned suffix for literals that wouldnt fit in the signed type, and ignores any literals too big for the corresponding unsigned type too. - The lint would only look at the integer part of any floating point literals without an exponent, this causing rust-lang#6129. This just ignores those literals. Examples: ```rust let _ = 2_32; // still 2_i32 let _ = 234_8; // would now suggest 234_u8 // these are now ignored let _ = 500_8; let _ = 123_32.123; ``` changelog: suggest correct integer types in [`mistyped_literal_suffix`], ignore float literals without an exponent fixes rust-lang#6129
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
std::vec does not check for overflow properly, and it should be possible to crash Rust where uint overflow can be triggered in reserve logic (at least in 32-bit Rust).
.reserve(n)
must allocaten
elements, orfail!()
(or controlled OOM abort in the runtime/allocator); I think this is ok today..reserve_at_least(n)
must allocate at leastn
elements orfail!()
. This is buggy today since sufficiently largen
will round "up" to0
..reserve
or.reverse_at_least
str
verdict: if you
unsafe {}
, check for overflow.The text was updated successfully, but these errors were encountered: