github / github/codeql

Want query to detect mutual assignment

Ouverte
#12,417 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
question
Langage dominant
CodeQL
Étoiles
10.1k
Forks
2.1k
Merge moyen
2 j 15 h
PR mergées (30 j)
141

Description

**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/

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.