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

jacobsee/Aurora-Perceptron: histogram.go; 38 LoC

Open
#16,908 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 [jacobsee/Aurora-Perceptron](https://www.github.com/jacobsee/Aurora-Perceptron) at [histogram.go](https://github.com/jacobsee/Aurora-Perceptron/blob/f9eaafa71aff2b25f13667d733f313d308e2e133/histogram.go#L67-L104)

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 directory used in defer or goroutine at line 79

[Click here to see the code in its original context.](https://github.com/jacobsee/Aurora-Perceptron/blob/f9eaafa71aff2b25f13667d733f313d308e2e133/histogram.go#L67-L104)

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

```go
for _, directory := range directories {
files, err := ioutil.ReadDir(directory.DirectoryName)
if err != nil {
log.Fatal(err)
}
tempHistograms := make([]Histogram, len(files))
badImports := make([]int, len(files))

var wg sync.WaitGroup
wg.Add(len(files))
for index, file := range files {
go func(index int, fileName string) {
values, min, max, err := generateHistogram(directory.DirectoryName + "/" + fileName)
if err == nil {
tempHistograms[index] = Histogram{
FileName: fileName,
Classification: directory.Classification,
Data: values,
Min: min,
Max: max,
}
badImports[index] = -1
} else {
badImports[index] = 1
}
wg.Done()
}(index, file.Name())
}
// resync threads
wg.Wait()
// get rid of files in the directory that didn't import correctly
for index, value := range badImports {
if value == 1 {
tempHistograms = append(tempHistograms[:index], tempHistograms[index+1:]...)
}
}
histograms = append(histograms, tempHistograms...)
}

```

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

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.