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

jogi1/golang-mvd: events.go; 61 LoC

Open
#8,038 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 [jogi1/golang-mvd](https://www.github.com/jogi1/golang-mvd) at [events.go](https://github.com/jogi1/golang-mvd/blob/760ffca1a46ddb24b8ca3045c5716cc976438a30/events.go#L12-L72)

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.

> reference to __player is reassigned at line 13

[Click here to see the code in its original context.](https://github.com/jogi1/golang-mvd/blob/760ffca1a46ddb24b8ca3045c5716cc976438a30/events.go#L12-L72)

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

```go
for _, __player := range parser.mvd.State.Players {
player := &__player
player_num := int(player.EventInfo.Pnum)
stat := &parser.stats[player_num]
if player.EventInfo.Events == 0 {
continue
}
p := &parser.mvd.State_last_frame.Players[player.EventInfo.Pnum]
if p.Userid != player.Userid {
// @TODO: Handle this better
return
}
if player.EventInfo.Events&mvdreader.PE_STATS == mvdreader.PE_STATS {
if player.Health > 0 && p.Health <= 0 {
e := Event_Player{EPT_Spawn, player_num}
parser.events = append(parser.events, e)
}

if player.Frags > p.Frags {
stat.Kills += player.Frags - p.Frags
e := Event_Player{EPT_Kill, player_num}
parser.events = append(parser.events, e)
}
if player.Health <= 0 && p.Health > 0 {
stat.Deaths += 1
e := Event_Player{EPT_Death, player_num}
parser.events = append(parser.events, e)
}

if player.Frags < p.Frags {
if player.Health <= 0 {
stat.Suicides += 1
e := Event_Player{EPT_Suicide, player_num}
parser.events = append(parser.events, e)
} else {
stat.Teamkills += 1
e := Event_Player{EPT_Teamkill, player_num}
parser.events = append(parser.events, e)
}
}

if player.Items != p.Items {
itemstat := &parser.stats[player.EventInfo.Pnum]
itemstat.SuperShotgun.CheckItem(parser, mvdreader.IT_SUPER_SHOTGUN, player, p)
itemstat.NailGun.CheckItem(parser, mvdreader.IT_NAILGUN, player, p)
itemstat.SuperNailGun.CheckItem(parser, mvdreader.IT_SUPER_NAILGUN, player, p)
itemstat.GrenadeLauncher.CheckItem(parser, mvdreader.IT_GRENADE_LAUNCHER, player, p)
itemstat.RocketLauncher.CheckItem(parser, mvdreader.IT_ROCKET_LAUNCHER, player, p)
itemstat.LightningGun.CheckItem(parser, mvdreader.IT_LIGHTNING, player, p)

itemstat.GreenArmor.CheckItem(parser, mvdreader.IT_ARMOR1, player, p)
itemstat.YellowArmor.CheckItem(parser, mvdreader.IT_ARMOR2, player, p)
itemstat.RedArmor.CheckItem(parser, mvdreader.IT_ARMOR3, player, p)

itemstat.MegaHealth.CheckItem(parser, mvdreader.IT_SUPERHEALTH, player, p)
itemstat.Quad.CheckItem(parser, mvdreader.IT_QUAD, player, p)
itemstat.Pentagram.CheckItem(parser, mvdreader.IT_INVULNERABILITY, player, p)
itemstat.Ring.CheckItem(parser, mvdreader.IT_INVISIBILITY, player, p)
}
}
}

```

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: 760ffca1a46ddb24b8ca3045c5716cc976438a30

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.