From 446a5dcf5a3230ce9832682d8f521071d8a34a2b Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Thu, 5 Oct 2023 12:20:11 -0700 Subject: [PATCH] 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 Reviewed-by: Jorropo Reviewed-by: Achille Roussel LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall --- src/bytes/boundary_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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) + } + } +} -- 2.50.0