github / github/codeql

[Rust] Unused variable false positive in compound conditional statements

未關閉
#20,201 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
false-positive
主要語言
CodeQL
星號
10.1k
分支
2.1k
平均合併
2 天 15 小時
30 天內合併 PR
141

描述

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

貢獻指南

開啟貢獻指南

研究方向

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.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
rust
領域
security
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。