diff --git a/src/crypto/rsa/rsa_test.go b/src/crypto/rsa/rsa_test.go
index 55aad05..affdf56 100644
--- a/src/crypto/rsa/rsa_test.go
+++ b/src/crypto/rsa/rsa_test.go
@@ -975,7 +975,7 @@
priv.D = d
for j, message := range test.msgs {
- label := []byte(fmt.Sprintf("hi#%d", j))
+ label := fmt.Appendf(nil, "hi#%d", j)
enc, err := EncryptOAEP(sha256, rand.Reader, &priv.PublicKey, message.in, label)
if err != nil {
t.Errorf("#%d,%d: EncryptOAEP: %v", i, j, err)
diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go
index 2cb2de0..c38774d 100644
--- a/src/database/sql/sql_test.go
+++ b/src/database/sql/sql_test.go
@@ -5013,7 +5013,7 @@
}
func (t issue69728Type) Value() (driver.Value, error) {
- return []byte(fmt.Sprintf("%d, %s", t.ID, t.Name)), nil
+ return fmt.Appendf(nil, "%d, %s", t.ID, t.Name), nil
}
func TestIssue69728(t *testing.T) {
diff --git a/src/encoding/gob/gobencdec_test.go b/src/encoding/gob/gobencdec_test.go
index 1ac7a16..a79ee84 100644
--- a/src/encoding/gob/gobencdec_test.go
+++ b/src/encoding/gob/gobencdec_test.go
@@ -103,7 +103,7 @@
}
func (g *Gobber) GobEncode() ([]byte, error) {
- return []byte(fmt.Sprintf("VALUE=%d", *g)), nil
+ return fmt.Appendf(nil, "VALUE=%d", *g), nil
}
func (g *Gobber) GobDecode(data []byte) error {
@@ -112,7 +112,7 @@
}
func (g *BinaryGobber) MarshalBinary() ([]byte, error) {
- return []byte(fmt.Sprintf("VALUE=%d", *g)), nil
+ return fmt.Appendf(nil, "VALUE=%d", *g), nil
}
func (g *BinaryGobber) UnmarshalBinary(data []byte) error {
@@ -121,7 +121,7 @@
}
func (g *TextGobber) MarshalText() ([]byte, error) {
- return []byte(fmt.Sprintf("VALUE=%d", *g)), nil
+ return fmt.Appendf(nil, "VALUE=%d", *g), nil
}
func (g *TextGobber) UnmarshalText(data []byte) error {
@@ -130,7 +130,7 @@
}
func (v ValueGobber) GobEncode() ([]byte, error) {
- return []byte(fmt.Sprintf("VALUE=%s", v)), nil
+ return fmt.Appendf(nil, "VALUE=%s", v), nil
}
func (v *ValueGobber) GobDecode(data []byte) error {
@@ -139,7 +139,7 @@
}
func (v BinaryValueGobber) MarshalBinary() ([]byte, error) {
- return []byte(fmt.Sprintf("VALUE=%s", v)), nil
+ return fmt.Appendf(nil, "VALUE=%s", v), nil
}
func (v *BinaryValueGobber) UnmarshalBinary(data []byte) error {
@@ -148,7 +148,7 @@
}
func (v TextValueGobber) MarshalText() ([]byte, error) {
- return []byte(fmt.Sprintf("VALUE=%s", v)), nil
+ return fmt.Appendf(nil, "VALUE=%s", v), nil
}
func (v *TextValueGobber) UnmarshalText(data []byte) error {
diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go
index 5c29f6b..67e2004 100644
--- a/src/encoding/json/decode_test.go
+++ b/src/encoding/json/decode_test.go
@@ -145,7 +145,7 @@
type u8marshal uint8
func (u8 u8marshal) MarshalText() ([]byte, error) {
- return []byte(fmt.Sprintf("u%d", u8)), nil
+ return fmt.Appendf(nil, "u%d", u8), nil
}
var errMissingU8Prefix = errors.New("missing 'u' prefix")
@@ -294,7 +294,7 @@
type byteWithMarshalJSON byte
func (b byteWithMarshalJSON) MarshalJSON() ([]byte, error) {
- return []byte(fmt.Sprintf(`"Z%.2x"`, byte(b))), nil
+ return fmt.Appendf(nil, `"Z%.2x"`, byte(b)), nil
}
func (b *byteWithMarshalJSON) UnmarshalJSON(data []byte) error {
@@ -322,7 +322,7 @@
type byteWithMarshalText byte
func (b byteWithMarshalText) MarshalText() ([]byte, error) {
- return []byte(fmt.Sprintf(`Z%.2x`, byte(b))), nil
+ return fmt.Appendf(nil, `Z%.2x`, byte(b)), nil
}
func (b *byteWithMarshalText) UnmarshalText(data []byte) error {
@@ -350,7 +350,7 @@
type intWithMarshalJSON int
func (b intWithMarshalJSON) MarshalJSON() ([]byte, error) {
- return []byte(fmt.Sprintf(`"Z%.2x"`, int(b))), nil
+ return fmt.Appendf(nil, `"Z%.2x"`, int(b)), nil
}
func (b *intWithMarshalJSON) UnmarshalJSON(data []byte) error {
@@ -378,7 +378,7 @@
type intWithMarshalText int
func (b intWithMarshalText) MarshalText() ([]byte, error) {
- return []byte(fmt.Sprintf(`Z%.2x`, int(b))), nil
+ return fmt.Appendf(nil, `Z%.2x`, int(b)), nil
}
func (b *intWithMarshalText) UnmarshalText(data []byte) error {
diff --git a/src/expvar/expvar_test.go b/src/expvar/expvar_test.go
index 24e2029..b944bf8 100644
--- a/src/expvar/expvar_test.go
+++ b/src/expvar/expvar_test.go
@@ -335,7 +335,7 @@
func BenchmarkMapSetDifferentRandom(b *testing.B) {
keys := make([]string, 100)
for i := range keys {
- keys[i] = fmt.Sprintf("%x", sha1.Sum([]byte(fmt.Sprint(i))))
+ keys[i] = fmt.Sprintf("%x", sha1.Sum(fmt.Append(nil, i)))
}
v := new(Int)
@@ -406,7 +406,7 @@
func BenchmarkMapAddDifferentRandom(b *testing.B) {
keys := make([]string, 100)
for i := range keys {
- keys[i] = fmt.Sprintf("%x", sha1.Sum([]byte(fmt.Sprint(i))))
+ keys[i] = fmt.Sprintf("%x", sha1.Sum(fmt.Append(nil, i)))
}
b.ResetTimer()
diff --git a/src/internal/trace/internal/testgen/trace.go b/src/internal/trace/internal/testgen/trace.go
index 2eade48..90a0a20 100644
--- a/src/internal/trace/internal/testgen/trace.go
+++ b/src/internal/trace/internal/testgen/trace.go
@@ -137,7 +137,7 @@
// Expectation file contents.
expect := []byte("SUCCESS\n")
if t.bad {
- expect = []byte(fmt.Sprintf("FAILURE %q\n", t.badMatch))
+ expect = fmt.Appendf(nil, "FAILURE %q\n", t.badMatch)
}
// Create the test file's contents.
diff --git a/src/log/slog/json_handler_test.go b/src/log/slog/json_handler_test.go
index fd6b2e3..a18f4d5 100644
--- a/src/log/slog/json_handler_test.go
+++ b/src/log/slog/json_handler_test.go
@@ -64,7 +64,7 @@
if j.s == "" {
return nil, errors.New("json: empty string")
}
- return []byte(fmt.Sprintf(`[%q]`, j.s)), nil
+ return fmt.Appendf(nil, `[%q]`, j.s), nil
}
type jsonMarshalerError struct {
diff --git a/src/log/slog/text_handler_test.go b/src/log/slog/text_handler_test.go
index e148baa..9ccab20 100644
--- a/src/log/slog/text_handler_test.go
+++ b/src/log/slog/text_handler_test.go
@@ -119,7 +119,7 @@
if t.s == "" {
return nil, errors.New("text: empty string")
}
- return []byte(fmt.Sprintf("text{%q}", t.s)), nil
+ return fmt.Appendf(nil, "text{%q}", t.s), nil
}
func TestTextHandlerPreformatted(t *testing.T) {
diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go
index df691ae..552d587 100644
--- a/src/net/http/serve_test.go
+++ b/src/net/http/serve_test.go
@@ -2112,11 +2112,11 @@
defer afterTest(t)
conn := new(testConn)
body := strings.Repeat("x", 100<<10)
- conn.readBuf.Write([]byte(fmt.Sprintf(
+ conn.readBuf.Write(fmt.Appendf(nil,
"POST / HTTP/1.1\r\n"+
"Host: test\r\n"+
"Content-Length: %d\r\n"+
- "\r\n", len(body))))
+ "\r\n", len(body)))
conn.readBuf.Write([]byte(body))
done := make(chan bool)
@@ -2155,11 +2155,11 @@
}
conn := new(testConn)
body := strings.Repeat("x", 1<<20)
- conn.readBuf.Write([]byte(fmt.Sprintf(
+ conn.readBuf.Write(fmt.Appendf(nil,
"POST / HTTP/1.1\r\n"+
"Host: test\r\n"+
"Content-Length: %d\r\n"+
- "\r\n", len(body))))
+ "\r\n", len(body)))
conn.readBuf.Write([]byte(body))
conn.closec = make(chan bool, 1)
@@ -2306,12 +2306,12 @@
cw.Close()
conn.readBuf.WriteString("\r\n")
} else {
- conn.readBuf.Write([]byte(fmt.Sprintf(
+ conn.readBuf.Write(fmt.Appendf(nil,
"POST / HTTP/1.1\r\n"+
"Host: test\r\n"+
tt.connectionHeader()+
"Content-Length: %d\r\n"+
- "\r\n", len(body))))
+ "\r\n", len(body)))
conn.readBuf.Write([]byte(body))
}
if !tt.reqConnClose {
@@ -3423,7 +3423,7 @@
t.Logf("set RST avoidance delay to %v", timeout)
const bodySize = 5 << 20
- req := []byte(fmt.Sprintf("POST / HTTP/1.1\r\nHost: foo.com\r\nContent-Length: %d\r\n\r\n", bodySize))
+ req := fmt.Appendf(nil, "POST / HTTP/1.1\r\nHost: foo.com\r\nContent-Length: %d\r\n\r\n", bodySize)
for range bodySize {
req = append(req, 'x')
}