strings,bytes: improve Repeat panic messages

The Repeat("-", maxInt) call should produce

   panic: runtime error: makeslice: len out of range

instead of

   panic: strings: Repeat output length overflow

This PR is only for theory perfection.

Change-Id: If67d87b147d666fbbb7238656f2a0cb6cf1dbb5b
GitHub-Last-Rev: 29dc0cb9c9
GitHub-Pull-Request: golang/go#67068
Reviewed-on: https://go-review.googlesource.com/c/go/+/581936
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
go101 2024-05-03 09:56:47 +00:00 committed by Gopher Robot
parent 2f5b420fb5
commit 44b54b99c9
4 changed files with 64 additions and 34 deletions

View file

@ -570,7 +570,7 @@ func Repeat(s string, count int) string {
if count < 0 {
panic("strings: negative Repeat count")
}
if len(s) >= maxInt/count {
if len(s) > maxInt/count {
panic("strings: Repeat output length overflow")
}
n := len(s) * count