diff --git a/README.md b/README.md index f7b41df..7063302 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ directory you can supply `./...` as the input argument. - G503: Import blocklist: crypto/rc4 - G504: Import blocklist: net/http/cgi - G505: Import blocklist: crypto/sha1 -- G601: Implicit memory aliasing of items from a range statement +- G601: Implicit memory aliasing of items from a range statement (only for Go 1.21 or lower) - G602: Slice access out of bounds ### Retired rules diff --git a/rules/implicit_aliasing.go b/rules/implicit_aliasing.go index a7eabb2..75de4ed 100644 --- a/rules/implicit_aliasing.go +++ b/rules/implicit_aliasing.go @@ -47,6 +47,12 @@ func doGetIdentExpr(expr ast.Expr, hasSelector bool) (*ast.Ident, bool) { } func (r *implicitAliasing) Match(n ast.Node, c *gosec.Context) (*issue.Issue, error) { + // This rule does not apply for Go 1.22, see https://tip.golang.org/doc/go1.22#language. + major, minor, _ := gosec.GoVersion() + if major >= 1 && minor >= 22 { + return nil, nil + } + switch node := n.(type) { case *ast.RangeStmt: // When presented with a range statement, get the underlying Object bound to