-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #8250 - pr2502:fix_repeat_underflow, r=giraffate
Fix underflow in `manual_split_once` lint Hi, a friend found clippy started crashing on a suspiciously large allocation of `u64::MAX` memory on their code. The mostly minimized repro is: ```rust fn _f01(title: &str) -> Option<()> { let _ = title[1..].splitn(2, '[').next()?; Some(()) } ``` The underflow happens in this case on line 57 of the patch but I've changed the other substraction to saturating as well since it could potentially cause the same issue. I'm not sure where to put a regression test, or if it's even worth for such a thing. Aside, has it been considered before to build clippy with overflow checks enabled? changelog: fix ICE of underflow in `manual_split_once` lint
- Loading branch information
Showing
3 changed files
with
27 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fn _f(s: &str) -> Option<()> { | ||
let _ = s[1..].splitn(2, '.').next()?; | ||
Some(()) | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error: manual implementation of `split_once` | ||
--> $DIR/ice-8250.rs:2:13 | ||
| | ||
LL | let _ = s[1..].splitn(2, '.').next()?; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s[1..].split_once('.').map_or(s[1..], |x| x.0)` | ||
| | ||
= note: `-D clippy::manual-split-once` implied by `-D warnings` | ||
|
||
error: unnecessary use of `splitn` | ||
--> $DIR/ice-8250.rs:2:13 | ||
| | ||
LL | let _ = s[1..].splitn(2, '.').next()?; | ||
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s[1..].split('.')` | ||
| | ||
= note: `-D clippy::needless-splitn` implied by `-D warnings` | ||
|
||
error: aborting due to 2 previous errors | ||
|