• 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
..
example_test.go Loading commit data...
export_android_test.go Loading commit data...
export_test.go Loading commit data...
export_windows_test.go Loading commit data...
format.go Loading commit data...
format_test.go Loading commit data...
genzabbrs.go Loading commit data...
internal_test.go Loading commit data...
mono_test.go Loading commit data...
sleep.go Loading commit data...
sleep_test.go Loading commit data...
sys_plan9.go Loading commit data...
sys_unix.go Loading commit data...
sys_windows.go Loading commit data...
tick.go Loading commit data...
tick_test.go Loading commit data...
time.go Loading commit data...
time_test.go Loading commit data...
zoneinfo.go Loading commit data...
zoneinfo_abbrs_windows.go Loading commit data...
zoneinfo_android.go Loading commit data...
zoneinfo_android_test.go Loading commit data...
zoneinfo_ios.go Loading commit data...
zoneinfo_plan9.go Loading commit data...
zoneinfo_read.go Loading commit data...
zoneinfo_test.go Loading commit data...
zoneinfo_unix.go Loading commit data...
zoneinfo_windows.go Loading commit data...
zoneinfo_windows_test.go Loading commit data...