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

YaleOpenLab/opensolar: rpc/developer.go; 60 LoC

Open
#10,782 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [YaleOpenLab/opensolar](https://www.github.com/YaleOpenLab/opensolar) at [rpc/developer.go](https://github.com/YaleOpenLab/opensolar/blob/b20446471b4d82ec42b3b0de3fbb3ef9fef4ce46/rpc/developer.go#L181-L240)

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 project used in defer or goroutine at line 204

[Click here to see the code in its original context.](https://github.com/YaleOpenLab/opensolar/blob/b20446471b4d82ec42b3b0de3fbb3ef9fef4ce46/rpc/developer.go#L181-L240)

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

```go
for i, project := range projects {
var x entityDashboardData
x.ExploreTab = make(map[string]interface{})
x.ExploreTab = project.Content.Details["Explore Tab"]
x.Role = "You are an Offtaker"
sStage, err := utils.ToString(project.Stage)
if err != nil {
log.Println(err)
erpc.MarshalSend(w, erpc.StatusInternalServerError)
return
}
x.PSA.Stage = "Project is in Stage: " + sStage
x.PSA.Actions = []string{"Contractor Actions", "No pending action"}
x.ProjectWallets.Wallets = make([][]string, 2)

var escrowBalance string

var wg sync.WaitGroup

if consts.Mainnet {
wg.Add(1)
go func(wg *sync.WaitGroup) {
defer wg.Done()
escrowBalance, err = utils.ToString(xlm.GetAssetBalance(project.EscrowPubkey, consts.AnchorUSDCode))
if err != nil {
log.Println(err)
}
}(&wg)

wg.Add(1)
go func(wg *sync.WaitGroup) {
defer wg.Done()
ret.YourWallet.ProjectWalletBalance += xlm.GetAssetBalance(project.EscrowPubkey, consts.AnchorUSDCode)
}(&wg)
} else {
wg.Add(1)
go func(wg *sync.WaitGroup) {
defer wg.Done()
escrowBalance, err = utils.ToString(xlm.GetAssetBalance(project.EscrowPubkey, consts.StablecoinCode))
if err != nil {
log.Println(err)
}
}(&wg)

wg.Add(1)
go func(wg *sync.WaitGroup) {
defer wg.Done()
ret.YourWallet.ProjectWalletBalance += xlm.GetAssetBalance(project.EscrowPubkey, consts.StablecoinCode)
}(&wg)
}

wg.Wait()

x.ProjectWallets.Wallets[0] = []string{"Project Escrow Wallet: " + project.EscrowPubkey, escrowBalance}
x.ProjectWallets.Wallets[1] = []string{"Renewable Energy Certificates (****BBDJL)", "10"}
x.PendingPayments = []string{"Your Pending Payment", "$203 due on April 30"}
x.Documents = project.Content.Details["Documents"]

ret.YourProjects[i] = x
}

```

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.