github / github/codeql

[Rust] Unused variable false positive in compound conditional statements

Aperta
#20,201 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
false-positive
Lingua principale
CodeQL
Stelle
10.1k
Fork
2.1k
Merge medio
2g 15h
PR unite (30g)
141

Descrizione

**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()`.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
rust
Ambito
security
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.