github-vet / github-vet/rangeloop-pointer-findings
andrewrk/hackerrank: botcleanv2/main.go; 14 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [andrewrk/hackerrank](https://www.github.com/andrewrk/hackerrank) at [botcleanv2/main.go](https://github.com/andrewrk/hackerrank/blob/c8f20d1fbce14c226e6377737884fbcfa0bc6150/botcleanv2/main.go#L318-L331)
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 dirtyCell is reassigned at line 323
[Click here to see the code in its original context.](https://github.com/andrewrk/hackerrank/blob/c8f20d1fbce14c226e6377737884fbcfa0bc6150/botcleanv2/main.go#L318-L331)
Click here to show the 14 line(s) of Go which triggered the analyzer.
```go
for _, dirtyCell := range(dirtyCells) {
cost := rectilinearDist(&dirtyCell, w.botPos)
// create a world in which we have moved to
// and cleaned that cell
simWorld := w.clone()
simWorld.botPos = &dirtyCell
simWorld.cells[dirtyCell.y][dirtyCell.x] = '-'
cost += computeCost(moveMap, simWorld)
if (lowestCostCell == nil || cost < lowestCost) {
var clone pos = dirtyCell
lowestCostCell = &clone
lowestCost = cost
}
}
```
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: c8f20d1fbce14c226e6377737884fbcfa0bc6150
Contributor guide
No contributing guide indexed for this repository
Research direction
Read botcleanv2/main.go lines 318-331 at commit c8f20d1fbce14c226e6377737884fbcfa0bc6150 and inspect how dirtyCell pointers are used in the range loop. Compare the behavior with the analyzer message, then leave the requested reaction classifying it as Bug, Mitigated, or Desirable Behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100