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

rgonomic/rgo: internal/pkg/testdata/testgen.go; 36 LoC

Open
#13,345 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 [rgonomic/rgo](https://www.github.com/rgonomic/rgo) at [internal/pkg/testdata/testgen.go](https://github.com/rgonomic/rgo/blob/2cd99811678ae14e91cd2df009068bfb229d32dd/internal/pkg/testdata/testgen.go#L150-L185)

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 c is reassigned at line 154

[Click here to see the code in its original context.](https://github.com/rgonomic/rgo/blob/2cd99811678ae14e91cd2df009068bfb229d32dd/internal/pkg/testdata/testgen.go#L150-L185)

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

```go
for _, c := range cases {
c.UID = suff[c.Name]
suff[c.Name]++
for i := range c.Funcs {
c.Funcs[i].pkg = &c
}

pkg := fmt.Sprintf("%s_%d", c.Name, c.UID)
err := os.Mkdir(pkg, 0o755)
if err != nil && !os.IsExist(err) {
log.Fatalf("failed to create testing package dir: %v", err)
}
f, err := os.Create(filepath.Join(pkg, c.Name+".go"))
if err != nil {
log.Fatalf("failed to create testing source file: %v", err)
}

var buf bytes.Buffer
err = src.Execute(&buf, c)
if err != nil {
log.Fatalf("failed to execute template: %v", err)
}
b, err := format.Source(buf.Bytes())
if err != nil {
log.Fatalf("failed to format source: %v", err)
}
_, err = f.Write(b)
if err != nil {
log.Fatalf("failed to write source: %v", err)
}

err = f.Close()
if err != nil {
log.Fatalf("failed to close testing source file: %v", err)
}
}

```

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: 2cd99811678ae14e91cd2df009068bfb229d32dd

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.