Skip to content

Commit

Permalink
all: fix printf(var) mistakes detected by latest printf checker
Browse files Browse the repository at this point in the history
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 <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
  • Loading branch information
adonovan committed Sep 4, 2024
1 parent 21ac23a commit cd9a300
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/cmd/api/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ func (w *Walker) emitType(obj *types.TypeName) {

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

for i := 0; i < typ.NumFields(); i++ {
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/asm/internal/asm/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ func (p *Parser) registerShift(name string, prefix rune) int64 {
if p.arch.Family == sys.ARM64 {
off, err := arch.ARM64RegisterShift(r1, op, count)
if err != nil {
p.errorf(err.Error())
p.errorf("%v", err)
}
return off
} else {
Expand Down Expand Up @@ -770,7 +770,7 @@ func (p *Parser) registerExtension(a *obj.Addr, name string, prefix rune) {
case sys.ARM64:
err := arch.ARM64RegisterExtension(a, ext, reg, num, isAmount, isIndex)
if err != nil {
p.errorf(err.Error())
p.errorf("%v", err)
}
default:
p.errorf("register extension not supported on this architecture")
Expand Down Expand Up @@ -1117,7 +1117,7 @@ ListLoop:
ext := tok.String()
curArrangement, err := arch.ARM64RegisterArrangement(reg, name, ext)
if err != nil {
p.errorf(err.Error())
p.errorf("%v", err)
}
if firstReg == -1 {
// only record the first register and arrangement
Expand Down Expand Up @@ -1164,7 +1164,7 @@ ListLoop:
case sys.ARM64:
offset, err := arch.ARM64RegisterListOffset(firstReg, regCnt, arrangement)
if err != nil {
p.errorf(err.Error())
p.errorf("%v", err)
}
a.Offset = offset
default:
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cgo/internal/testerrors/argposition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (v *Visitor) Visit(node ast.Node) ast.Visitor {
}

if !gotMatch {
v.t.Errorf(errorMessage.String())
v.t.Error(errorMessage.String())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/inline/inlheur/callsite.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func fmtFullPos(p src.XPos) string {
var sb strings.Builder
sep := ""
base.Ctxt.AllPos(p, func(pos src.Pos) {
fmt.Fprintf(&sb, sep)
sb.WriteString(sep)
sep = "|"
file := filepath.Base(pos.Filename())
fmt.Fprintf(&sb, "%s:%d:%d", file, pos.Line(), pos.Col())
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/ir/reassign_consistency_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func fmtFullPos(p src.XPos) string {
var sb strings.Builder
sep := ""
base.Ctxt.AllPos(p, func(pos src.Pos) {
fmt.Fprintf(&sb, sep)
sb.WriteString(sep)
sep = "|"
file := filepath.Base(pos.Filename())
fmt.Fprintf(&sb, "%s:%d:%d", file, pos.Line(), pos.Col())
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/liveness/mergelocals.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ func fmtFullPos(p src.XPos) string {
var sb strings.Builder
sep := ""
base.Ctxt.AllPos(p, func(pos src.Pos) {
fmt.Fprintf(&sb, sep)
sb.WriteString(sep)
sep = "|"
file := filepath.Base(pos.Filename())
fmt.Fprintf(&sb, "%s:%d:%d", file, pos.Line(), pos.Col())
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/liveness/plive.go
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ func (lv *liveness) showlive(v *ssa.Value, live bitvec.BitVec) {
s += " " + v
}

base.WarnfAt(pos, s)
base.WarnfAt(pos, "%s", s)
}

func (lv *liveness) printbvec(printed bool, name string, live bitvec.BitVec) bool {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/logopt/log_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func parseLogPath(destination string) (string, string) {
func checkLogPath(destination string) string {
path, complaint := parseLogPath(destination)
if complaint != "" {
log.Fatalf(complaint)
log.Fatal(complaint)
}
err := os.MkdirAll(path, 0755)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions src/cmd/compile/internal/loopvar/loopvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ func TestLoopVarInlinesGo1_21(t *testing.T) {
c := f(root + "/c")
m := f(root)

t.Logf(a)
t.Logf(b)
t.Logf(c)
t.Logf(m)
t.Log(a)
t.Log(b)
t.Log(c)
t.Log(m)

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

for _, arg := range []string{"v001100110110110010100100", "vx336ca4"} {
m := f(arg)
t.Logf(m)
t.Log(m)

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

t.Logf(m)
t.Log(m)

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

t.Logf(m)
t.Log(m)

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

t.Logf(m) // expect error
t.Log(m) // expect error

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

t.Logf(m) // expect error
t.Log(m) // expect error

yCount := strings.Count(m, "opt-121.go:18:6: loop variable private now per-iteration, heap-allocated (loop inlined into ./opt-121.go:31)")
nCount := strings.Count(m, "shared")
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/ssa/lca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func testLCAgen(t *testing.T, bg blockGen, size int) {
fun := c.Fun("entry", bg(size)...)
CheckFunc(fun.f)
if size == 4 {
t.Logf(fun.f.String())
t.Log(fun.f.String())
}
lca1 := makeLCArange(fun.f)
lca2 := makeLCAeasy(fun.f)
Expand Down
26 changes: 13 additions & 13 deletions src/cmd/compile/internal/syntax/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ func checkBranches(body *BlockStmt, errh ErrorHandler) {
name := fwd.Label.Value
if l := ls.labels[name]; l != nil {
l.used = true // avoid "defined and not used" error
ls.err(fwd.Label.Pos(), "goto %s jumps into block starting at %s", name, l.parent.start)
ls.errf(fwd.Label.Pos(), "goto %s jumps into block starting at %s", name, l.parent.start)
} else {
ls.err(fwd.Label.Pos(), "label %s not defined", name)
ls.errf(fwd.Label.Pos(), "label %s not defined", name)
}
}

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

func (ls *labelScope) err(pos Pos, format string, args ...interface{}) {
func (ls *labelScope) errf(pos Pos, format string, args ...interface{}) {
ls.errh(Error{pos, fmt.Sprintf(format, args...)})
}

Expand All @@ -75,7 +75,7 @@ func (ls *labelScope) declare(b *block, s *LabeledStmt) *label {
labels = make(map[string]*label)
ls.labels = labels
} else if alt := labels[name]; alt != nil {
ls.err(s.Label.Pos(), "label %s already defined at %s", name, alt.lstmt.Label.Pos().String())
ls.errf(s.Label.Pos(), "label %s already defined at %s", name, alt.lstmt.Label.Pos().String())
return alt
}
l := &label{b, s, false}
Expand Down Expand Up @@ -188,7 +188,7 @@ func (ls *labelScope) blockBranches(parent *block, ctxt targets, lstmt *LabeledS
fwd.Target = s
l.used = true
if jumpsOverVarDecl(fwd) {
ls.err(
ls.errf(
fwd.Label.Pos(),
"goto %s jumps over declaration of %s at %s",
name, String(varName), varPos,
Expand All @@ -215,13 +215,13 @@ func (ls *labelScope) blockBranches(parent *block, ctxt targets, lstmt *LabeledS
if t := ctxt.breaks; t != nil {
s.Target = t
} else {
ls.err(s.Pos(), "break is not in a loop, switch, or select")
ls.errf(s.Pos(), "break is not in a loop, switch, or select")
}
case _Continue:
if t := ctxt.continues; t != nil {
s.Target = t
} else {
ls.err(s.Pos(), "continue is not in a loop")
ls.errf(s.Pos(), "continue is not in a loop")
}
case _Fallthrough:
msg := "fallthrough statement out of place"
Expand All @@ -237,7 +237,7 @@ func (ls *labelScope) blockBranches(parent *block, ctxt targets, lstmt *LabeledS
break // fallthrough ok
}
}
ls.err(s.Pos(), msg)
ls.errf(s.Pos(), "%s", msg)
case _Goto:
fallthrough // should always have a label
default:
Expand All @@ -258,10 +258,10 @@ func (ls *labelScope) blockBranches(parent *block, ctxt targets, lstmt *LabeledS
case *SwitchStmt, *SelectStmt, *ForStmt:
s.Target = t
default:
ls.err(s.Label.Pos(), "invalid break label %s", name)
ls.errf(s.Label.Pos(), "invalid break label %s", name)
}
} else {
ls.err(s.Label.Pos(), "break label not defined: %s", name)
ls.errf(s.Label.Pos(), "break label not defined: %s", name)
}

case _Continue:
Expand All @@ -271,10 +271,10 @@ func (ls *labelScope) blockBranches(parent *block, ctxt targets, lstmt *LabeledS
if t, ok := t.Stmt.(*ForStmt); ok {
s.Target = t
} else {
ls.err(s.Label.Pos(), "invalid continue label %s", name)
ls.errf(s.Label.Pos(), "invalid continue label %s", name)
}
} else {
ls.err(s.Label.Pos(), "continue label not defined: %s", name)
ls.errf(s.Label.Pos(), "continue label not defined: %s", name)
}

case _Goto:
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/test/mergelocals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestMergeLocalsIntegration(t *testing.T) {
fields := strings.Fields(line)
wantFields := 9
if len(fields) != wantFields {
t.Logf(string(out))
t.Log(string(out))
t.Fatalf("bad trace output line, wanted %d fields got %d: %s",
wantFields, len(fields), line)
}
Expand All @@ -173,7 +173,7 @@ func TestMergeLocalsIntegration(t *testing.T) {
wantvnum := 8
gotvnum := len(vars)
if wantvnum != gotvnum {
t.Logf(string(out))
t.Log(string(out))
t.Fatalf("expected trace output on %d vars got %d\n", wantvnum, gotvnum)
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/test/ssa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func runGenTest(t *testing.T, filename, tmpname string, ev ...string) {
rungo := filepath.Join(t.TempDir(), "run.go")
ok := os.WriteFile(rungo, stdout.Bytes(), 0600)
if ok != nil {
t.Fatalf("Failed to create temporary file " + rungo)
t.Fatalf("Failed to create temporary file %s", rungo)
}

stdout.Reset()
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/test/testdata/addressed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var output string

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

}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/load/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ func disallowInternal(ctx context.Context, srcDir string, importer *Package, imp
perr := &PackageError{
alwaysPrintStack: true,
ImportStack: stk.Copy(),
Err: ImportErrorf(p.ImportPath, "use of internal package "+p.ImportPath+" not allowed"),
Err: ImportErrorf(p.ImportPath, "use of internal package %s not allowed", p.ImportPath),
}
return perr
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modload/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ func setDefaultBuildMod() {
}
}
} else {
cfg.BuildModReason = fmt.Sprintf("Go version in " + versionSource + " is unspecified, so vendor directory was not used.")
cfg.BuildModReason = fmt.Sprintf("Go version in %s is unspecified, so vendor directory was not used.", versionSource)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/internal/goobj/objfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ func TestIssue41621LargeNumberOfRelocations(t *testing.T) {

// Emit testcase.
var w bytes.Buffer
fmt.Fprintf(&w, issue41621prolog)
w.WriteString(issue41621prolog)
for i := 0; i < 1048576+13; i++ {
fmt.Fprintf(&w, "\t\"%d\",\n", i)
}
fmt.Fprintf(&w, issue41621epilog)
w.WriteString(issue41621epilog)
err = os.WriteFile(tmpdir+"/large.go", w.Bytes(), 0666)
if err != nil {
t.Fatalf("can't write output: %v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/internal/objabi/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (f *DebugFlag) Set(debugstr string) error {
}
err := f.debugSSA(phase, flag, val, valstring)
if err != "" {
log.Fatalf(err)
log.Fatal(err)
}
// Setting this false for -d=ssa/... preserves old behavior
// of turning off concurrency for any debug flags.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/internal/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func TestAddDataMethods(t *testing.T) {
name := fmt.Sprintf("new%d", k+1)
mi := ldr.LookupOrCreateSym(name, 0)
if mi == 0 {
t.Fatalf("LookupOrCreateSym failed for '" + name + "'")
t.Fatalf("LookupOrCreateSym failed for %q", name)
}
mi = tp.addDataFunc(ldr, mi, pmi)
if ldr.SymType(mi) != tp.expKind {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/linkbig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestLargeText(t *testing.T) {
testname := fmt.Sprintf("bigfn%d", j)
fmt.Fprintf(&w, "TEXT ·%s(SB),$0\n", testname)
for i := 0; i < 2200000; i++ {
fmt.Fprintf(&w, inst)
w.WriteString(inst)
}
fmt.Fprintf(&w, "\tRET\n")
err := os.WriteFile(tmpdir+"/"+testname+".s", w.Bytes(), 0666)
Expand Down

0 comments on commit cd9a300

Please sign in to comment.