Skip to content

Commit 26ede31

Browse files
authored
Rollup merge of #5784 - matthiaskrgr:ice_5780, r=phansch
Fix out of bounds access by checking length equality BEFORE accessing by index. Fixes #5780 changelog: fix out of bounds access in unnested_or_patterns lint. Edit: I did not bother reducing a testcase from `librustc_typeck` crate but I can confirm that with the change the crash no longer occurs.
2 parents 32ef448 + 1b3bc16 commit 26ede31

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

clippy_lints/src/unnested_or_patterns.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ fn extend_with_matching(
400400

401401
/// Are the patterns in `ps1` and `ps2` equal save for `ps1[idx]` compared to `ps2[idx]`?
402402
fn eq_pre_post(ps1: &[P<Pat>], ps2: &[P<Pat>], idx: usize) -> bool {
403-
ps1[idx].is_rest() == ps2[idx].is_rest() // Avoid `[x, ..] | [x, 0]` => `[x, .. | 0]`.
404-
&& ps1.len() == ps2.len()
403+
ps1.len() == ps2.len()
404+
&& ps1[idx].is_rest() == ps2[idx].is_rest() // Avoid `[x, ..] | [x, 0]` => `[x, .. | 0]`.
405405
&& over(&ps1[..idx], &ps2[..idx], |l, r| eq_pat(l, r))
406406
&& over(&ps1[idx + 1..], &ps2[idx + 1..], |l, r| eq_pat(l, r))
407407
}

0 commit comments

Comments
 (0)