go.tools/cmd/vet: fix a panic on invalid AddInt
Ignore calls to various flavours of atomic.AddInt with a wrong number of arguments. LGTM=r R=golang-codereviews, r CC=golang-codereviews https://golang.org/cl/91370045
This commit is contained in:
parent
d52b449ed7
commit
91b1b28499
|
@ -44,6 +44,9 @@ func (f *File) checkAtomicAssignment(n *ast.AssignStmt) {
|
|||
// checkAtomicAddAssignment walks the atomic.Add* method calls checking for assigning the return value
|
||||
// to the same variable being used in the operation
|
||||
func (f *File) checkAtomicAddAssignment(left ast.Expr, call *ast.CallExpr) {
|
||||
if len(call.Args) != 2 {
|
||||
return
|
||||
}
|
||||
arg := call.Args[0]
|
||||
broken := false
|
||||
|
||||
|
|
|
@ -38,4 +38,6 @@ func AtomicTests() {
|
|||
ap := []*uint64{&au[0], &au[1]}
|
||||
*ap[0] = atomic.AddUint64(ap[0], 1) // ERROR "direct assignment to atomic value"
|
||||
*ap[1] = atomic.AddUint64(ap[0], 1)
|
||||
|
||||
x = atomic.AddUint64() // Used to make vet crash; now silently ignored.
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue