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

jamesunger/saws: saws.go; 59 LoC

Open
#16,723 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [jamesunger/saws](https://www.github.com/jamesunger/saws) at [saws.go](https://github.com/jamesunger/saws/blob/69f31f1b4cc360b052689faf0dcafe572d9c19d0/saws.go#L1315-L1373)

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.

> range-loop variable i used in defer or goroutine at line 1364

[Click here to see the code in its original context.](https://github.com/jamesunger/saws/blob/69f31f1b4cc360b052689faf0dcafe572d9c19d0/saws.go#L1315-L1373)

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

```go
for i := range config.RDS {
// setup RDS instances

_, err = getRDSInstanceById(rdsc, &config.RDS[i].DBInstanceIdentifier)
if err == nil {
fmt.Println("RDS instance", config.RDS[i].DBInstanceIdentifier, "exists.")
continue
}

groupname := "sawsdbprivate"
cdbsgi := &rds.CreateDBSubnetGroupInput{DBSubnetGroupName: &groupname, SubnetIds: []*string{&config.PrivateSubnetId, &config.PublicSubnetId}, DBSubnetGroupDescription: &groupname}
_, err := rdsc.CreateDBSubnetGroup(cdbsgi)
if err != nil {

//fmt.Println("Failed to create db subnetgroup:", err)
//FIXME: search for subnet gorup if already created
//panic(err)
}

//fmt.Println("Creating with:", config.RDS[i])
//fmt.Println("DBSubnetGroupName: ", cdsgo.DBSubnetGroup.DBSubnetGroupName)
//fmt.Println("Engine: ", config.RDS[i].Engine)
//fmt.Println("DBName: ", config.RDS[i].DBName)
//fmt.Println("DBInstanceIdentifier: ", config.RDS[i].DBInstanceIdentifier)
//fmt.Println("AllocatedStorage: ", config.RDS[i].AllocatedStorage)
//fmt.Println("DBInstanceClass: ", config.RDS[i].DBInstanceClass)
//fmt.Println("MasterUsername: ", config.RDS[i].MasterUsername)
//fmt.Println("MasterUserPassword: ", config.RDS[i].MasterUserPassword)

cdbi := &rds.CreateDBInstanceInput{
DBSubnetGroupName: &groupname,
Engine: &config.RDS[i].Engine,
DBName: &config.RDS[i].DBName,
DBInstanceIdentifier: &config.RDS[i].DBInstanceIdentifier,
AllocatedStorage: &config.RDS[i].AllocatedStorage,
DBInstanceClass: &config.RDS[i].DBInstanceClass,
MasterUsername: &config.RDS[i].MasterUsername,
MasterUserPassword: &config.RDS[i].MasterUserPassword,
}
_, err = rdsc.CreateDBInstance(cdbi)
if err != nil {
fmt.Println("Error creating db instance.")
panic(err)
}
//fmt.Println(cdbo)
fmt.Println("Created", config.RDS[i].Engine, "RDS instance: ", config.RDS[i].DBInstanceIdentifier)

numStepsDeferred++
go func() {
rdsinst, err := waitForRDSEndpoint(rdsc, &config.RDS[i].DBInstanceIdentifier)
if err != nil {
fmt.Println(err)
doneChan <- fmt.Sprint(err)
} else {
doneChan <- fmt.Sprintf("Endpoint for RDS instance %s: %s", config.RDS[i].DBInstanceIdentifier, *rdsinst.Endpoint.Address)
}
}()

}

```

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: 69f31f1b4cc360b052689faf0dcafe572d9c19d0

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.