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

Huawei/cloud-sdk-go: examples/rds/v3/instances_ext.go; 14 LoC

Open
#15,138 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 [Huawei/cloud-sdk-go](https://www.github.com/Huawei/cloud-sdk-go) at [examples/rds/v3/instances_ext.go](https://github.com/Huawei/cloud-sdk-go/blob/cf2007c96f3d13d6e4485c84bf644fc281262880/examples/rds/v3/instances_ext.go#L231-L244)

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 v is reassigned at line 236

[Click here to see the code in its original context.](https://github.com/Huawei/cloud-sdk-go/blob/cf2007c96f3d13d6e4485c84bf644fc281262880/examples/rds/v3/instances_ext.go#L231-L244)

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

```go
for _, v := range resp.Instances {
jsServer, _ := json.MarshalIndent(v, "", " ")
fmt.Println("Server info is :", string(jsServer))
fmt.Println("Server id is :", v.Id)
if v.Id == instanceID && v.Status == "ACTIVE" {
instanceResTmp = &v
fmt.Println("[LogInfor]GetRdsInstanceInfo create instance status is ACTIVE infor: ", instanceResTmp)
return true, nil
}
if v.Id == instanceID && v.Status != "ACTIVE" {
fmt.Println("[LogInfor]GetRdsInstanceInfo create instance status is: ", v.Status)
return true, nil
}
}

```

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: cf2007c96f3d13d6e4485c84bf644fc281262880

Contributor guide

No contributing guide indexed for this repository

Research direction

Open examples/rds/v3/instances_ext.go at lines 231-244 and inspect how instanceResTmp is used after the loop. Check the Go range-loop reference behavior and determine whether taking &v changes the result; done means classifying the finding as Bug, Mitigated, or Desirable Behavior with a rationale.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cloud
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.