• Daniel Martí's avatar
    cmd/vet: better align print warnings with fmt · 98409a44
    Daniel Martí authored
    fmt's %d, %x, and %X all accept pointer arguments. However, in cmd/vet's
    printVerbs table, they were defined as if they did not accept pointer
    arguments.
    
    This inconsistency with fmt did not manifest to users since the vet
    codebase worked around it. In particular, pointer arguments were usually
    allowed for verbs that accepted integers, as the *types.Pointer argument
    type case read the following:
    
    	t&(argInt|argPointer) != 0
    
    As a result, using the %q verb with a pointer resulted in a bug in
    cmd/vet:
    
    	$ go run f.go
    	%!q(*int=0xc000014140)
    	$ go vet f.go
    	[no warning]
    
    As documented, fmt's %q verb only accepts runes (integers), strings, and
    byte slices. It should not accept pointers, and it does not. But since
    vet mixed integers and pointers, it wasn't properly warning about the
    misuse of fmt.
    
    This patch surfaced another bug with fmt.Printf("%p", nil):
    
    	$ go run f.go
    	%!p(<nil>)
    	$ go vet f.go
    	[no warning]
    
    As documented, fmt's %p verb only accepts pointers, and untyped nil is
    not a valid pointer. But vet did not warn about it, which is another
    inconsistency with fmt's documented rules. Fix that too, with a test,
    also getting rid of the TODO associated with the code.
    
    As a result of those changes, fix a wrong use of the fmt format verbs in
    the standard library, now correctly spotted by vet.
    
    Fixes #25233.
    
    Change-Id: Id0ad31fbc25adfe1c46c6b6879b8d02b23633b3a
    Reviewed-on: https://go-review.googlesource.com/111284
    Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarAlan Donovan <adonovan@google.com>
    98409a44
Name
Last commit
Last update
..
all Loading commit data...
internal Loading commit data...
testdata Loading commit data...
README Loading commit data...
asmdecl.go Loading commit data...
assign.go Loading commit data...
atomic.go Loading commit data...
bool.go Loading commit data...
buildtag.go Loading commit data...
cgo.go Loading commit data...
composite.go Loading commit data...
copylock.go Loading commit data...
dead.go Loading commit data...
deadcode.go Loading commit data...
doc.go Loading commit data...
httpresponse.go Loading commit data...
lostcancel.go Loading commit data...
main.go Loading commit data...
method.go Loading commit data...
nilfunc.go Loading commit data...
print.go Loading commit data...
rangeloop.go Loading commit data...
shadow.go Loading commit data...
shift.go Loading commit data...
structtag.go Loading commit data...
tests.go Loading commit data...
types.go Loading commit data...
unsafeptr.go Loading commit data...
unused.go Loading commit data...
vet_test.go Loading commit data...