github-vet / bots

Bots for running analysis on GitHub's public Go repositories and crowdsourcing their classification.
MIT License
1 stars 1 forks source link

Track pointer comparisons #132

Open kalexmills opened 3 years ago

kalexmills commented 3 years ago

Pointer comparisons are another important way in which a reference to a range-loop variable can be misused. It's possible for Go code to compare two pointers using == or !=. Although this may not be a very commonly used feature, someone might be using it, so we should check -- it will be interesting to see what we find.

For instance, the below loop will have different semantics after the change. We need to report anywhere we find it.

func main() {
  var y int
  for _, x := range []int{1,2,3,4} {
    bar(&x, &y)
  }
}

func bar(x, y *int) {
  if x == y {
    fmt.Printf("memory address %p found before %p", x, y)
  }
}
kalexmills commented 3 years ago

Blocked by #131.

False negatives occur until this is implemented.