Skip to content

Commit

Permalink
internal/language: fix resizeRange index wrong way
Browse files Browse the repository at this point in the history
Fixes golang/go#42536

Change-Id: I572cdbb26d320c4d9a972d555ddc6427ce1f0348
Reviewed-on: https://go-review.googlesource.com/c/text/+/270697
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Trust: Meng Zhuo <mzh@golangcn.org>
  • Loading branch information
mengzhuo committed Nov 18, 2020
1 parent 22f1617 commit 4482a91
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/language/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ func (s *scanner) resizeRange(oldStart, oldEnd, newSize int) {
s.start = oldStart
if end := oldStart + newSize; end != oldEnd {
diff := end - oldEnd
if end < cap(s.b) {
b := make([]byte, len(s.b)+diff)
var b []byte
if n := len(s.b) + diff; n > cap(s.b) {
b = make([]byte, n)
copy(b, s.b[:oldStart])
copy(b[end:], s.b[oldEnd:])
s.b = b
} else {
s.b = append(s.b[end:], s.b[oldEnd:]...)
b = s.b[:n:n]
}
copy(b[end:], s.b[oldEnd:])
s.b = b
s.next = end + (s.next - s.end)
s.end = end
}
Expand Down
1 change: 1 addition & 0 deletions language/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ func TestParseAcceptLanguage(t *testing.T) {
{nil, "aa;q", false},
{nil, "aa;q=", false},
{nil, "aa;q=.", false},
{nil, "00-t-0o", false},

// odd fallbacks
{
Expand Down

0 comments on commit 4482a91

Please sign in to comment.