diff options
author | Francesc Campoy <campoy@golang.org> | 2019-02-11 16:33:12 +0200 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2019-02-26 23:51:17 +0000 |
commit | 20930c7623be7c78189898795d089002c2f9de41 (patch) | |
tree | 447fabfa76868cc614765a972cf22be0544b6d55 /src/regexp/regexp.go | |
parent | 98cbf45cfc6a5a50cc6ac2367f9572cb198b57c7 (diff) | |
download | go-git-20930c7623be7c78189898795d089002c2f9de41.tar.gz |
regexp: limit the capacity of slices of bytes returned by FindX
This change limits the capacity of the slices of bytes returned by:
- Find
- FindAll
- FindAllSubmatch
to be the same as their length.
Fixes #30169
Change-Id: I07b632757d2bfeab42fce0d42364e2a16c597360
Reviewed-on: https://go-review.googlesource.com/c/161877
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/regexp/regexp.go')
-rw-r--r-- | src/regexp/regexp.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/regexp/regexp.go b/src/regexp/regexp.go index 38b3c86d9f..88122d4250 100644 --- a/src/regexp/regexp.go +++ b/src/regexp/regexp.go @@ -761,7 +761,7 @@ func (re *Regexp) Find(b []byte) []byte { if a == nil { return nil } - return b[a[0]:a[1]] + return b[a[0]:a[1]:a[1]] } // FindIndex returns a two-element slice of integers defining the location of @@ -829,7 +829,7 @@ func (re *Regexp) FindSubmatch(b []byte) [][]byte { ret := make([][]byte, 1+re.numSubexp) for i := range ret { if 2*i < len(a) && a[2*i] >= 0 { - ret[i] = b[a[2*i]:a[2*i+1]] + ret[i] = b[a[2*i]:a[2*i+1]:a[2*i+1]] } } return ret @@ -1025,7 +1025,7 @@ func (re *Regexp) FindAll(b []byte, n int) [][]byte { if result == nil { result = make([][]byte, 0, startSize) } - result = append(result, b[match[0]:match[1]]) + result = append(result, b[match[0]:match[1]:match[1]]) }) return result } @@ -1100,7 +1100,7 @@ func (re *Regexp) FindAllSubmatch(b []byte, n int) [][][]byte { slice := make([][]byte, len(match)/2) for j := range slice { if match[2*j] >= 0 { - slice[j] = b[match[2*j]:match[2*j+1]] + slice[j] = b[match[2*j]:match[2*j+1]:match[2*j+1]] } } result = append(result, slice) |