Fix a potential overflow in core::str::Searcher::new#16701
Fix a potential overflow in core::str::Searcher::new#16701tbu- wants to merge 1 commit intorust-lang:masterfrom
core::str::Searcher::new#16701Conversation
The overflow is mitigated by checking a sufficient condition for the less relation. Given the term `A - B < C` (`A`, `B` and `C` fixed size unsigned integers) one can check whether it holds, by evaluating `A < C || A - B < C`.
|
What overflow is this fixing? When |
|
That is, if |
|
It's impossible for the length to be 20 below |
|
Is it theoretically impossible for the length to be 20 below If it's theoretically possible then maybe some guideline on "what can we expect from array lengths" would be good so it's consistent over all Rust code. (Maybe: All arrays of objects with size |
|
It's impossible because On modern operating systems, the kernel gets half of the address space and userspace gets the other half, so saying |
|
If #16715 is fixed, this can be replaced by a comment instead of the check. |
|
As-is, I believe that this fix is not necessary, @tbu- can you update this PR to have a comment instead? |
|
@alexcrichton The PR author is writing correct code and I think it's something we should observe better throughout libcore/libstd (I've hunted such problems before). Being correct one time too many would be a good start. |
|
Closing due to inactivity, but feel free to reopen with my comment addressed! |
Closes rust-lang/rust-clippy#16698 changelog: [`match_same_arms`] fix FP with associated consts
The overflow is mitigated by checking a sufficient condition for the less
relation.
Given the term
A - B < C(A,BandCfixed size unsigned integers) onecan check whether it holds, by evaluating
A < C || A - B < C.