github-vet / github-vet/rangeloop-pointer-findings
Optum/dce: scripts/migrations/v0.21.0_rename_db_tables_dce/main.go; 41 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [Optum/dce](https://www.github.com/Optum/dce) at [scripts/migrations/v0.21.0_rename_db_tables_dce/main.go](https://github.com/Optum/dce/blob/f4a1c1cee56cd7daa01ecca7f35aaec7fe4199b1/scripts/migrations/v0.21.0_rename_db_tables_dce/main.go#L56-L96)
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 srcTableName was used in a composite literal at line 59
[Click here to see the code in its original context.](https://github.com/Optum/dce/blob/f4a1c1cee56cd7daa01ecca7f35aaec7fe4199b1/scripts/migrations/v0.21.0_rename_db_tables_dce/main.go#L56-L96)
Click here to show the 41 line(s) of Go which triggered the analyzer.
```go
for srcTableName, dstTableName := range input.tables {
// Dump table records
scanRes, err := input.db.Scan(&dynamodb.ScanInput{
TableName: &srcTableName,
})
if err != nil {
return errors.Wrapf(err, "Scan failed for %s", srcTableName)
}
// Create records in the new table
var deferredErrors []error
t := dstTableName
for i, item := range scanRes.Items {
_, err = input.db.PutItem(&dynamodb.PutItemInput{
TableName: &t,
Item: item,
})
if err != nil {
deferredErrors = append(deferredErrors, err)
log.Printf(`
Failed to put item %d/%d to %s
Error: %s
Item: %v
`, i+1, len(scanRes.Items), dstTableName, err, item)
continue
}
log.Printf("Migrated record %d/%d from %s to %s", i+1, len(scanRes.Items), srcTableName, dstTableName)
}
// Handle deferred errors
if len(deferredErrors) > 0 {
return errors2.NewMultiError(
fmt.Sprintf(
"%d/%d migrations to %s failed",
len(deferredErrors), len(scanRes.Items), dstTableName,
),
deferredErrors,
)
}
}
```
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: f4a1c1cee56cd7daa01ecca7f35aaec7fe4199b1
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.