aboutsummaryrefslogtreecommitdiff
path: root/src/bytes
diff options
context:
space:
mode:
authorPaul E. Murphy <murp@ibm.com>2021-10-19 11:17:53 -0500
committerLynn Boger <laboger@linux.vnet.ibm.com>2021-11-02 17:31:50 +0000
commit4e7dd9fc08fb5aa86773b65d865719d96f67f49d (patch)
treed8953f1bdad1e5d9dcb8683ae82dcf0866af1d9e /src/bytes
parent62b29b035948c08041e4218d0b176d057c8a6f6f (diff)
downloadgo-4e7dd9fc08fb5aa86773b65d865719d96f67f49d.tar.gz
go-4e7dd9fc08fb5aa86773b65d865719d96f67f49d.zip
bytes: test for page boundary crosses on sep of Index
Improve TestIndexNearPageBoundary to verify needles ending on a page boundary don't cause a segfault. Change-Id: I2edb13db63a71dc9955e266f6b97026ee13bf76e Reviewed-on: https://go-review.googlesource.com/c/go/+/356889 Reviewed-by: Cherry Mui <cherryyz@google.com> Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
Diffstat (limited to 'src/bytes')
-rw-r--r--src/bytes/boundary_test.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/bytes/boundary_test.go b/src/bytes/boundary_test.go
index 8dac751866..f9855fcb05 100644
--- a/src/bytes/boundary_test.go
+++ b/src/bytes/boundary_test.go
@@ -65,7 +65,11 @@ func TestIndexByteNearPageBoundary(t *testing.T) {
func TestIndexNearPageBoundary(t *testing.T) {
t.Parallel()
- var q [64]byte
+ q := dangerousSlice(t)
+ if len(q) > 64 {
+ // Only worry about when we're near the end of a page.
+ q = q[len(q)-64:]
+ }
b := dangerousSlice(t)
if len(b) > 256 {
// Only worry about when we're near the end of a page.
@@ -81,4 +85,16 @@ func TestIndexNearPageBoundary(t *testing.T) {
}
q[j-1] = 0
}
+
+ // Test differing alignments and sizes of q which always end on a page boundary.
+ q[len(q)-1] = 1 // difference is only found on the last byte
+ for j := 0; j < len(q); j++ {
+ for i := range b {
+ idx := Index(b[i:], q[j:])
+ if idx != -1 {
+ t.Fatalf("Index(b[%d:], q[%d:])=%d, want -1\n", i, j, idx)
+ }
+ }
+ }
+ q[len(q)-1] = 0
}