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

madflojo/efs2: app/app.go; 54 LoC

Open
#18,136 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 [madflojo/efs2](https://www.github.com/madflojo/efs2) at [app/app.go](https://github.com/madflojo/efs2/blob/99859d0c5b7a7c379cb31de5b7e2af5cffdfb80b/app/app.go#L82-L135)

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 h used in defer or goroutine at line 87

[Click here to see the code in its original context.](https://github.com/madflojo/efs2/blob/99859d0c5b7a7c379cb31de5b7e2af5cffdfb80b/app/app.go#L82-L135)

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

```go
for _, h := range cfg.Hosts {
wg.Add(1)
go func() {
defer wg.Done()
c := clientCfg
c.Host = h
sh, err := ssh.Dial(c)
if err != nil {
errCount = errCount + 1
if !cfg.Quiet {
color.Red("%s: Error connecting to host - %s", h, err)
}
return
}
for i, t := range tasks {
if !cfg.Quiet {
color.Blue("%s: Executing Task %d - %s", h, i, t.Task)
}
if cfg.DryRun {
continue
}
if t.File.Source != "" {
err := sh.Put(t.File)
if err != nil {
errCount = errCount + 1
if !cfg.Quiet {
color.Red("%s: Error uploading file - %s", h, err)
}
return
}
if !cfg.Quiet {
color.Blue("%s: File upload successful", h)
}
}
if t.Command.Cmd != "" {
r, err := sh.Run(t.Command)
if err != nil {
errCount = errCount + 1
if !cfg.Quiet {
color.Red("%s: Error executing command - %s", h, err)
}
return
}
if !cfg.Quiet {
color.Blue("%s: %s", h, r)
}
}
}

}()
if !cfg.Parallel {
wg.Wait()
}
}

```

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: 99859d0c5b7a7c379cb31de5b7e2af5cffdfb80b

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.