From f25ccd9fb51d02f6f6f6e9289b2b3edf4261deb1 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Wed, 21 Feb 2024 08:41:11 +0100 Subject: [PATCH] Ignore 'implicit memory aliasing' rule for Go 1.22+ Signed-off-by: Janusz Marcinkiewicz --- README.md | 2 +- rules/implicit_aliasing.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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