mirror of
https://github.com/golang/go
synced 2024-11-26 06:47:58 -07:00
compress/flate: add a copy overrun test.
R=rsc, r CC=golang-dev https://golang.org/cl/6143043
This commit is contained in:
parent
83aa040c45
commit
86a91539b8
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user