github-vet / github-vet/rangeloop-pointer-findings
crimsonfaith91/bgd-operator: main.go; 24 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [crimsonfaith91/bgd-operator](https://www.github.com/crimsonfaith91/bgd-operator) at [main.go](https://github.com/crimsonfaith91/bgd-operator/blob/a1012d91f445c401433b757a91a9afd7ece2286e/main.go#L121-L144)
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 curRS was used in a composite literal at line 133
[Click here to see the code in its original context.](https://github.com/crimsonfaith91/bgd-operator/blob/a1012d91f445c401433b757a91a9afd7ece2286e/main.go#L121-L144)
Click here to show the 24 line(s) of Go which triggered the analyzer.
```go
for _, curRS := range rss.Items {
selectorMap, err := metav1.LabelSelectorAsMap(curRS.Spec.Selector)
if err != nil {
panic(fmt.Sprintf("failed to convert label selector of RS %q to a map: %v", curRS.Name, err))
}
curColor := selectorMap["color"]
if curRS.Status.AvailableReplicas == 0 {
// Update the new color with color of the RS with zero replica
newColor = curColor
// Delete the RS with zero replica
err = crdclient.DeleteReplicaSet(&curRS)
if err != nil {
panic(fmt.Sprintf("failed to delete RS %q with zero replica before creating a new RS with newest image name: %v", curRS.Name, err))
}
// Immediate break out for the loop to prevent the new color from being updated again
break
} else {
// Update the new color with another color
newColor = colorMap[curColor]
}
}
```
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: a1012d91f445c401433b757a91a9afd7ece2286e
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with main.go lines 121-144 and inspect the range loop around curRS, especially the composite literal passed to DeleteReplicaSet. Compare the analyzer message with the linked classification descriptions, then leave a reaction marking the finding as Bug, Mitigated, or Desirable Behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100