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

openshift/compliance-operator: cmd/manager/suitererunner.go; 38 LoC

Open
#7,789 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [openshift/compliance-operator](https://www.github.com/openshift/compliance-operator) at [cmd/manager/suitererunner.go](https://github.com/openshift/compliance-operator/blob/725ee2c43b7470ed787953aa596de1c7dfe255e9/cmd/manager/suitererunner.go#L90-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.

> reference to scan is reassigned at line 91

[Click here to see the code in its original context.](https://github.com/openshift/compliance-operator/blob/725ee2c43b7470ed787953aa596de1c7dfe255e9/cmd/manager/suitererunner.go#L90-L127)

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

```go
for _, scan := range scans.Items {
currentScan := &scan
key := types.NamespacedName{Name: scan.GetName(), Namespace: scan.GetNamespace()}
err := backoff.Retry(func() error {
var scanCopy *compv1alpha1.ComplianceScan
if currentScan == nil {
fmt.Printf("Re-fetching ComplianceScan '%s' since the reference we had is no longer valid\n", scanCopy.Name)
err = conf.client.client.Get(context.TODO(), key, currentScan)
if err != nil {
fmt.Printf("Error re-fetching ComplianceScan '%s': %s\n", scanCopy.Name, err)
return err
}
} else {
scanCopy = currentScan.DeepCopy()
}
if scanCopy.Annotations == nil {
scanCopy.Annotations = make(map[string]string)
}
scanCopy.Annotations[compv1alpha1.ComplianceScanRescanAnnotation] = ""

fmt.Printf("Re-running ComplianceScan '%s'\n", scanCopy.Name)
err := conf.client.client.Update(context.TODO(), scanCopy)
if err != nil && (errors.IsResourceExpired(err) || errors.IsConflict(err)) {
currentScan = nil
return err
} else if err != nil {
fmt.Printf("Error while updating scan '%s', err: %s\n", scanCopy.Name, err)
fmt.Printf("Retrying.\n")
return err
}
return nil
}, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), maxScanUpdateRetries))

if err != nil {
fmt.Printf("Couldn't update scan '%s', err: %s\n", scan.Name, err)
os.Exit(1)
}
}

```

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: 725ee2c43b7470ed787953aa596de1c7dfe255e9

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.