github-vet / github-vet/rangeloop-pointer-findings
pinpt/ripsrc: cmd/validate.go; 85 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [pinpt/ripsrc](https://www.github.com/pinpt/ripsrc) at [cmd/validate.go](https://github.com/pinpt/ripsrc/blob/ca61a6465b25aa76391610cd5e666b02b4cfb5e2/cmd/validate.go#L40-L124)
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 repoDir used in defer or goroutine at line 66
[Click here to see the code in its original context.](https://github.com/pinpt/ripsrc/blob/ca61a6465b25aa76391610cd5e666b02b4cfb5e2/cmd/validate.go#L40-L124)
Click here to show the 85 line(s) of Go which triggered the analyzer.
```go
for _, repoDir := range args {
fmt.Println("running on repo", repoDir)
opts := process.Opts{}
opts.RepoDir = repoDir
opts.CommitFromIncl, _ = cmd.Flags().GetString("commit-from-incl")
pr := process.New(opts)
res := make(chan process.Result)
done := make(chan bool)
go func() {
for r := range res {
fmt.Println("Checking commit:", r.Commit)
LOOPFILES:
for p, bl1 := range r.Files {
fmt.Println("Checking file:", r.Commit, p)
if manuallyChecked[p] {
fmt.Println("Skipping checking file (manully checked to be ok to differ):", p)
continue
}
if len(bl1.Lines) == 0 {
// removed file, no blame
continue
}
bl2, err := gitblame2.Run(repoDir, r.Commit, p)
if err != nil {
panic(err)
}
rerr := func() {
fmt.Println("Failed checks.")
fmt.Println("Content of incremental blame")
fmt.Println(bl1)
fmt.Println("Content of git blame")
fmt.Println(bl2)
fmt.Println("ERROR!")
}
// validate
if len(bl1.Lines) != len(bl2.Lines) {
fmt.Println("Error: lines len mismatch")
rerr()
continue
}
for i := range bl1.Lines {
l1 := bl1.Lines[i]
l2 := bl2.Lines[i]
// TODO: looks like currently we convert newlines to linux style, even if it was different in source
c1 := strings.TrimSpace(string(l1.Line))
c2 := strings.TrimSpace(l2.Content)
if l1.Commit != l2.CommitHash {
// repeating blocks are in sometime in different order when both ordering is correct
mostlySameContent := false
if c1 == c2 {
if len(c1) <= 10 {
mostlySameContent = true
}
if c1 == "return" {
mostlySameContent = true
}
}
// the new blame sometimes assigned ownership to lines in a different order, happens for repeating lines, such as empty lines, lines, containing braces, etc
// ignore diff for lines with 1 char only
if !mostlySameContent {
fmt.Println("invalid commit, line ", i)
continue LOOPFILES
}
}
if c1 != c2 {
fmt.Println("invalid content, line ", i)
continue LOOPFILES
}
}
}
}
done <- true
}()
err := pr.Run(res)
if err != nil {
panic(err)
}
<-done
fmt.Println("SUCCESS on", repoDir)
}
```
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: ca61a6465b25aa76391610cd5e666b02b4cfb5e2
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.