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

C++: Promote cpp/unsigned-difference-expression-compared-zero to Code Scanning #16982

Conversation

MathiasVP
Copy link
Contributor

@MathiasVP MathiasVP commented Jul 15, 2024

All results flagged up by MRVA are either clear TPs, or FPs because of bad code. I consider "bad code" to be code such as:

/** INVARIANT: x >= y */
void foo(unsigned x, unsigned y) {
  if(x - y > 0) {
    // ...
  } else {
    // x >= y and x - y <= 0 so x == y.
  }
}

and rewriting this to something like:

void foo(unsigned x, unsigned y) {
  if(x > y) {
    // ...
  } else {
    // ...
  }
}

or even (if that was the intended meaning):

void foo(unsigned x, unsigned y) {
  if(x != y) {
    // ...
  } else {
    // ...
  }
}

is much clearer and less error-prone. As an added bonus, all of these alerts should be easily auto-fixable.

@MathiasVP MathiasVP force-pushed the promote-unsigned-difference-expression-compared-zero-to-code-scanning branch from 16ed628 to 5f70c44 Compare July 17, 2024 10:44
@MathiasVP MathiasVP marked this pull request as ready for review July 25, 2024 12:56
@MathiasVP MathiasVP requested a review from a team as a code owner July 25, 2024 12:56
@jketema
Copy link
Contributor

jketema commented Jul 25, 2024

What was your assessment of the DCA results?

@MathiasVP
Copy link
Contributor Author

DCA results were all good. There were two clear FPs on DCA which were subsequently fixed in #16988. The remaining ones fit the above description (where a - b > 0 really should be replaced with a > b)

@MathiasVP
Copy link
Contributor Author

DCA looks good to me. The alerts are the same as the previous DCA run with the exception of two removed FPs that disappeared in #16988 🎉

Performance looks totally unchanged.

@MathiasVP MathiasVP merged commit 30abc95 into github:main Jul 25, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants