Radar · Go · Archive · Week 31 · Jul 27 – Aug 2, 2026
go/analysis/passes/printf: disallow %d formatting of pointers
Worth knowingtooling
- What changed
- The vet checker now reports an error when a pointer value is formatted with the
%dverb. - Production impact
- The source does not say.
- Try it
- Run
go vet ./...on a package that containsfmt.Sprintf("%d", ptr)whereptris a pointer; you should see a vet error. - Source
- github.com/golang/go/issues/62595
Understand it, then run it
The Go vet tool checks code for common mistakes. One check looks at calls to fmt.Printf‑style functions. It used to allow formatting a pointer with the %d verb, which prints a decimal number. That number is actually the pointer’s address, but most people expect %d to print an integer value. The change makes vet report an error when a pointer is passed to %d.
Now, if you write fmt.Printf("%d", &x) where x is an int, vet will warn you that this is likely a mistake. You should either dereference the pointer (*p) or use a different verb.
The change does not alter how fmt itself works; it only adds a stricter check in the static analysis.
Run it now
// This program demonstrates the new vet rule: it will fail vet
// if you try to format a pointer with %d. The code compiles
// and runs, but running `go vet` on it will produce an error.
package main
import "fmt"
func main() {
x := 42
p := &x
// The following line would trigger the new vet error:
// fmt.Printf("%d\n", p)
// Instead we dereference the pointer to print the value.
fmt.Printf("%d\n", *p)
}
What it printed when we ran it on Go 1.27.1
42
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed