Skip to content

Commit

Permalink
Fix out of bounds access by checking length equality BEFORE accessing…
Browse files Browse the repository at this point in the history
… by index.

Fixes #5780
  • Loading branch information
matthiaskrgr committed Jul 11, 2020
1 parent be88122 commit 1b3bc16
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/unnested_or_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ fn extend_with_matching(

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

0 comments on commit 1b3bc16

Please sign in to comment.