printf-style function with dynamic format string and no further arguments should use print-style function instead
147
148 // Initial cluster size may not be greater than 1 with fork-from
149 if pgConfig.InitialClusterSize > 1 {
150 fmt.Fprintf(io.Out, colorize.Yellow("Warning: --initial-cluster-size is ignored when specifying --fork-from\n"))151 pgConfig.InitialClusterSize = 1
152 }
153
Description
Using fmt.Printf
with a dynamic first argument can lead to unexpected output.
The first argument is a format string, where certain character combinations have
special meaning.
Forming the first parameter via string
concatenation with user input should be
avoided for the same reason. When printing user input, either use a variant of
fmt.Print
, or use the %s
Printf
verb and pass the string
as an argument.
Bad practice
s := "Interest rate: 5%"
fmt.Printf(s) // Prints: Interest rate: 5%!(NOVERB)
Recommended
s := "Interest rate: 5%"
fmt.Print(s) // Prints: Interest rate: 5%
s := "Interest rate: 5%"
fmt.Printf("%s", s) // Prints: Interest rate: 5%