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

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

Open
#13,311 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/relayer_stats.go](https://github.com/hydroscan/hydroscan-api/blob/a8882653a5aaf2dd2f9fa397400c160cef0488b3/task/relayer_stats.go#L35-L53)

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.

>

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

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

```go
for _, relayer := range relayers {
result := QueryResult{}

models.DB.Raw("SELECT sum(volume_usd) AS volume24h FROM trades WHERE date > ? AND date <= ? AND relayer_address = ?",
time24hAgo, timeNow, relayer.Address).Scan(&result)
models.DB.Raw("SELECT sum(volume_usd) AS volume24h_last FROM trades WHERE date > ? AND date <= ? AND relayer_address = ?",
time48hAgo, time24hAgo, relayer.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.Relayer 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(&relayer).Updates(map[string]interface{}{"volume_24h": result.Volume24h, "volume_24h_change": change})
}

```

Click here to show extra information the analyzer produced.

```
No path was found through the callgraph that could lead to a function which writes a pointer argument.

No path was found through the callgraph that could lead to a function which passes a pointer to third-party code.

root signature {Model 1} was not found in the callgraph; reference was passed directly to third-party code
```

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.