github-vet / github-vet/rangeloop-pointer-findings
DisaDisa/tg_fun_bot: main.go; 60 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [DisaDisa/tg_fun_bot](https://www.github.com/DisaDisa/tg_fun_bot) at [main.go](https://github.com/DisaDisa/tg_fun_bot/blob/35cc23d52efdeb5594f66f0c9f63195372e5aec1/main.go#L45-L104)
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 update used in defer or goroutine at line 54
[Click here to see the code in its original context.](https://github.com/DisaDisa/tg_fun_bot/blob/35cc23d52efdeb5594f66f0c9f63195372e5aec1/main.go#L45-L104)
Click here to show the 60 line(s) of Go which triggered the analyzer.
```go
for update := range updates {
go func() {
for {
ticker := time.NewTicker(time.Minute)
select {
case <-ticker.C:
user, cnt := voter.Top()
reply := "Пидор дня: " + user + "\nC этим согласны " + strconv.Itoa(cnt) + " человек."
msg := tgbotapi.NewMessage(update.Message.Chat.ID, reply)
//msg.ReplyToMessageID = update.Message.MessageID
bot.Send(msg)
}
}
}()
if update.Message == nil {
continue
}
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
if update.Message.Command() == "" {
counter.Add(update.Message.From.UserName)
}
var reply string
switch update.Message.Command() {
case "status":
log.Printf("status command")
reply = counter.Status()
case "reset":
log.Printf("reset command")
counter.Init()
reply = "Done"
case "vote_pidor":
log.Printf("votePidor command")
text := update.Message.Text
for i := len(text); i > 0; i-- {
if text[i-1:i] == " " {
voter.Add(text[i:])
break
}
}
case "vote_status":
log.Printf("voteStatus command")
reply = voter.Status()
case "activate_day_top":
log.Printf("activate day top")
voter.ActivateDayTop(update.Message.Chat.ID, bot)
case "disactivate_day_top":
log.Printf("disactivate day top")
voter.DisactivateDayTop(update.Message.Chat.ID)
}
if reply != "" {
msg := tgbotapi.NewMessage(update.Message.Chat.ID, reply)
//msg.ReplyToMessageID = update.Message.MessageID
bot.Send(msg)
}
}
```
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: 35cc23d52efdeb5594f66f0c9f63195372e5aec1
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.