github-vet / github-vet/rangeloop-pointer-findings
AnatolyShirykalov/msu_go: 4/99_homework/game-2/src/main/main.go; 52 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [AnatolyShirykalov/msu_go](https://www.github.com/AnatolyShirykalov/msu_go) at [4/99_homework/game-2/src/main/main.go](https://github.com/AnatolyShirykalov/msu_go/blob/d31b0eb0f66d46263a17a688390a28e5dae260c1/4/99_homework/game-2/src/main/main.go#L76-L127)
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 100
[Click here to see the code in its original context.](https://github.com/AnatolyShirykalov/msu_go/blob/d31b0eb0f66d46263a17a688390a28e5dae260c1/4/99_homework/game-2/src/main/main.go#L76-L127)
Click here to show the 52 line(s) of Go which triggered the analyzer.
```go
for update := range updates {
var message tgbotapi.MessageConfig
answer := ""
if update.Message.Text == "DELETE PLAYERS" && update.Message.Chat.UserName == "albina_artist" {
gamers := ""
flag := false
for name := range Gamers {
if flag {
gamers += ", " + name
} else {
gamers += name
flag = true
}
}
answer = fmt.Sprintf("вышло из игры %d: %s", len(Gamers), gamers)
DeletePlayers()
}
if _, ok := Gamers[update.Message.Chat.FirstName]; !ok {
if update.Message.Text == "/start" {
answer = update.Message.Chat.FirstName + ", начнем играть 0_0"
}
Gamers[update.Message.Chat.FirstName] = NewPlayer(update.Message.Chat.FirstName)
mu := &sync.Mutex{}
go func() {
for msg := range Gamers[update.Message.Chat.FirstName].GetOutput() {
mu.Lock()
lastOutput[update.Message.Chat.FirstName] = msg
log.Printf("Authorized on account %s", update.Message.Chat.FirstName+msg)
mu.Unlock()
}
}()
if len(Gamers) == 1 {
InitGame()
}
AddPlayer(Gamers[update.Message.Chat.FirstName])
} else {
if update.Message.Text == "/start" {
answer = update.Message.Chat.FirstName + ", ты уж в игре)"
}
}
if answer == "" {
lastOutput = map[string]string{}
Gamers[update.Message.Chat.FirstName].HandleInput(update.Message.Text)
time.Sleep(time.Microsecond)
runtime.Gosched() // дадим считать ответ
answer = lastOutput[update.Message.Chat.FirstName]
}
message = tgbotapi.NewMessage(update.Message.Chat.ID, answer)
message.ReplyMarkup = tgbotapi.NewReplyKeyboard(buttons[0])
bot.Send(message)
}
```
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: d31b0eb0f66d46263a17a688390a28e5dae260c1
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.