Skip to content
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

new lint: find length comparisons after access by index in ANDded if-chains #5785

Open
matthiaskrgr opened this issue Jul 11, 2020 · 1 comment
Labels
A-lint Area: New lints

Comments

@matthiaskrgr
Copy link
Member

What it does

Check for code like

fn a(v1: Vec<_>, v2: Vec<_>, x: usize) {
  if v1[x] == v2[x] &&
     v1.len() == v2.len() {}
}

The length-check is probably intended to guard against index-out-of-bounds access however it was (most likely mistakenly) placed AFTER the access by index. It should be at the front.

Categories (optional)

  • Kind: correctness

Inspired by #5780 and #5784

@matthiaskrgr matthiaskrgr added the A-lint Area: New lints label Jul 11, 2020
@GuillaumeGomez
Copy link
Member

I would even suggest to use get() instead. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

2 participants