Go: go/comparison-of-identical-expressions false positive when a variable is reassigned in a range loop (go-all 8.0.0)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 54/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- go
- 領域
- testing-qa
調査の方向性
Start by reproducing the false positive with the Go samples in the issue and the two versions of CompareIdenticalValues.ql; compare results with go-all 7.3.2 and 8.0.0. Investigate how the range-loop CFG handles assignments that flow past the loop, and check whether related data-flow queries are affected. Done when the range-loop comparison is no longer reported while the issue’s other cases behave as expected.
索引モデルが issue の本文から書いたものです。
説明
Description of the false positive
Since codeql/go-queries 1.6.12 (with codeql/go-all 8.0.0), go/comparison-of-identical-expressions reports a comparison between a variable and the value it was initialised from, even though the variable may be reassigned inside a range loop between the two. With codeql/go-queries 1.6.11 (codeql/go-all 7.3.2), the same database gives no result.
The trigger is the range loop. The same assignment in a plain if or in a three-clause for loop is not reported. It looks related to the CFG rewrite in go-all 8.0.0, whose changelog mentions range statements. If assignments in a range body don't reach the code after the loop, other data-flow queries might be affected as well. I have only checked this query.
Code samples or links to source code
package repro
// Reported (line "if n == c"): n may be raised inside the range loop.
func Settle(c int, xs []int) int {
for {
n := c
for _, x := range xs {
if x > n {
n = x
}
}
if n == c { // <- "This expression compares an expression to itself."
break
}
c = n
}
return c
}
// Also reported: unconditional assignment in a range loop.
func VariantD(c int, xs []int) int {
n := c
for _, x := range xs {
n = x
}
if n == c { // <- reported
return 0
}
return n
}
// Not reported: the same assignment in a three-clause loop.
func VariantB(c int, xs []int) int {
n := c
for i := 0; i < len(xs); i++ {
if xs[i] > n {
n = xs[i]
}
}
if n == c {
return 0
}
return n
}
To reproduce (CodeQL CLI 2.27.1, macOS arm64, Go 1.25.13). --no-tracing is used only because this machine has no Rosetta for the tracer.
codeql database create db --language=go --source-root src --build-mode=autobuild --no-tracing
codeql database analyze db codeql/[email protected]:RedundantCode/CompareIdenticalValues.ql --format=sarif-latest --output=a.sarif --rerun
codeql database analyze db codeql/[email protected]:RedundantCode/CompareIdenticalValues.ql --format=sarif-latest --output=b.sarif --rerun
a.sarif, go-queries 1.6.11 / go-all 7.3.2: 0 results.b.sarif, go-queries 1.6.12 / go-all 8.0.0: 3 results:Settle,VariantD, and a third range-loop variant without the outer loop.
Without --rerun, the second command silently reuses the first command's cached results: its SARIF reports go-queries 1.6.11 and 0 results. This may be worth a look separately.
The same comparison is reported in real code here: https://github.com/gomaja/go-asn1/blob/2e83d89af0dc815fc1e0a589691032aa069153bc/runtime/ber/named_bit_size.go#L43. In that code, next starts as candidate and can be raised inside the range loop over the permitted intervals.
- 主要言語
- CodeQL
- スター
- 10.2k
- フォーク
- 2.1k
- 平均マージ
- 2日 15時間
- マージ済み PR(30日)
- 153
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
github/codeql のほかの issue
-
false-positive javascript
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
github/codeql#22632 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Add AlertSuppression.ql for Rust (inline // codeql[...] suppression)対応中かも @cnuss が 196 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
github/codeql#21637 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
false-positive
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
github/codeql#21076 · コメント 3 件 · リアクション 3 件 ·
メンテナーはふだん 1 日以内に返信
-
question
難易度 4/5 1週間以上 初心者へのやさしさ 18/100
メンテナーはふだん 1 日以内に返信
-
bug Swift
難易度 4/5 3〜5日 初心者へのやさしさ 15/100
github/codeql#22803 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
tesseract-ocr/tesseract#4653 ·
メンテナーはふだん 1 日以内に返信
-
Four problem loader browser tests fail on Windows対応中かも @Patriciaath999 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
good first issue help wanted windows
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
-
HttpRequestTrait fatals on WordPress 7.2: $blocked_http_requests clashes with WP_UnitTestCase_Baseオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
test_pgbouncer deploys the server under test from Charmhub instead of the local build (track/1.31)オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
canonical/temporal-k8s-operator#195 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信