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

hydroscan/hydroscan-api: task/token_stats.go; 19 LoC

Open
#6,245 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 [hydroscan/hydroscan-api](https://www.github.com/hydroscan/hydroscan-api) at [task/token_stats.go](https://github.com/hydroscan/hydroscan-api/blob/a8882653a5aaf2dd2f9fa397400c160cef0488b3/task/token_stats.go#L36-L54)

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.

> function call which takes a reference to token at line 53 may start a goroutine

[Click here to see the code in its original context.](https://github.com/hydroscan/hydroscan-api/blob/a8882653a5aaf2dd2f9fa397400c160cef0488b3/task/token_stats.go#L36-L54)

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

```go
for _, token := range tokens {
result := QueryResult{}

models.DB.Raw("SELECT sum(volume_usd) AS volume24h FROM trades WHERE date > ? AND date <= ? AND (base_token_address = ? OR quote_token_address = ?)",
time24hAgo, timeNow, token.Address, token.Address).Scan(&result)
models.DB.Raw("SELECT sum(volume_usd) AS volume24h_last FROM trades WHERE date > ? AND date <= ? AND (base_token_address = ? OR quote_token_address = ?)",
time48hAgo, time24hAgo, token.Address, token.Address).Scan(&result)

// the minimum change is -1 (-100%), so using -2 represent not a number
var change float32 = -2
if !result.Volume24hLast.Equal(decimal.NewFromFloat32(0)) {
changeFloat64, _ := result.Volume24h.Sub(result.Volume24hLast).Div(result.Volume24hLast).Float64()
change = float32(changeFloat64)
}
// Using map[string]interface{} instead of models.Token since
// when update with struct, GORM will only update those fields that with non blank value
// nothing will be updated as "", 0, false are blank values of their types
models.DB.Model(&token).Updates(map[string]interface{}{"volume_24h": result.Volume24h, "volume_24h_change": change})
}

```

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

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.