Skip to content

fix rowserrcheck reports false positive #1670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4
github.com/jgautheron/goconst v0.0.0-20201117150253-ccae5bf973f3
github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a
github.com/jingyugao/rowserrcheck v0.0.0-20210130005344-c6a0c12dd98d
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3
github.com/kulti/thelper v0.2.1
github.com/kunwardeep/paralleltest v1.0.2
Expand Down
7 changes: 3 additions & 4 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions test/testdata/rowserrcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package testdata

import (
"database/sql"
"fmt"
"math/rand"
)

func RowsErrNotChecked(db *sql.DB) {
Expand All @@ -11,3 +13,27 @@ func RowsErrNotChecked(db *sql.DB) {

}
}

func issue943(db *sql.DB) {
var rows *sql.Rows
var err error

if rand.Float64() < 0.5 {
rows, err = db.Query("select 1")
} else {
rows, err = db.Query("select 2")
}
if err != nil {
panic(err)
}

defer rows.Close()

for rows.Next() {
fmt.Println("new rows")
}

if err := rows.Err(); err != nil {
panic(err)
}
}