diff --git a/deferred.go b/deferred.go index c2bb6ec..94e4ee6 100644 --- a/deferred.go +++ b/deferred.go @@ -24,10 +24,7 @@ func (d *Deferred) MarshalCBOR(w io.Writer) error { } func (d *Deferred) UnmarshalCBOR(br io.Reader) (err error) { - // Reuse any existing buffers. - reusedBuf := d.Raw[:0] - d.Raw = nil - buf := bytes.NewBuffer(reusedBuf) + buf := bytes.NewBuffer(nil) // Allocate some scratch space. scratch := make([]byte, maxHeaderSize) @@ -90,6 +87,7 @@ func (d *Deferred) UnmarshalCBOR(br io.Reader) (err error) { return fmt.Errorf("unhandled deferred cbor type: %d", maj) } } - d.Raw = buf.Bytes() + d.Raw = d.Raw[:0] + d.Raw = append(d.Raw, buf.Bytes()...) return nil }