Skip to content

Commit cd9a300

Browse files
committed
all: fix printf(var) mistakes detected by latest printf checker
These will cause build failures once we vendor x/tools. In once case I renamed a function err to errf to indicate that it is printf-like. Updates #68796 Change-Id: I04d57b34ee5362f530554b7e8b817f70a9088d12 Reviewed-on: https://go-review.googlesource.com/c/go/+/610739 Commit-Queue: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Tim King <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent 21ac23a commit cd9a300

File tree

20 files changed

+45
-45
lines changed

20 files changed

+45
-45
lines changed

src/cmd/api/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ func (w *Walker) emitType(obj *types.TypeName) {
10191019

10201020
func (w *Walker) emitStructType(name string, typ *types.Struct) {
10211021
typeStruct := fmt.Sprintf("type %s struct", name)
1022-
w.emitf(typeStruct)
1022+
w.emitf("%s", typeStruct)
10231023
defer w.pushScope(typeStruct)()
10241024

10251025
for i := 0; i < typ.NumFields(); i++ {

src/cmd/asm/internal/asm/parse.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ func (p *Parser) registerShift(name string, prefix rune) int64 {
708708
if p.arch.Family == sys.ARM64 {
709709
off, err := arch.ARM64RegisterShift(r1, op, count)
710710
if err != nil {
711-
p.errorf(err.Error())
711+
p.errorf("%v", err)
712712
}
713713
return off
714714
} else {
@@ -770,7 +770,7 @@ func (p *Parser) registerExtension(a *obj.Addr, name string, prefix rune) {
770770
case sys.ARM64:
771771
err := arch.ARM64RegisterExtension(a, ext, reg, num, isAmount, isIndex)
772772
if err != nil {
773-
p.errorf(err.Error())
773+
p.errorf("%v", err)
774774
}
775775
default:
776776
p.errorf("register extension not supported on this architecture")
@@ -1117,7 +1117,7 @@ ListLoop:
11171117
ext := tok.String()
11181118
curArrangement, err := arch.ARM64RegisterArrangement(reg, name, ext)
11191119
if err != nil {
1120-
p.errorf(err.Error())
1120+
p.errorf("%v", err)
11211121
}
11221122
if firstReg == -1 {
11231123
// only record the first register and arrangement
@@ -1164,7 +1164,7 @@ ListLoop:
11641164
case sys.ARM64:
11651165
offset, err := arch.ARM64RegisterListOffset(firstReg, regCnt, arrangement)
11661166
if err != nil {
1167-
p.errorf(err.Error())
1167+
p.errorf("%v", err)
11681168
}
11691169
a.Offset = offset
11701170
default:

src/cmd/cgo/internal/testerrors/argposition_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (v *Visitor) Visit(node ast.Node) ast.Visitor {
5858
}
5959

6060
if !gotMatch {
61-
v.t.Errorf(errorMessage.String())
61+
v.t.Error(errorMessage.String())
6262
}
6363
}
6464
}

src/cmd/compile/internal/inline/inlheur/callsite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func fmtFullPos(p src.XPos) string {
100100
var sb strings.Builder
101101
sep := ""
102102
base.Ctxt.AllPos(p, func(pos src.Pos) {
103-
fmt.Fprintf(&sb, sep)
103+
sb.WriteString(sep)
104104
sep = "|"
105105
file := filepath.Base(pos.Filename())
106106
fmt.Fprintf(&sb, "%s:%d:%d", file, pos.Line(), pos.Col())

src/cmd/compile/internal/ir/reassign_consistency_check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func fmtFullPos(p src.XPos) string {
3737
var sb strings.Builder
3838
sep := ""
3939
base.Ctxt.AllPos(p, func(pos src.Pos) {
40-
fmt.Fprintf(&sb, sep)
40+
sb.WriteString(sep)
4141
sep = "|"
4242
file := filepath.Base(pos.Filename())
4343
fmt.Fprintf(&sb, "%s:%d:%d", file, pos.Line(), pos.Col())

src/cmd/compile/internal/liveness/mergelocals.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ func fmtFullPos(p src.XPos) string {
10031003
var sb strings.Builder
10041004
sep := ""
10051005
base.Ctxt.AllPos(p, func(pos src.Pos) {
1006-
fmt.Fprintf(&sb, sep)
1006+
sb.WriteString(sep)
10071007
sep = "|"
10081008
file := filepath.Base(pos.Filename())
10091009
fmt.Fprintf(&sb, "%s:%d:%d", file, pos.Line(), pos.Col())

src/cmd/compile/internal/liveness/plive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ func (lv *liveness) showlive(v *ssa.Value, live bitvec.BitVec) {
11481148
s += " " + v
11491149
}
11501150

1151-
base.WarnfAt(pos, s)
1151+
base.WarnfAt(pos, "%s", s)
11521152
}
11531153

11541154
func (lv *liveness) printbvec(printed bool, name string, live bitvec.BitVec) bool {

src/cmd/compile/internal/logopt/log_opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func parseLogPath(destination string) (string, string) {
309309
func checkLogPath(destination string) string {
310310
path, complaint := parseLogPath(destination)
311311
if complaint != "" {
312-
log.Fatalf(complaint)
312+
log.Fatal(complaint)
313313
}
314314
err := os.MkdirAll(path, 0755)
315315
if err != nil {

src/cmd/compile/internal/loopvar/loopvar_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ func TestLoopVarInlinesGo1_21(t *testing.T) {
141141
c := f(root + "/c")
142142
m := f(root)
143143

144-
t.Logf(a)
145-
t.Logf(b)
146-
t.Logf(c)
147-
t.Logf(m)
144+
t.Log(a)
145+
t.Log(b)
146+
t.Log(c)
147+
t.Log(m)
148148

149149
if !strings.Contains(a, "f, af, bf, abf, cf sums = 100, 45, 100, 100, 100") {
150150
t.Errorf("Did not see expected value of a")
@@ -200,7 +200,7 @@ func TestLoopVarHashes(t *testing.T) {
200200

201201
for _, arg := range []string{"v001100110110110010100100", "vx336ca4"} {
202202
m := f(arg)
203-
t.Logf(m)
203+
t.Log(m)
204204

205205
mCount := countMatches(m, "loopvarhash triggered cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6: .* 001100110110110010100100")
206206
otherCount := strings.Count(m, "loopvarhash")
@@ -249,7 +249,7 @@ func TestLoopVarVersionEnableFlag(t *testing.T) {
249249
b, err := cmd.CombinedOutput()
250250
m := string(b)
251251

252-
t.Logf(m)
252+
t.Log(m)
253253

254254
yCount := strings.Count(m, "opt.go:16:6: loop variable private now per-iteration, heap-allocated (loop inlined into ./opt.go:29)")
255255
nCount := strings.Count(m, "shared")
@@ -288,7 +288,7 @@ func TestLoopVarVersionEnableGoBuild(t *testing.T) {
288288
b, err := cmd.CombinedOutput()
289289
m := string(b)
290290

291-
t.Logf(m)
291+
t.Log(m)
292292

293293
yCount := strings.Count(m, "opt-122.go:18:6: loop variable private now per-iteration, heap-allocated (loop inlined into ./opt-122.go:31)")
294294
nCount := strings.Count(m, "shared")
@@ -327,7 +327,7 @@ func TestLoopVarVersionDisableFlag(t *testing.T) {
327327
b, err := cmd.CombinedOutput()
328328
m := string(b)
329329

330-
t.Logf(m) // expect error
330+
t.Log(m) // expect error
331331

332332
yCount := strings.Count(m, "opt.go:16:6: loop variable private now per-iteration, heap-allocated (loop inlined into ./opt.go:29)")
333333
nCount := strings.Count(m, "shared")
@@ -366,7 +366,7 @@ func TestLoopVarVersionDisableGoBuild(t *testing.T) {
366366
b, err := cmd.CombinedOutput()
367367
m := string(b)
368368

369-
t.Logf(m) // expect error
369+
t.Log(m) // expect error
370370

371371
yCount := strings.Count(m, "opt-121.go:18:6: loop variable private now per-iteration, heap-allocated (loop inlined into ./opt-121.go:31)")
372372
nCount := strings.Count(m, "shared")

src/cmd/compile/internal/ssa/lca_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func testLCAgen(t *testing.T, bg blockGen, size int) {
1111
fun := c.Fun("entry", bg(size)...)
1212
CheckFunc(fun.f)
1313
if size == 4 {
14-
t.Logf(fun.f.String())
14+
t.Log(fun.f.String())
1515
}
1616
lca1 := makeLCArange(fun.f)
1717
lca2 := makeLCAeasy(fun.f)

src/cmd/compile/internal/syntax/branches.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ func checkBranches(body *BlockStmt, errh ErrorHandler) {
2929
name := fwd.Label.Value
3030
if l := ls.labels[name]; l != nil {
3131
l.used = true // avoid "defined and not used" error
32-
ls.err(fwd.Label.Pos(), "goto %s jumps into block starting at %s", name, l.parent.start)
32+
ls.errf(fwd.Label.Pos(), "goto %s jumps into block starting at %s", name, l.parent.start)
3333
} else {
34-
ls.err(fwd.Label.Pos(), "label %s not defined", name)
34+
ls.errf(fwd.Label.Pos(), "label %s not defined", name)
3535
}
3636
}
3737

3838
// spec: "It is illegal to define a label that is never used."
3939
for _, l := range ls.labels {
4040
if !l.used {
4141
l := l.lstmt.Label
42-
ls.err(l.Pos(), "label %s defined and not used", l.Value)
42+
ls.errf(l.Pos(), "label %s defined and not used", l.Value)
4343
}
4444
}
4545
}
@@ -61,7 +61,7 @@ type block struct {
6161
lstmt *LabeledStmt // labeled statement associated with this block, or nil
6262
}
6363

64-
func (ls *labelScope) err(pos Pos, format string, args ...interface{}) {
64+
func (ls *labelScope) errf(pos Pos, format string, args ...interface{}) {
6565
ls.errh(Error{pos, fmt.Sprintf(format, args...)})
6666
}
6767

@@ -75,7 +75,7 @@ func (ls *labelScope) declare(b *block, s *LabeledStmt) *label {
7575
labels = make(map[string]*label)
7676
ls.labels = labels
7777
} else if alt := labels[name]; alt != nil {
78-
ls.err(s.Label.Pos(), "label %s already defined at %s", name, alt.lstmt.Label.Pos().String())
78+
ls.errf(s.Label.Pos(), "label %s already defined at %s", name, alt.lstmt.Label.Pos().String())
7979
return alt
8080
}
8181
l := &label{b, s, false}
@@ -188,7 +188,7 @@ func (ls *labelScope) blockBranches(parent *block, ctxt targets, lstmt *LabeledS
188188
fwd.Target = s
189189
l.used = true
190190
if jumpsOverVarDecl(fwd) {
191-
ls.err(
191+
ls.errf(
192192
fwd.Label.Pos(),
193193
"goto %s jumps over declaration of %s at %s",
194194
name, String(varName), varPos,
@@ -215,13 +215,13 @@ func (ls *labelScope) blockBranches(parent *block, ctxt targets, lstmt *LabeledS
215215
if t := ctxt.breaks; t != nil {
216216
s.Target = t
217217
} else {
218-
ls.err(s.Pos(), "break is not in a loop, switch, or select")
218+
ls.errf(s.Pos(), "break is not in a loop, switch, or select")
219219
}
220220
case _Continue:
221221
if t := ctxt.continues; t != nil {
222222
s.Target = t
223223
} else {
224-
ls.err(s.Pos(), "continue is not in a loop")
224+
ls.errf(s.Pos(), "continue is not in a loop")
225225
}
226226
case _Fallthrough:
227227
msg := "fallthrough statement out of place"
@@ -237,7 +237,7 @@ func (ls *labelScope) blockBranches(parent *block, ctxt targets, lstmt *LabeledS
237237
break // fallthrough ok
238238
}
239239
}
240-
ls.err(s.Pos(), msg)
240+
ls.errf(s.Pos(), "%s", msg)
241241
case _Goto:
242242
fallthrough // should always have a label
243243
default:
@@ -258,10 +258,10 @@ func (ls *labelScope) blockBranches(parent *block, ctxt targets, lstmt *LabeledS
258258
case *SwitchStmt, *SelectStmt, *ForStmt:
259259
s.Target = t
260260
default:
261-
ls.err(s.Label.Pos(), "invalid break label %s", name)
261+
ls.errf(s.Label.Pos(), "invalid break label %s", name)
262262
}
263263
} else {
264-
ls.err(s.Label.Pos(), "break label not defined: %s", name)
264+
ls.errf(s.Label.Pos(), "break label not defined: %s", name)
265265
}
266266

267267
case _Continue:
@@ -271,10 +271,10 @@ func (ls *labelScope) blockBranches(parent *block, ctxt targets, lstmt *LabeledS
271271
if t, ok := t.Stmt.(*ForStmt); ok {
272272
s.Target = t
273273
} else {
274-
ls.err(s.Label.Pos(), "invalid continue label %s", name)
274+
ls.errf(s.Label.Pos(), "invalid continue label %s", name)
275275
}
276276
} else {
277-
ls.err(s.Label.Pos(), "continue label not defined: %s", name)
277+
ls.errf(s.Label.Pos(), "continue label not defined: %s", name)
278278
}
279279

280280
case _Goto:

src/cmd/compile/internal/test/mergelocals_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func TestMergeLocalsIntegration(t *testing.T) {
161161
fields := strings.Fields(line)
162162
wantFields := 9
163163
if len(fields) != wantFields {
164-
t.Logf(string(out))
164+
t.Log(string(out))
165165
t.Fatalf("bad trace output line, wanted %d fields got %d: %s",
166166
wantFields, len(fields), line)
167167
}
@@ -173,7 +173,7 @@ func TestMergeLocalsIntegration(t *testing.T) {
173173
wantvnum := 8
174174
gotvnum := len(vars)
175175
if wantvnum != gotvnum {
176-
t.Logf(string(out))
176+
t.Log(string(out))
177177
t.Fatalf("expected trace output on %d vars got %d\n", wantvnum, gotvnum)
178178
}
179179

src/cmd/compile/internal/test/ssa_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func runGenTest(t *testing.T, filename, tmpname string, ev ...string) {
3636
rungo := filepath.Join(t.TempDir(), "run.go")
3737
ok := os.WriteFile(rungo, stdout.Bytes(), 0600)
3838
if ok != nil {
39-
t.Fatalf("Failed to create temporary file " + rungo)
39+
t.Fatalf("Failed to create temporary file %s", rungo)
4040
}
4141

4242
stdout.Reset()

src/cmd/compile/internal/test/testdata/addressed_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
var output string
1313

1414
func mypanic(t *testing.T, s string) {
15-
t.Fatalf(s + "\n" + output)
15+
t.Fatal(s + "\n" + output)
1616

1717
}
1818

src/cmd/go/internal/load/pkg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ func disallowInternal(ctx context.Context, srcDir string, importer *Package, imp
15071507
perr := &PackageError{
15081508
alwaysPrintStack: true,
15091509
ImportStack: stk.Copy(),
1510-
Err: ImportErrorf(p.ImportPath, "use of internal package "+p.ImportPath+" not allowed"),
1510+
Err: ImportErrorf(p.ImportPath, "use of internal package %s not allowed", p.ImportPath),
15111511
}
15121512
return perr
15131513
}

src/cmd/go/internal/modload/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ func setDefaultBuildMod() {
15041504
}
15051505
}
15061506
} else {
1507-
cfg.BuildModReason = fmt.Sprintf("Go version in " + versionSource + " is unspecified, so vendor directory was not used.")
1507+
cfg.BuildModReason = fmt.Sprintf("Go version in %s is unspecified, so vendor directory was not used.", versionSource)
15081508
}
15091509
}
15101510
}

src/cmd/internal/goobj/objfile_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ func TestIssue41621LargeNumberOfRelocations(t *testing.T) {
104104

105105
// Emit testcase.
106106
var w bytes.Buffer
107-
fmt.Fprintf(&w, issue41621prolog)
107+
w.WriteString(issue41621prolog)
108108
for i := 0; i < 1048576+13; i++ {
109109
fmt.Fprintf(&w, "\t\"%d\",\n", i)
110110
}
111-
fmt.Fprintf(&w, issue41621epilog)
111+
w.WriteString(issue41621epilog)
112112
err = os.WriteFile(tmpdir+"/large.go", w.Bytes(), 0666)
113113
if err != nil {
114114
t.Fatalf("can't write output: %v\n", err)

src/cmd/internal/objabi/flag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func (f *DebugFlag) Set(debugstr string) error {
354354
}
355355
err := f.debugSSA(phase, flag, val, valstring)
356356
if err != "" {
357-
log.Fatalf(err)
357+
log.Fatal(err)
358358
}
359359
// Setting this false for -d=ssa/... preserves old behavior
360360
// of turning off concurrency for any debug flags.

src/cmd/link/internal/loader/loader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func TestAddDataMethods(t *testing.T) {
355355
name := fmt.Sprintf("new%d", k+1)
356356
mi := ldr.LookupOrCreateSym(name, 0)
357357
if mi == 0 {
358-
t.Fatalf("LookupOrCreateSym failed for '" + name + "'")
358+
t.Fatalf("LookupOrCreateSym failed for %q", name)
359359
}
360360
mi = tp.addDataFunc(ldr, mi, pmi)
361361
if ldr.SymType(mi) != tp.expKind {

src/cmd/link/linkbig_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestLargeText(t *testing.T) {
4646
testname := fmt.Sprintf("bigfn%d", j)
4747
fmt.Fprintf(&w, "TEXT ·%s(SB),$0\n", testname)
4848
for i := 0; i < 2200000; i++ {
49-
fmt.Fprintf(&w, inst)
49+
w.WriteString(inst)
5050
}
5151
fmt.Fprintf(&w, "\tRET\n")
5252
err := os.WriteFile(tmpdir+"/"+testname+".s", w.Bytes(), 0666)

0 commit comments

Comments
 (0)