You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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.
Description of the issue
Here is a minimal test case showing mutual assignment where we do
b = a;followed bya = b;: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/
The text was updated successfully, but these errors were encountered: