From 7b7e9a10c62458f58366ecb409490215653707a0 Mon Sep 17 00:00:00 2001 From: Roman Atachiants Date: Sun, 26 Jul 2026 01:27:35 +0400 Subject: [PATCH 1/2] Fix retained slices when decoding streams --- reader.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/reader.go b/reader.go index 36b2d69..fe8748c 100644 --- a/reader.go +++ b/reader.go @@ -156,7 +156,6 @@ func (r *sliceReader) Reset(b []byte) { // streamReader represents a reader implementation for a generic reader (i.e. streams) type streamReader struct { Reader - scratch [10]byte } // Reader represents the interface a reader should implement. @@ -179,12 +178,7 @@ func newStreamReader(r io.Reader) *streamReader { // Slice selects a sub-slice of next bytes. func (r *streamReader) Slice(n int) (buffer []byte, err error) { - if n <= 10 { - buffer = r.scratch[:n] - } else { - buffer = make([]byte, n, n) - } - + buffer = make([]byte, n) _, err = io.ReadFull(r, buffer) return } From 320aaac8797940cc0fcca8fc138660a619f338ef Mon Sep 17 00:00:00 2001 From: Roman Atachiants Date: Sun, 26 Jul 2026 01:27:59 +0400 Subject: [PATCH 2/2] Test nocopy strings decoded from streams --- nocopy/types_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/nocopy/types_test.go b/nocopy/types_test.go index 3f38ceb..8a4911d 100644 --- a/nocopy/types_test.go +++ b/nocopy/types_test.go @@ -4,12 +4,28 @@ package nocopy import ( + "bytes" "testing" "github.com/kelindar/binary" "github.com/stretchr/testify/assert" ) +func TestStreamDecodeRetainsStrings(t *testing.T) { + type pair struct { + First String + Second String + } + + want := pair{First: "first", Second: "second"} + data, err := binary.Marshal(want) + assert.NoError(t, err) + + var got pair + assert.NoError(t, binary.NewDecoder(bytes.NewReader(data)).Decode(&got)) + assert.Equal(t, want, got) +} + type composite map[string]column type column struct {