From f3167760ff0c039fe6536f1b1c5c3c634c634c9d Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sat, 8 May 2021 01:56:58 +0900 Subject: [PATCH] Fix stream decoder --- decode_stream.go | 9 ++++++++- decode_string.go | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/decode_stream.go b/decode_stream.go index c5009a3..da75e8f 100644 --- a/decode_stream.go +++ b/decode_stream.go @@ -82,7 +82,14 @@ func (s *stream) readBuf() []byte { copy(s.buf, remainBuf) } remainLen := s.length - s.cursor - return s.buf[s.cursor+remainLen:] + remainNotNulCharNum := int64(0) + for i := int64(0); i < remainLen; i++ { + if s.buf[s.cursor+i] == nul { + break + } + remainNotNulCharNum++ + } + return s.buf[s.cursor+remainNotNulCharNum:] } func (s *stream) read() bool { diff --git a/decode_string.go b/decode_string.go index fc9aae2..8f1b0e5 100644 --- a/decode_string.go +++ b/decode_string.go @@ -213,6 +213,7 @@ func stringBytes(s *stream) ([]byte, error) { s.buf = append(append(append([]byte{}, s.buf[:cursor]...), runeErrBytes...), s.buf[cursor+1:]...) _, _, p = s.stat() cursor += runeErrBytesLen + s.length += runeErrBytesLen continue case nul: s.cursor = cursor @@ -238,6 +239,7 @@ func stringBytes(s *stream) ([]byte, error) { _, _, p = s.stat() } cursor += int64(len(b)) + s.length += int64(len(b)) continue } cursor++