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

maistra/istio: tests/codecov/main.go; 34 LoC

Open
#11,722 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 [maistra/istio](https://www.github.com/maistra/istio) at [tests/codecov/main.go](https://github.com/maistra/istio/blob/e7fb8d5b3ef08aa161073ace01748f158f09690d/tests/codecov/main.go#L93-L126)

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 thresholdFile used in defer or goroutine at line 100

[Click here to see the code in its original context.](https://github.com/maistra/istio/blob/e7fb8d5b3ef08aa161073ace01748f158f09690d/tests/codecov/main.go#L93-L126)

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

```go
for _, thresholdFile := range files {
f, err := os.Open(thresholdFile)
if err != nil {
return nil, fmt.Errorf("failed to open threshold file, %s, %v", thresholdFile, err)
}
defer func() {
if err = f.Close(); err != nil {
glog.Errorf("failed to close file %s, %v", thresholdFile, err)
}
}()

scanner := bufio.NewScanner(f)

for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if strings.HasPrefix(line, "#") { // Skip comments
continue
}
m := thresholdRegxep.FindStringSubmatch(line)
if len(m) == 3 {
threshold, err := strconv.ParseFloat(strings.TrimSpace(m[2]), 64)
if err != nil {
return nil, fmt.Errorf("failed to parse threshold to float64 for package %s: %s, %v",
m[1], m[2], err)
}
thresholds[strings.TrimSpace(m[1])] = threshold
} else if len(line) > 0 { // The line is the package being ignored.
thresholds[strings.TrimSpace(line)] = 100
}
if scanner.Err() != nil {
return thresholds, scanner.Err()
}
}
}

```

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

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.