github-vet / github-vet/rangeloop-pointer-findings
netwayfind/cp-scoring: server/server.go; 37 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [netwayfind/cp-scoring](https://www.github.com/netwayfind/cp-scoring) at [server/server.go](https://github.com/netwayfind/cp-scoring/blob/4637ade4e5cdde3a4cfc7a2914929f18a3ec0832/server/server.go#L2137-L2173)
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.
> range-loop variable hostToken used in defer or goroutine at line 2146
[Click here to see the code in its original context.](https://github.com/netwayfind/cp-scoring/blob/4637ade4e5cdde3a4cfc7a2914929f18a3ec0832/server/server.go#L2137-L2173)
Click here to show the 37 line(s) of Go which triggered the analyzer.
```go
for i, hostToken := range hostTokens {
if firstHostToken {
firstHostToken = false
} else {
w.Write([]byte(","))
}
w.Write([]byte(fmt.Sprintf("\"%d - %s\": [", i, hostnames[hostToken])))
out := make(chan processing.DocumentDiff)
go func() {
err := theServer.backingStore.SelectStateDiffs(hostToken, timeStart, timeEnd, out)
if err != nil {
msg := "ERROR: cannot retrieve state diffs;"
log.Println(msg, err)
http.Error(w, msg, http.StatusInternalServerError)
return
}
}()
firstOut := true
for diff := range out {
if firstOut {
firstOut = false
} else {
w.Write([]byte(","))
}
b, err := json.Marshal(diff)
if err != nil {
msg := "ERROR: cannot marshall state diffs;"
log.Println(msg, err)
http.Error(w, msg, http.StatusInternalServerError)
return
}
w.Write(b)
}
w.Write([]byte("]"))
}
```
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: 4637ade4e5cdde3a4cfc7a2914929f18a3ec0832
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.