github-vet / github-vet/rangeloop-pointer-findings
rgonomic/rgo: internal/rgo/testdata/testgen.go; 47 LoC
- 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/rgo/testdata/testgen.go](https://github.com/rgonomic/rgo/blob/2cd99811678ae14e91cd2df009068bfb229d32dd/internal/rgo/testdata/testgen.go#L145-L191)
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 149
[Click here to see the code in its original context.](https://github.com/rgonomic/rgo/blob/2cd99811678ae14e91cd2df009068bfb229d32dd/internal/rgo/testdata/testgen.go#L145-L191)
Click here to show the 47 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)
}
err = os.Remove(filepath.Join(pkg, "go.mod"))
if err != nil && !os.IsNotExist(err) {
log.Fatalf("failed to remove go.mod file: %v", err)
}
cmd := exec.Command("go", "mod", "init", pkg)
cmd.Dir = filepath.Join(".", pkg)
err = cmd.Run()
if err != nil {
log.Fatalf("failed create go.mod 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.