]> Cypherpunks repositories - gostls13.git/commitdiff
bytes: add a boundary test for Count of 1 byte
authorKeith Randall <khr@golang.org>
Thu, 5 Oct 2023 19:20:11 +0000 (12:20 -0700)
committerKeith Randall <khr@golang.org>
Thu, 30 Nov 2023 20:05:58 +0000 (20:05 +0000)
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>
src/bytes/boundary_test.go

index f9855fcb0520f3bdf9082f71ddf794c923c3d0b5..67f377e089634f15f06069c28d4779bb161b1614 100644 (file)
@@ -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)
+               }
+       }
+}