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

TRON-US/go-btfs: core/commands/swarm.go; 24 LoC

Open
#12,742 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 [TRON-US/go-btfs](https://www.github.com/TRON-US/go-btfs) at [core/commands/swarm.go](https://github.com/TRON-US/go-btfs/blob/bf18415cf63962bb94168971c262af41e95d7a57/core/commands/swarm.go#L421-L444)

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 ainfo was used in a composite literal at line 422

[Click here to see the code in its original context.](https://github.com/TRON-US/go-btfs/blob/bf18415cf63962bb94168971c262af41e95d7a57/core/commands/swarm.go#L421-L444)

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

```go
for _, ainfo := range addrs {
maddrs, err := peer.AddrInfoToP2pAddrs(&ainfo)
if err != nil {
return err
}
// FIXME: This will print:
//
// disconnect QmFoo success
// disconnect QmFoo success
// ...
//
// Once per address specified. However, I'm not sure of
// a good backwards compat solution. Right now, I'm just
// preserving the current behavior.
for _, addr := range maddrs {
msg := "disconnect " + ainfo.ID.Pretty()
if err := api.Swarm().Disconnect(req.Context, addr); err != nil {
msg += " failure: " + err.Error()
} else {
msg += " success"
}
output = append(output, msg)
}
}

```

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: bf18415cf63962bb94168971c262af41e95d7a57

Contributor guide

No contributing guide indexed for this repository

Research direction

Read core/commands/swarm.go around lines 421-444, focusing on the range loop and the &ainfo passed to AddrInfoToP2pAddrs. Check whether the reported pointer-to-range-variable behavior affects this command and whether the current behavior is intentional; done means leaving the requested Bug, Mitigated, or Desirable Behavior classification with evidence.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.