bytes: limit allocation in SplitN

This commit is contained in:
Philippe Antoine 2022-04-04 22:09:07 +02:00
parent 6f1dce0fcb
commit f8df09d65e
2 changed files with 5 additions and 0 deletions

View file

@ -348,6 +348,9 @@ func genSplit(s, sep []byte, sepSave, n int) [][]byte {
if n < 0 {
n = Count(s, sep) + 1
}
if n > len(s)+1 {
n = len(s) + 1
}
a := make([][]byte, n)
n--