Skip to content

Commit

Permalink
Ignore 'implicit memory aliasing' rule for Go 1.22+
Browse files Browse the repository at this point in the history
Signed-off-by: Janusz Marcinkiewicz <januszm@nvidia.com>
  • Loading branch information
VirrageS authored and ccojocar committed Mar 4, 2024
1 parent 582e91a commit f25ccd9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions rules/implicit_aliasing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f25ccd9

Please sign in to comment.