diff --git a/roaring64/roaring64.go b/roaring64/roaring64.go index 712f3ea4..ebea5ffc 100644 --- a/roaring64/roaring64.go +++ b/roaring64/roaring64.go @@ -87,11 +87,10 @@ func (rb *Bitmap) WriteTo(stream io.Writer) (int64, error) { func (rb *Bitmap) FromUnsafeBytes(data []byte) (p int64, err error) { stream := internal.NewByteBuffer(data) sizeBuf := make([]byte, 8) - n, err := stream.Read(sizeBuf) + _, err = stream.Read(sizeBuf) if err != nil { return 0, err } - p += int64(n) size := binary.LittleEndian.Uint64(sizeBuf) rb.highlowcontainer.resize(0) @@ -115,17 +114,16 @@ func (rb *Bitmap) FromUnsafeBytes(data []byte) (p int64, err error) { if err != nil { return 0, fmt.Errorf("error in bitmap.UnsafeFromBytes: could not read key #%d: %w", i, err) } - p += 4 rb.highlowcontainer.keys[i] = binary.LittleEndian.Uint32(keyBuf) rb.highlowcontainer.containers[i] = roaring.NewBitmap() n, err := rb.highlowcontainer.containers[i].ReadFrom(stream) + if n == 0 || err != nil { return int64(n), fmt.Errorf("Could not deserialize bitmap for key #%d: %s", i, err) } - p += int64(n) } - return p, nil + return stream.GetReadBytes(), nil } // ReadFrom reads a serialized version of this bitmap from stream. @@ -167,12 +165,12 @@ func (rb *Bitmap) ReadFrom(stream io.Reader) (p int64, err error) { rb.highlowcontainer.keys[i] = binary.LittleEndian.Uint32(keyBuf) rb.highlowcontainer.containers[i] = roaring.NewBitmap() n, err := rb.highlowcontainer.containers[i].ReadFrom(stream) + if n == 0 || err != nil { return int64(n), fmt.Errorf("Could not deserialize bitmap for key #%d: %s", i, err) } p += int64(n) } - return p, nil } diff --git a/roaring64/roaring64cow_test.go b/roaring64/roaring64cow_test.go index b3b7bee9..7466e56c 100644 --- a/roaring64/roaring64cow_test.go +++ b/roaring64/roaring64cow_test.go @@ -1481,7 +1481,6 @@ func TestBigRandomCOW(t *testing.T) { } func rTestCOW(t *testing.T, N int) { - log.Println("rtest N=", N) for gap := 1; gap <= 65536; gap *= 2 { bs1 := bitset.New(0) rb1 := NewBitmap() diff --git a/roaring64/serialization_test.go b/roaring64/serialization_test.go index 5660133f..7655d8b8 100644 --- a/roaring64/serialization_test.go +++ b/roaring64/serialization_test.go @@ -20,13 +20,13 @@ import ( func fromUnsafeBytesChecked(t *testing.T, unsafeBm *Bitmap, b []byte) { var r bytes.Reader r.Reset(b) - var safeBm Bitmap + safeBm := NewBitmap() safeCount, err := safeBm.ReadFrom(&r) unsafeCount, err := unsafeBm.FromUnsafeBytes(b) require.NoError(t, err) require.NoError(t, err) - assert.EqualValues(t, safeCount, unsafeCount) assert.True(t, safeBm.Equals(unsafeBm)) + assert.EqualValues(t, safeCount, unsafeCount) } func TestSerializationOfEmptyBitmap(t *testing.T) { diff --git a/roaring_test.go b/roaring_test.go index cd299bc1..520da6ab 100644 --- a/roaring_test.go +++ b/roaring_test.go @@ -95,8 +95,6 @@ func checkValidity(t *testing.T, rb *Bitmap) { } func hashTest(t *testing.T, N uint64) { - t.Log("rtest N=", N) - hashes := map[uint64]struct{}{} count := 0 @@ -1944,7 +1942,6 @@ func TestHash(t *testing.T) { } func rTest(t *testing.T, N int) { - t.Log("rtest N=", N) for gap := 1; gap <= 65536; gap *= 2 { bs1 := bitset.New(0) rb1 := NewBitmap() diff --git a/roaringcow_test.go b/roaringcow_test.go index 94d07acb..c04acae4 100644 --- a/roaringcow_test.go +++ b/roaringcow_test.go @@ -1533,7 +1533,6 @@ func TestBigRandomCOW(t *testing.T) { } func rTestCOW(t *testing.T, N int) { - t.Log("rtest N=", N) for gap := 1; gap <= 65536; gap *= 2 { bs1 := bitset.New(0) rb1 := NewBitmap()