bytes: limit allocation in SplitN

So that bytes.SplitN("", "T", int(144115188075855872)) does not panic.

Change-Id: I7c068852bd708416164fc2ed8b84cf6b2d593666
GitHub-Last-Rev: f8df09d65e
GitHub-Pull-Request: golang/go#52147
Reviewed-on: https://go-review.googlesource.com/c/go/+/398076
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: mzh <mzh@golangcn.org>
This commit is contained in:
Philippe Antoine 2022-04-05 20:28:16 +00:00 committed by Ian Lance Taylor
parent 6c17529af7
commit 5bb2628c6f
2 changed files with 5 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import (
. "bytes"
"fmt"
"internal/testenv"
"math"
"math/rand"
"reflect"
"strings"
@ -723,6 +724,7 @@ var splittests = []SplitTest{
{"1 2", " ", 3, []string{"1", "2"}},
{"123", "", 2, []string{"1", "23"}},
{"123", "", 17, []string{"1", "2", "3"}},
{"bT", "T", math.MaxInt / 4, []string{"b", ""}},
}
func TestSplit(t *testing.T) {