github-vet / github-vet/rangeloop-pointer-findings
Selsynn/cbepbackend: business/characters/npc.go; 11 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [Selsynn/cbepbackend](https://www.github.com/Selsynn/cbepbackend) at [business/characters/npc.go](https://github.com/Selsynn/cbepbackend/blob/f01abd83bbf7ce9889ba940ff5af100874f570c6/business/characters/npc.go#L68-L78)
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 w is reassigned at line 71
[Click here to see the code in its original context.](https://github.com/Selsynn/cbepbackend/blob/f01abd83bbf7ce9889ba940ff5af100874f570c6/business/characters/npc.go#L68-L78)
Click here to show the 11 line(s) of Go which triggered the analyzer.
```go
for _, w := range n.workQueue {
w.WorkProgress += units
if (ref.WorkCost - ref.WorkProgress) > (w.WorkCost - w.WorkProgress) {
ref = &w
}
if a.ID == ref.Player.ID {
//warning there should not have any work already in progress with that npc
//return ActionNotAllowedErr
return errors.Wrapf(ActionNotAllowedErr, "Player %s cannot have new item with NPC %s as there is already the item %s ", a.ID, n.Name, w.Item.Name)
}
}
```
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: f01abd83bbf7ce9889ba940ff5af100874f570c6
Contributor guide
No contributing guide indexed for this repository
Research direction
Read business/characters/npc.go at lines 68-78 and review the range-loop handling of w, including its progress update and reassignment to ref. Confirm whether the reported reference behavior can select or mutate the wrong NPC, then classify the finding or document the verified behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100