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:
Robert Obryk 2014-05-14 12:16:58 -07:00 committed by Rob Pike
parent d52b449ed7
commit 91b1b28499
2 changed files with 5 additions and 0 deletions

View File

@ -44,6 +44,9 @@ func (f *File) checkAtomicAssignment(n *ast.AssignStmt) {
// checkAtomicAddAssignment walks the atomic.Add* method calls checking for assigning the return value // checkAtomicAddAssignment walks the atomic.Add* method calls checking for assigning the return value
// to the same variable being used in the operation // to the same variable being used in the operation
func (f *File) checkAtomicAddAssignment(left ast.Expr, call *ast.CallExpr) { func (f *File) checkAtomicAddAssignment(left ast.Expr, call *ast.CallExpr) {
if len(call.Args) != 2 {
return
}
arg := call.Args[0] arg := call.Args[0]
broken := false broken := false

View File

@ -38,4 +38,6 @@ func AtomicTests() {
ap := []*uint64{&au[0], &au[1]} ap := []*uint64{&au[0], &au[1]}
*ap[0] = atomic.AddUint64(ap[0], 1) // ERROR "direct assignment to atomic value" *ap[0] = atomic.AddUint64(ap[0], 1) // ERROR "direct assignment to atomic value"
*ap[1] = atomic.AddUint64(ap[0], 1) *ap[1] = atomic.AddUint64(ap[0], 1)
x = atomic.AddUint64() // Used to make vet crash; now silently ignored.
} }