]> Cypherpunks repositories - gostls13.git/commitdiff
compress/flate: add a copy overrun test.
authorNigel Tao <nigeltao@golang.org>
Tue, 1 May 2012 04:28:33 +0000 (14:28 +1000)
committerNigel Tao <nigeltao@golang.org>
Tue, 1 May 2012 04:28:33 +0000 (14:28 +1000)
R=rsc, r
CC=golang-dev
https://golang.org/cl/6143043

src/pkg/compress/flate/copy_test.go

index d13941cf1c05f0c173b68004c6564595eebf7584..a9281d446e9c407aeea97e710956aaf50720a123 100644 (file)
@@ -29,7 +29,7 @@ func TestForwardCopy(t *testing.T) {
                {0, 0, 0, 0, ""},
        }
        for _, tc := range testCases {
-               b := []byte("012345678")
+               b := []byte("0123456789")
                dst := b[tc.dst0:tc.dst1]
                src := b[tc.src0:tc.src1]
                n := forwardCopy(dst, src)
@@ -38,5 +38,15 @@ func TestForwardCopy(t *testing.T) {
                        t.Errorf("dst=b[%d:%d], src=b[%d:%d]: got %q, want %q",
                                tc.dst0, tc.dst1, tc.src0, tc.src1, got, tc.want)
                }
+               // Check that the bytes outside of dst[:n] were not modified.
+               for i, x := range b {
+                       if i >= tc.dst0 && i < tc.dst0+n {
+                               continue
+                       }
+                       if int(x) != '0'+i {
+                               t.Errorf("dst=b[%d:%d], src=b[%d:%d]: copy overrun at b[%d]: got '%c', want '%c'",
+                                       tc.dst0, tc.dst1, tc.src0, tc.src1, i, x, '0'+i)
+                       }
+               }
        }
 }