github-vet / github-vet/rangeloop-pointer-findings

golangci/golangci-lint: test/testdata/exportloopref.go; 18 LoC

Open
#17,644 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [golangci/golangci-lint](https://www.github.com/golangci/golangci-lint) at [test/testdata/exportloopref.go](https://github.com/golangci/golangci-lint/blob/cfbbead393da0a0d3fce6b1fbe06a8666a64e377/test/testdata/exportloopref.go#L11-L28)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.

> reference to p is reassigned at line 14

[Click here to see the code in its original context.](https://github.com/golangci/golangci-lint/blob/cfbbead393da0a0d3fce6b1fbe06a8666a64e377/test/testdata/exportloopref.go#L11-L28)

Click here to show the 18 line(s) of Go which triggered the analyzer.

```go
for i, p := range []int{10, 11, 12, 13} {
printp(&p)
slice = append(slice, &p) // ERROR : "exporting a pointer for the loop variable p"
array[i] = &p // ERROR : "exporting a pointer for the loop variable p"
if i%2 == 0 {
ref = &p // ERROR : "exporting a pointer for the loop variable p"
str.x = &p // ERROR : "exporting a pointer for the loop variable p"
}
var vStr struct{ x *int }
var vArray [4]*int
var v *int
if i%2 == 0 {
v = &p
vArray[1] = &p
vStr.x = &p
}
_ = v
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: cfbbead393da0a0d3fce6b1fbe06a8666a64e377

Contributor guide

No contributing guide indexed for this repository

Research direction

Open test/testdata/exportloopref.go at the cited commit and inspect the range-loop pointer uses. Decide whether the analyzer warning is a Bug, Mitigated, or Desirable Behavior, then leave the corresponding reaction; completion is the classification reaction on this issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
devtools
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.