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

web-platform-tests/wpt.fyi: util/populate_dev_data.go; 60 LoC

Open
#14,892 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 [web-platform-tests/wpt.fyi](https://www.github.com/web-platform-tests/wpt.fyi) at [util/populate_dev_data.go](https://github.com/web-platform-tests/wpt.fyi/blob/a4555d7d1c531afa0e2aa1a244752d1203ea2008/util/populate_dev_data.go#L240-L299)

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 aligned is reassigned at line 242

[Click here to see the code in its original context.](https://github.com/web-platform-tests/wpt.fyi/blob/a4555d7d1c531afa0e2aa1a244752d1203ea2008/util/populate_dev_data.go#L240-L299)

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

```go
for _, aligned := range []bool{false, true} {
if aligned {
filters.Aligned = &aligned
}
prodTestRuns, err := shared.FetchRuns(*remoteHost, filters)
if err != nil {
log.Print(err)
continue
}
labelRuns(prodTestRuns, "prod")

latestProductionTestRunMetadata := make([]interface{}, 0, len(prodTestRuns))
for i := range prodTestRuns {
if !seenTestRunIDs.Contains(prodTestRuns[i].ID) {
seenTestRunIDs.Add(prodTestRuns[i].ID)
latestProductionTestRunMetadata = append(latestProductionTestRunMetadata, &prodTestRuns[i])
}
}
addData(store, "TestRun", latestProductionTestRunMetadata)

passRateMetadataKindName := metrics.GetDatastoreKindName(metrics.PassRateMetadata{})
filters.MaxCount = nil
prodPassRateMetadata, err := FetchInterop(*remoteHost, filters)
if err != nil {
log.Printf("Failed to fetch interop (?aligned=%v).", aligned)
continue
}
// Update the interop IDs to match the newly-copied local test-run IDs.
// We re-fetch locally because we might have copied a large number of runs,
// but only want the latest for interop.
prodPassRateMetadata.TestRunIDs = make([]int64, len(prodPassRateMetadata.TestRuns))
one := 1
sha := shared.LatestSHA
var localRunCopies shared.TestRuns
if aligned {
var shas []string
var keys map[string]shared.KeysByProduct
if shas, keys, err = q.GetAlignedRunSHAs(shared.GetDefaultProducts(), filters.Labels, nil, nil, &one, nil); err != nil {
log.Printf("Failed to load a aligned run SHA: %s", err.Error())
continue
}
if len(shas) > 0 {
sha = shas[0]
if loaded, err := q.LoadTestRunsByKeys(keys[sha]); err != nil {
log.Printf("Failed to load test runs by keys: %s", err.Error())
continue
} else {
localRunCopies = loaded.AllRuns()
}
}
}
if len(localRunCopies) != len(prodPassRateMetadata.TestRunIDs) {
log.Printf("Could not find local copies for SHA %s", sha)
continue
}
for i := range prodPassRateMetadata.TestRunIDs {
prodPassRateMetadata.TestRunIDs[i] = localRunCopies[i].ID
}
addData(store, passRateMetadataKindName, []interface{}{&prodPassRateMetadata})
}

```

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

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.