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

vsink/bsatool: bsatool.go; 72 LoC

Open
#15,900 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 [vsink/bsatool](https://www.github.com/vsink/bsatool) at [bsatool.go](https://github.com/vsink/bsatool/blob/d115aeda1b4ee1f252af1b9d5cab071646f1550f/bsatool.go#L6037-L6108)

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 fname used in defer or goroutine at line 6048

[Click here to see the code in its original context.](https://github.com/vsink/bsatool/blob/d115aeda1b4ee1f252af1b9d5cab071646f1550f/bsatool.go#L6037-L6108)

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

```go
for _, fname := range *files {
dndsPerGenomeAll[fname] = make(map[string]string)
geneDnDs[fname] = map[string]string{}
t1 := time.Now()
for _, allloc := range allLocuses {

// prod := getProductByName(allloc)
if len(altPositionsPerFile[fname][allloc]) > 2 {
dndsChan := make(chan []string)
go func() {

dndsChan <- getDnDsByLocus(allloc, altPositionsPerFile[fname][allloc])
}()
dndsRes, ok := <-dndsChan

// fmt.Println(fname, dndsRes)
if ok {

// if allloc == "Rv3879c" {

// fmt.Println(allloc, dndsRes, altPositions[allloc], fname)

// }

// fmt.Println(dndsRes)

// locDNDS[dndsRes[0]] = append(locDNDS[dndsRes[0]], dndsRes[1])
// if allloc == "Rv3854c" {
// fmt.Println(allloc, dndsRes, altPositions[allloc])
// }
// fmt.Println(allloc, dndsRes)
// locInGenome[fname][dndsRes[0]] = dndsRes[1]
if dndsRes[1] == "1.00" {
countNbrOne[allloc]++
countNeutral[fname]++
}
// close(dndsChan)
dndsPerGenomeAll[fname][dndsRes[0]] = dndsRes[1]
dndsFloat, _ = strconv.ParseFloat(dndsRes[1], 64)
geneDnDs[fname][allloc] = dndsRes[1]
if dndsFloat > 1 {
countPositive[fname]++
positiveGenes[fname] = append(positiveGenes[fname], allloc)
positiveGenesList = append(positiveGenesList, allloc)
positiveGenesCheck[allloc] = 1
} else if dndsFloat < 1 {
countNegative[fname]++
}
countNonZeroValues[allloc]++
}

} else {

// locDNDS[allloc] = append(locDNDS[allloc], "1")
// locInGenome[fname][allloc] = "1.00"
dndsPerGenomeAll[fname][allloc] = "1.00"
geneDnDs[fname][allloc] = "1.00"
// geneDnDs[fname][allloc] = "1.00"
countNeutral[fname]++
countNbrOne[allloc]++
}

}

// if *gbVerbose == true {
fmt.Printf("Calculating DN/DS: Working on %v from %v (%v) \t\t Time:\t%v\n", i, len(*files), fname, t1.Sub(t0))
// }
i++
// fmt.Println(locInGenome)
// fmt.Println(len(altPositions))

}

```

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Open bsatool.go around lines 6037-6108 and inspect the range over files and the goroutine reported at line 6048, including its use of fname. Determine whether the analyzer finding represents a bug, mitigated issue, or desirable behavior, then leave the corresponding reaction on this issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.