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>
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 {
t.Error(err)
}
default:
- t.Fatalf("unknown marker: " + marker)
+ t.Fatalf("unknown marker: %s", marker)
}
}
}
want := "error in rows.Next"
rowsCursorNextHook = func(dest []driver.Value) error {
- return fmt.Errorf(want)
+ return errors.New(want)
}
defer func() { rowsCursorNextHook = nil }()
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)
func TestMarshalerError(t *testing.T) {
s := "test variable"
st := reflect.TypeOf(s)
- errText := "json: test error"
+ const errText = "json: test error"
tests := []struct {
CaseName
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 {
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)
}
}
}
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
}
"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")
actual := getStatsResults(samples)
err := actual.checkSimilarDistribution(expected)
if err != nil {
- t.Errorf(err.Error())
+ t.Error(err)
}
}
actual := getStatsResults(samples)
err := actual.checkSimilarDistribution(expected)
if err != nil {
- t.Errorf(err.Error())
+ t.Error(err)
}
}
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
}
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 {
}
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
}
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
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