1
0
mirror of https://github.com/golang/go synced 2024-11-17 07:24:53 -07:00

bytes: explode checks for n too large

As is already done in strings package.
This commit is contained in:
Philippe Antoine 2022-04-15 13:33:16 +02:00
parent d255203742
commit 1174c25035

View File

@ -30,7 +30,7 @@ func Compare(a, b []byte) int {
// explode splits s into a slice of UTF-8 sequences, one per Unicode code point (still slices of bytes), // explode splits s into a slice of UTF-8 sequences, one per Unicode code point (still slices of bytes),
// up to a maximum of n byte slices. Invalid UTF-8 sequences are chopped into individual bytes. // up to a maximum of n byte slices. Invalid UTF-8 sequences are chopped into individual bytes.
func explode(s []byte, n int) [][]byte { func explode(s []byte, n int) [][]byte {
if n <= 0 { if n <= 0 || n > len(s) {
n = len(s) n = len(s)
} }
a := make([][]byte, n) a := make([][]byte, n)