github-vet / rangeloop-pointer-findings

Issue tracker collects instances of Go code on GitHub that make use of references to range loop variables.
0 stars 0 forks source link

huaweicloud/huaweicloud-sdk-go: examples/rds/v3/instances_ext.go; 14 LoC #3904

Open githubvet opened 3 years ago

githubvet commented 3 years ago

Found a possible issue in huaweicloud/huaweicloud-sdk-go at examples/rds/v3/instances_ext.go

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.

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 for more information.

commit ID: f7f79ffe470a8b339ef55207a84ff264f0e67e04

mdempsky commented 3 years ago

Function always returns after the statement, so the loop never continues to the next iteration.

kalexmills commented 3 years ago

This one should be caught automatically as a false-positive and not reported, but there's an open bug for it.