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

spatialmodel/inmap: emissions/slca/population.go; 42 LoC

Open
#9,709 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 [spatialmodel/inmap](https://www.github.com/spatialmodel/inmap) at [emissions/slca/population.go](https://github.com/spatialmodel/inmap/blob/ee84ff451b79e26405e00128457cb6d0f15be5a3/emissions/slca/population.go#L235-L276)

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 popType used in defer or goroutine at line 252

[Click here to see the code in its original context.](https://github.com/spatialmodel/inmap/blob/ee84ff451b79e26405e00128457cb6d0f15be5a3/emissions/slca/population.go#L235-L276)

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

```go
for mortType, popType := range c.MortalityRateColumns {
oT := make([]float64, len(cells))
pi, ok := popIndices[popType]
if !ok {
panic(fmt.Errorf("missing population type %s", popType))
}
mi, ok := mortIndices[mortType]
if !ok {
panic(fmt.Errorf("missing mortality type %s", mortType))
}

var wg sync.WaitGroup
wg.Add(ncpu)
for p := 0; p < ncpu; p++ {
go func(p, pi int, oT []float64) {
for i := p; i < len(cells); i += ncpu {
g := cells[i]
if griddedPop[popType][i] == 0 {
continue
}
var popTotal float64
var mPop float64
cellPop := popIndex.SearchIntersect(g.Bounds())
for _, mI := range mortIndex.SearchIntersect(g.Bounds()) {
m := mI.(*mortality)
for _, pI := range cellPop {
p := pI.(*population)
popTemp := p.Polygonal.Intersection(g).Intersection(m.Polygonal).Area() / p.Area() * p.PopData[pi]
mPop += m.Io[mi] * popTemp
popTotal += popTemp
}
}
if popTotal != 0 {
oT[i] = mPop / popTotal
}
}
wg.Done()
}(p, pi, oT)
}
wg.Wait()
o[popType] = oT
}

```

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

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.