github-vet / github-vet/rangeloop-pointer-findings
hscells/groove: rank/clf.go; 88 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [hscells/groove](https://www.github.com/hscells/groove) at [rank/clf.go](https://github.com/hscells/groove/blob/8c20ac6a00a1c672d22742c32e84ec993b088fb3/rank/clf.go#L550-L637)
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 552
[Click here to see the code in its original context.](https://github.com/hscells/groove/blob/8c20ac6a00a1c672d22742c32e84ec993b088fb3/rank/clf.go#L550-L637)
Click here to show the 88 line(s) of Go which triggered the analyzer.
```go
for i, candidate := range filteredCandidates {
go func() {
fmt.Printf("[%s] variation %d/%d\n", topic, i+1, len(filteredCandidates))
// String-ify the query.
s, err := transmute.CompileCqr2PubMed(candidate.Query)
if err != nil {
panic(err)
}
s:
// Obtain list of pmids.
tree, _, err := combinator.NewLogicalTree(pipeline.NewQuery(candidate.Topic, candidate.Topic, candidate.Query), e, fileCache)
if err != nil {
if options.Headway != nil {
go options.Headway.Message(err.Error())
}
fmt.Println(err)
goto s
}
pmids := tree.Documents(fileCache)
//pmids, err := e.Search(s)
//if err != nil {
// fmt.Println(err)
// goto s
//}
items := make(merging.Items, len(pmids))
for i, pmid := range pmids {
items[i] = merging.Item{Id: strconv.Itoa(int(pmid)), Score: 0}
}
// Create posting list for query.
//f:
//posting, err := newPostingFromPMIDS(pmids, topic+"_"+strconv.Itoa(int(hash(s))), indexPath, e)
//if err != nil {
// fmt.Println(err)
// goto f
//}
//// Use fusion technique to rank retrieved results and write results to file.
//res, err := clf(pipeline.NewQuery(topic, topic, candidate.Query), posting, e, options)
//if err != nil {
// return err
//}
err = writeResults(items.TRECResults(topic), path.Join(p, topic, strconv.Itoa(int(hash(s)))+".res.retrieved"))
if err != nil {
panic(err)
}
// Use fusion technique to rank only the relevant results and write to file.
//idealRes, err := clf(pipeline.NewQuery(topic, topic, candidate.Query), idealPosting, e, options)
//if err != nil {
// return err
//}
//err = writeResults(idealRes, path.Join(p, topic, strconv.Itoa(int(hash(s)))+".res.ideal"))
//if err != nil {
// return err
//}
// Write the query to file for posterity.
f, err := os.OpenFile(path.Join(p, topic, strconv.Itoa(int(hash(s)))+".qry"), os.O_CREATE|os.O_WRONLY, 0664)
if err != nil {
panic(err)
}
_, err = f.WriteString(s)
if err != nil {
panic(err)
}
err = f.Close()
if err != nil {
panic(err)
}
// Write the transformation ID.
f2, err := os.OpenFile(path.Join(p, topic, strconv.Itoa(int(hash(s)))+".t12n"), os.O_CREATE|os.O_WRONLY, 0664)
if err != nil {
panic(err)
}
_, err = f2.WriteString(strconv.Itoa(candidate.TransformationID))
if err != nil {
panic(err)
}
err = f2.Close()
if err != nil {
panic(err)
}
if options.Headway != nil {
go options.Headway.Send(float64(i), float64(len(filteredCandidates)), fmt.Sprintf("topic [%s]", topic), "")
}
}()
}
```
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: 8c20ac6a00a1c672d22742c32e84ec993b088fb3
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.