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)
}
}
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.