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

PUMATeam/catapult: pkg/services/host.go; 25 LoC

Open
#15,934 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 [PUMATeam/catapult](https://www.github.com/PUMATeam/catapult) at [pkg/services/host.go](https://github.com/PUMATeam/catapult/blob/b39efbf765fa2f8e1b5946be3782e5348a9d354a/pkg/services/host.go#L46-L70)

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 at line 51 passes reference to host to third-party code

[Click here to see the code in its original context.](https://github.com/PUMATeam/catapult/blob/b39efbf765fa2f8e1b5946be3782e5348a9d354a/pkg/services/host.go#L46-L70)

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

```go
for _, host := range hosts {
address := fmt.Sprintf("%s:%d", host.Address, host.Port)
switch host.Status {
case model.INSTALLING:
hs.log(ctx, host.Name).Info("Host in status INSTALLING, moving to DOWN")
hs.UpdateHostStatus(ctx, &host, model.DOWN)
case model.UP:
// Set host status to INITIALIZING during intialization
hs.UpdateHostStatus(ctx, &host, model.INITIALIZING)
go func(h *model.Host) {
defer wg.Done()
wg.Add(1)
_, err := hs.connManager.Connect(ctx, address)

if err == nil {
hs.UpdateHostStatus(ctx, h, model.UP)
} else {
hs.log(ctx, h.Name).Error("Failed to initialize host connection")

errors = append(errors, err)
hs.UpdateHostStatus(ctx, h, model.DOWN)
}
}(&host)
}
}

```

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.

The following graphviz dot graph describes paths through the callgraph that could lead to a function which passes a pointer to third-party code:
digraph G {
"(UpdateHostStatus, 3)" -> {"(updateHostStatus, 3)";}
"(updateHostStatus, 3)" -> {"(UpdateHost, 2)";}
"(UpdateHost, 2)" -> {}
}

```

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

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.