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

Find suspicious duplicated assignments #981

Open
quasilyte opened this issue Apr 19, 2021 · 1 comment
Open

Find suspicious duplicated assignments #981

quasilyte opened this issue Apr 19, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@quasilyte
Copy link
Contributor

quasilyte commented Apr 19, 2021

PVS Studio is famous for its checks for copy/paste errors.

For example, there is a chance of writing this kind of code:

$x[0] = $v0;
$x[0] = $v1;

Or this:

$x[0] = $v0;
$x[1] = $v0;

It could be intermixed with something else:

// Questionable case: if unrelated() call can affect $x or $v variables,
// we should not report this code;
// but if unrelated() is pure, it should be safe?
$x[0] = $v0;
unrelated();
$x[1] = $v0;

Also bad:

$x[0] = $y;
$x[0] = $y;

We detect some cases with "unused" variable check. But it's worthwhile to verify that we don't miss some of these cases.

There are pitfalls that should be considered here to avoid false positives:

  • RHS should probably be pure
  • RHS (and LHS) should probably not contain the previously assigned value
  • and so on

These blocks should be analysed as "windows" of somewhat fixed size.

@quasilyte quasilyte changed the title Find suspicious duplicated statements Find suspicious duplicated assignments Apr 19, 2021
@i582
Copy link
Contributor

i582 commented Apr 19, 2021

It looks interesting.

@i582 i582 added the enhancement New feature or request label Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants