diff --git a/common/buf/buffer.go b/common/buf/buffer.go index facf6812..2aa60e6a 100644 --- a/common/buf/buffer.go +++ b/common/buf/buffer.go @@ -13,6 +13,8 @@ const ( Size = 8192 ) +var zero = [Size * 10]byte{0} + var pool = bytespool.GetPool(Size) // ownership represents the data owner of the buffer. @@ -150,6 +152,7 @@ func (b *Buffer) Extend(n int32) []byte { } ext := b.v[b.end:end] b.end = end + copy(ext, zero[:]) return ext } @@ -198,6 +201,7 @@ func (b *Buffer) Check() { // Resize cuts the buffer at the given position. func (b *Buffer) Resize(from, to int32) { + oldEnd := b.end if from < 0 { from += b.Len() } @@ -210,6 +214,9 @@ func (b *Buffer) Resize(from, to int32) { b.end = b.start + to b.start += from b.Check() + if b.end > oldEnd { + copy(b.v[oldEnd:b.end], zero[:]) + } } // Advance cuts the buffer at the given position.