Printf
with dynamic first argument and no further arguments SCC-SA1006 97 }
98
99 paddingSize := widths[i] - len(column.Contents)
100 _, err = fmt.Fprintf(dst, strings.Repeat(" ", paddingSize))101 if err != nil {
102 return err
103 }
47 }
48 }
49 if workersNames == nil {
50 fmt.Printf(ui.WarningColor("WARNING: No stalled workers found.\n"))51 }
52 }
53
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.
s := "Interest rate: 5%"
fmt.Printf(s) // Prints: Interest rate: 5%!(NOVERB)
s := "Interest rate: 5%"
fmt.Print(s) // Prints: Interest rate: 5%
s := "Interest rate: 5%"
fmt.Printf("%s", s) // Prints: Interest rate: 5%