Skip to content

Track pointer comparisons #132

@kalexmills

Description

@kalexmills

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfalse-negativethe issue can create a false-negativevet-botthe issue is part of VetBot's responsibility

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions