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

hscells/groove: analysis/reachability.go; 85 LoC

Open
#7,661 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 [hscells/groove](https://www.github.com/hscells/groove) at [analysis/reachability.go](https://github.com/hscells/groove/blob/8c20ac6a00a1c672d22742c32e84ec993b088fb3/analysis/reachability.go#L277-L361)

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 q used in defer or goroutine at line 285

[Click here to see the code in its original context.](https://github.com/hscells/groove/blob/8c20ac6a00a1c672d22742c32e84ec993b088fb3/analysis/reachability.go#L277-L361)

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

```go
for _, q := range queries {
var objectives, typeOfStudy, referenceStandards, participants, indexTests, targetConditions, title []metawrap.MappingCandidate

var wg0 sync.WaitGroup
wg0.Add(1)
go func() {
defer wg0.Done()
var err error
p := protocols[q.Topic]
objectives, err = client.Candidates(p.Objective)
if err != nil {
return
}
typeOfStudy, err = client.Candidates(p.TypeOfStudy)
if err != nil {
return
}
referenceStandards, err = client.Candidates(p.ReferenceStandards)
if err != nil {
return
}
participants, err = client.Candidates(p.Participants)
if err != nil {
return
}
indexTests, err = client.Candidates(p.IndexTests)
if err != nil {
return
}
targetConditions, err = client.Candidates(p.TargetConditions)
if err != nil {
return
}
title, err = client.Candidates(q.Name)
if err != nil {
return
}
}()

keywords := QueryKeywords(q.Query)
var queryCandidates []metawrap.MappingCandidate
var wg1 sync.WaitGroup
for _, kw := range keywords {
wg1.Add(1)
go func(k cqr.Keyword) {
defer wg1.Done()
candidates, err := client.Candidates(kw.QueryString)
if err != nil {
return
}
queryCandidates = append(queryCandidates, candidates...)
}(kw)
}

wg1.Wait()
wg0.Wait()

fieldConcepts := map[string][]metawrap.MappingCandidate{
"Objectives": objectives,
"Type Of Study": typeOfStudy,
"Reference Standards": referenceStandards,
"Participants": participants,
"Index Tests": indexTests,
"Target Conditions": targetConditions,
"Title": title,
}

for field, candidates := range fieldConcepts {
for _, candidate := range candidates {
v, _ := strconv.Atoi(candidate.CandidateScore)
score := math.Abs(float64(v))
found := false
for _, queryCandidate := range queryCandidates {
if queryCandidate.CandidateCUI == candidate.CandidateCUI {
inQuery[field] = append(inQuery[field], score)
found = true
break
}
}
if !found {
notInQuery[field] = append(notInQuery[field], score)
}
}
}
}

```

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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.