diff --git a/lib/cgolz4/cgolz4.go b/lib/cgolz4/cgolz4.go index dc9563dd..84c226cf 100644 --- a/lib/cgolz4/cgolz4.go +++ b/lib/cgolz4/cgolz4.go @@ -346,6 +346,12 @@ func (c *WriterRecycler) Close() error { return nil } +func minDstLenForBlockMaxLen() uint64 { + return uint64(C.cgolz4_compress_min_dst_len(C.uint32_t(blockMaxLen))) +} + +const writerBufLen = 2*blockMaxLen + 16 + // Writer compresses to the lz4 format. // // Compressed bytes may be buffered and not sent to the underlying io.Writer @@ -353,7 +359,7 @@ func (c *WriterRecycler) Close() error { // // The zero value is not usable until Reset is called. type Writer struct { - buf [2 * blockMaxLen]byte + buf [writerBufLen]byte j uint32 w io.Writer begun bool diff --git a/lib/cgolz4/cgolz4_test.go b/lib/cgolz4/cgolz4_test.go index 4748ced3..3f9b79ed 100644 --- a/lib/cgolz4/cgolz4_test.go +++ b/lib/cgolz4/cgolz4_test.go @@ -89,3 +89,9 @@ func TestRoundTrip(tt *testing.T) { } } } + +func TestWriterBufIsLargeEnough(tt *testing.T) { + if m := minDstLenForBlockMaxLen(); writerBufLen < m { + tt.Fatalf("writerBufLen: got %d, want >= %d", writerBufLen, m) + } +}