github / github/codeql

[Rust] Unused variable false positive in compound conditional statements

Ouverte
#20,201 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
false-positive
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 false positive**

When there is an if-let statement, and multiple conditions exist in the conditional check (either AND or OR as operators), CodeQL flags the original variable as unused if it is used in subsequent conditional statements.

**Code samples or links to source code**

There are many dismissed false positives linked to this merged PR:

A small example would be:

```rust
for result in builder.build() {
match result {
Ok(entry) => {
if let Some(file_type) = entry.file_type()
&& file_type.is_file()
{
paths.push(entry.path().to_path_buf());
}
}
Err(msg) => eprintln!("Error reading entry: {msg}"),
}
}
```

Here, `file_type` was flagged as a false positive, even though it is used in the following boolean statement `file_type.is_file()`.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Start by reproducing the Rust example and compare it with the dismissed false positives linked from seiri PR 57. Trace the CodeQL unused-variable analysis for if-let conditions with compound boolean operators; no source file or test is named in the issue. Done means the variable is no longer reported when used in a subsequent condition, with coverage for the shown case.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
rust
Domaine
security
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

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