Commit 72b6daa3 authored by Rob Pike's avatar Rob Pike

cmd/vet: check argument types in printf formats

Fixes #4404.

R=gri, rsc
CC=golang-dev
https://golang.org/cl/7378061
parent 39c476cb
......@@ -3,6 +3,6 @@
# license that can be found in the LICENSE file.
test testshort:
go build
go build -tags unsafe
../../../test/errchk ./vet -printfuncs='Warn:1,Warnf:1' *.go
......@@ -10,7 +10,7 @@ import (
"sync/atomic"
)
// checkAtomicAssignment walks the assignment statement checking for comomon
// checkAtomicAssignment walks the assignment statement checking for common
// mistaken usage of atomic package, such as: x = atomic.AddUint64(&x, 1)
func (f *File) checkAtomicAssignment(n *ast.AssignStmt) {
if !vet("atomic") {
......
......@@ -160,7 +160,8 @@ func doPackageDir(directory string) {
}
type Package struct {
types map[ast.Expr]types.Type
types map[ast.Expr]types.Type
values map[ast.Expr]interface{}
}
// doPackage analyzes the single package constructed from the named files.
......@@ -188,8 +189,12 @@ func doPackage(names []string) {
}
pkg := new(Package)
pkg.types = make(map[ast.Expr]types.Type)
pkg.values = make(map[ast.Expr]interface{})
exprFn := func(x ast.Expr, typ types.Type, val interface{}) {
pkg.types[x] = typ
if val != nil {
pkg.values[x] = val
}
}
context := types.Context{
Expr: exprFn,
......
This diff is collapsed.
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build unsafe
// This file contains a special test for the printf-checker that tests unsafe.Pointer.
package main
import (
"fmt"
"unsafe" // just for test case printing unsafe.Pointer
)
func UnsafePointerPrintfTest() {
var up *unsafe.Pointer
fmt.Printf("%p", up)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment