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

Want query to detect mutual assignment #12417

Open
ryao opened this issue Mar 7, 2023 · 2 comments
Open

Want query to detect mutual assignment #12417

ryao opened this issue Mar 7, 2023 · 2 comments
Labels
question Further information is requested

Comments

@ryao
Copy link

ryao commented Mar 7, 2023

Description of the issue

Here is a minimal test case showing mutual assignment where we do b = a; followed by a = b;:

int main(void) {
        int a = 0;
        int b = a;
        int c = 1;
        a = b;
        return a*b*c;
}

The statement a = b; is redundant. Unless the variables are marked volatile, there should be no legitimate reason for code to do this. We just found an instance of this in OpenZFS:

https://github.com/openzfs/zfs/pull/14565/files#r1124115812

A quick search revealed that PVS Studio has a check for this:

https://pvs-studio.com/en/docs/warnings/v587/

@ryao ryao added the question Further information is requested label Mar 7, 2023
@tausbn
Copy link
Contributor

tausbn commented Mar 7, 2023

Thank you for your suggestion! I will forward it to the C/C++ team.

I will note, however, that as we are currently focusing on improving our security queries (and since this seems to be more of a "code correctness" query with no immediate security consequences), it may be a while before your suggestion gets addressed.

@jketema
Copy link
Contributor

jketema commented May 2, 2023

The C/C++ team discussed this, and as this is not security related we will indeed not schedule this any time soon. Do note that we accept external contributions. Hence, I'd like to encourage you to develop a query yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants