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

SSSaaS/sssaas-golang: sssaas-golang.go; 66 LoC

Open
#9,818 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 [SSSaaS/sssaas-golang](https://www.github.com/SSSaaS/sssaas-golang) at [sssaas-golang.go](https://github.com/SSSaaS/sssaas-golang/blob/8afc5aa8b404246771a673d60cc80f312a75868f/sssaas-golang.go#L90-L155)

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 i used in defer or goroutine at line 97

[Click here to see the code in its original context.](https://github.com/SSSaaS/sssaas-golang/blob/8afc5aa8b404246771a673d60cc80f312a75868f/sssaas-golang.go#L90-L155)

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

```go
for i := range endpoints {
wg.Add(1)
go func() {
client := &http.Client{
Timeout: duration,
}

req, err := http.NewRequest("GET", endpoints[i], nil)
if err != nil {
global_err = append(global_err, err)

if !done {
wg.Done()
}
return
}

req.Header.Set("User-Agent", "sssaas-golang v0 v0.0.1")
res, err := client.Do(req)
if err != nil {
global_err = append(global_err, err)

if !done {
wg.Done()
}
return
}

if res.StatusCode != 200 {
global_err = append(global_err, errors.New(strconv.Itoa(res.StatusCode)+":"+res.Status))

if !done {
wg.Done()
}
} else {
defer res.Body.Close()
data, err := ioutil.ReadAll(res.Body)
if err != nil {
global_err = append(global_err, err)
}

current := response{}

err = json.Unmarshal([]byte(data), ¤t)
if err != nil {
global_err = append(global_err, err)
}

for j := range current.SharedSecrets {
results = append(results, current.SharedSecrets[j])
}
}

results = removeDuplicates(results)

if len(results) >= minimum && !done {
done = true
for _ = range endpoints {
wg.Done()
}
}
if !done {
wg.Done()
}
}()
}

```

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: 8afc5aa8b404246771a673d60cc80f312a75868f

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.