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

petersondmg/vigilantpi: led.go; 39 LoC

Open
#15,361 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 [petersondmg/vigilantpi](https://www.github.com/petersondmg/vigilantpi) at [led.go](https://github.com/petersondmg/vigilantpi/blob/0f73d04054b021d2301bd37f4e8be3e6bdba9971/led.go#L28-L66)

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 blinks used in defer or goroutine at line 54

[Click here to see the code in its original context.](https://github.com/petersondmg/vigilantpi/blob/0f73d04054b021d2301bd37f4e8be3e6bdba9971/led.go#L28-L66)

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

```go
for blinks := range times {
if ticker != nil {
stop <- struct{}{}
ticker.Stop()
ticker = nil
}

if blinks == 0 {
continue
}

ticker = time.NewTicker(blinkInterval)
go func() {
var on bool
pin.Low()

for {
select {
case <-ticker.C:
if on {
on = false
pin.Low()
continue
}
on = true

iterations := blinks * 2
stateDuration := blinkInterval / time.Duration(iterations)

for i := 0; i < iterations; i++ {
pin.Toggle()
time.Sleep(stateDuration)
}
case <-stop:
return
}
}
}()
}

```

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: 0f73d04054b021d2301bd37f4e8be3e6bdba9971

Contributor guide

No contributing guide indexed for this repository

Research direction

Review led.go lines 28-66, focusing on the range loop and the goroutine that uses blinks. Determine whether the reported range-loop capture is a real bug in this code, considering the ticker and stop behavior. Done means leaving the appropriate classification reaction on this issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
embedded-iot
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.