std: fix calls to Printf(s) with non-constant s

In all cases the intent was not to interpret s as a format string.
In one case (go/types), this was a latent bug in production.
(These were uncovered by a new check in vet's printf analyzer.)

Updates #60529

Change-Id: I3e17af7e589be9aec1580783a1b1011c52ec494b
Reviewed-on: https://go-review.googlesource.com/c/go/+/587855
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Alan Donovan 2024-05-23 10:47:36 -04:00
parent c34c124f40
commit bf91eb3a8b
14 changed files with 18 additions and 18 deletions

View file

@ -533,7 +533,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
case _Max, _Min:
// max(x, ...)
// min(x, ...)
check.verifyVersionf(call.Fun, go1_21, quote(bin.name))
check.verifyVersionf(call.Fun, go1_21, "%s", quote(bin.name))
op := token.LSS
if id == _Max {

View file

@ -160,7 +160,7 @@ func TestPSSGolden(t *testing.T) {
t.Error(err)
}
default:
t.Fatalf("unknown marker: " + marker)
t.Fatalf("unknown marker: %s", marker)
}
}
}

View file

@ -1753,7 +1753,7 @@ func TestIssue6651(t *testing.T) {
want := "error in rows.Next"
rowsCursorNextHook = func(dest []driver.Value) error {
return fmt.Errorf(want)
return errors.New(want)
}
defer func() { rowsCursorNextHook = nil }()
@ -1765,7 +1765,7 @@ func TestIssue6651(t *testing.T) {
want = "error in rows.Close"
setRowsCloseHook(func(rows *Rows, err *error) {
*err = fmt.Errorf(want)
*err = errors.New(want)
})
defer setRowsCloseHook(nil)
err = db.QueryRow("SELECT|people|name|").Scan(&v)

View file

@ -1168,7 +1168,7 @@ func TestMarshalUncommonFieldNames(t *testing.T) {
func TestMarshalerError(t *testing.T) {
s := "test variable"
st := reflect.TypeOf(s)
errText := "json: test error"
const errText = "json: test error"
tests := []struct {
CaseName

View file

@ -536,7 +536,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
case _Max, _Min:
// max(x, ...)
// min(x, ...)
check.verifyVersionf(call.Fun, go1_21, quote(bin.name))
check.verifyVersionf(call.Fun, go1_21, "%s", quote(bin.name))
op := token.LSS
if id == _Max {

View file

@ -488,7 +488,7 @@ func (check *Checker) instantiatedType(ix *typeparams.IndexExpr, def *TypeName)
if i < len(ix.Indices) {
pos = ix.Indices[i].Pos()
}
check.softErrorf(atPos(pos), InvalidTypeArg, err.Error())
check.softErrorf(atPos(pos), InvalidTypeArg, "%v", err)
} else {
check.mono.recordInstance(check.pkg, ix.Pos(), inst.TypeParams().list(), inst.TypeArgs().list(), ix.Indices)
}

View file

@ -197,7 +197,7 @@ func testForSpecificFunctions(t *testing.T, dir string, want []string, avoid []s
}
}
if rval != "" {
t.Logf("=-= begin output:\n" + output + "\n=-= end output\n")
t.Logf("=-= begin output:\n%s\n=-= end output\n", output)
}
return rval
}

View file

@ -1909,7 +1909,7 @@ func TestFillBytes(t *testing.T) {
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
} {
t.Run(n, func(t *testing.T) {
t.Logf(n)
t.Log(n)
x, ok := new(Int).SetString(n, 0)
if !ok {
panic("invalid test entry")

View file

@ -77,7 +77,7 @@ func checkSampleDistribution(t *testing.T, samples []float64, expected *statsRes
actual := getStatsResults(samples)
err := actual.checkSimilarDistribution(expected)
if err != nil {
t.Errorf(err.Error())
t.Error(err)
}
}

View file

@ -74,7 +74,7 @@ func checkSampleDistribution(t *testing.T, samples []float64, expected *statsRes
actual := getStatsResults(samples)
err := actual.checkSimilarDistribution(expected)
if err != nil {
t.Errorf(err.Error())
t.Error(err)
}
}

View file

@ -4743,11 +4743,11 @@ Host: foo
func TestHandlerFinishSkipBigContentLengthRead(t *testing.T) {
setParallel(t)
conn := newTestConn()
conn.readBuf.Write([]byte(fmt.Sprintf(
conn.readBuf.WriteString(
"POST / HTTP/1.1\r\n" +
"Host: test\r\n" +
"Content-Length: 9999999999\r\n" +
"\r\n" + strings.Repeat("a", 1<<20))))
"\r\n" + strings.Repeat("a", 1<<20))
ls := &oneConnListener{conn}
var inHandlerLen int

View file

@ -206,7 +206,7 @@ func (c *Client) Auth(a Auth) error {
}
resp64 := make([]byte, encoding.EncodedLen(len(resp)))
encoding.Encode(resp64, resp)
code, msg64, err := c.cmd(0, strings.TrimSpace(fmt.Sprintf("AUTH %s %s", mech, resp64)))
code, msg64, err := c.cmd(0, "%s", strings.TrimSpace(fmt.Sprintf("AUTH %s %s", mech, resp64)))
for err == nil {
var msg []byte
switch code {
@ -232,7 +232,7 @@ func (c *Client) Auth(a Auth) error {
}
resp64 = make([]byte, encoding.EncodedLen(len(resp)))
encoding.Encode(resp64, resp)
code, msg64, err = c.cmd(0, string(resp64))
code, msg64, err = c.cmd(0, "%s", resp64)
}
return err
}

View file

@ -772,10 +772,10 @@ func TestSendMail(t *testing.T) {
tc := textproto.NewConn(conn)
for i := 0; i < len(data) && data[i] != ""; i++ {
tc.PrintfLine(data[i])
tc.PrintfLine("%s", data[i])
for len(data[i]) >= 4 && data[i][3] == '-' {
i++
tc.PrintfLine(data[i])
tc.PrintfLine("%s", data[i])
}
if data[i] == "221 Goodbye" {
return

View file

@ -1272,7 +1272,7 @@ func TestMutexProfile(t *testing.T) {
if ok, err := regexp.MatchString(r3, lines[5]); err != nil || !ok {
t.Errorf("%q didn't match %q", lines[5], r3)
}
t.Logf(prof)
t.Log(prof)
})
t.Run("proto", func(t *testing.T) {
// proto format