aboutsummaryrefslogtreecommitdiff
path: root/src/bytes
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2023-10-05 12:20:11 -0700
committerKeith Randall <khr@golang.org>2023-11-30 20:05:58 +0000
commit446a5dcf5a3230ce9832682d8f521071d8a34a2b (patch)
tree9dd711e5ad2b3c31e1a5e04e9d7ffdb185e7c424 /src/bytes
parentbda1ef13f8f9954d20b712ece649776c272f8526 (diff)
downloadgo-446a5dcf5a3230ce9832682d8f521071d8a34a2b.tar.gz
go-446a5dcf5a3230ce9832682d8f521071d8a34a2b.zip
bytes: add a boundary test for Count of 1 byte
This bottoms out in internal/bytealg.Count, which does a fair amount of avx shenanigans. Make sure we're not reading out of bounds. Change-Id: Ied0e461f536f75acc24c6797f7fc74e3f3901c10 Reviewed-on: https://go-review.googlesource.com/c/go/+/533116 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Achille Roussel <achille.roussel@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/bytes')
-rw-r--r--src/bytes/boundary_test.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/bytes/boundary_test.go b/src/bytes/boundary_test.go
index f9855fcb05..67f377e089 100644
--- a/src/bytes/boundary_test.go
+++ b/src/bytes/boundary_test.go
@@ -98,3 +98,18 @@ func TestIndexNearPageBoundary(t *testing.T) {
}
q[len(q)-1] = 0
}
+
+func TestCountNearPageBoundary(t *testing.T) {
+ t.Parallel()
+ b := dangerousSlice(t)
+ for i := range b {
+ c := Count(b[i:], []byte{1})
+ if c != 0 {
+ t.Fatalf("Count(b[%d:], {1})=%d, want 0\n", i, c)
+ }
+ c = Count(b[:i], []byte{0})
+ if c != i {
+ t.Fatalf("Count(b[:%d], {0})=%d, want %d\n", i, c, i)
+ }
+ }
+}