Skip to content

Commit 72b6daa

Browse files
committed
cmd/vet: check argument types in printf formats
Fixes #4404. R=gri, rsc CC=golang-dev https://golang.org/cl/7378061
1 parent 39c476c commit 72b6daa

File tree

5 files changed

+231
-65
lines changed

5 files changed

+231
-65
lines changed

src/cmd/vet/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
# license that can be found in the LICENSE file.
44

55
test testshort:
6-
go build
6+
go build -tags unsafe
77
../../../test/errchk ./vet -printfuncs='Warn:1,Warnf:1' *.go
88

src/cmd/vet/atomic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"sync/atomic"
1111
)
1212

13-
// checkAtomicAssignment walks the assignment statement checking for comomon
13+
// checkAtomicAssignment walks the assignment statement checking for common
1414
// mistaken usage of atomic package, such as: x = atomic.AddUint64(&x, 1)
1515
func (f *File) checkAtomicAssignment(n *ast.AssignStmt) {
1616
if !vet("atomic") {

src/cmd/vet/main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ func doPackageDir(directory string) {
160160
}
161161

162162
type Package struct {
163-
types map[ast.Expr]types.Type
163+
types map[ast.Expr]types.Type
164+
values map[ast.Expr]interface{}
164165
}
165166

166167
// doPackage analyzes the single package constructed from the named files.
@@ -188,8 +189,12 @@ func doPackage(names []string) {
188189
}
189190
pkg := new(Package)
190191
pkg.types = make(map[ast.Expr]types.Type)
192+
pkg.values = make(map[ast.Expr]interface{})
191193
exprFn := func(x ast.Expr, typ types.Type, val interface{}) {
192194
pkg.types[x] = typ
195+
if val != nil {
196+
pkg.values[x] = val
197+
}
193198
}
194199
context := types.Context{
195200
Expr: exprFn,

0 commit comments

Comments
 (0)