From 31055a3cd357a764c9e329acc34106caa26aadbe Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Fri, 19 Jul 2019 10:13:32 +0000 Subject: [PATCH] Bugfix for parsekit.read: when filling the buffer, the read offset was not taken into account for determining how many bytes could be read. --- read/read.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/read/read.go b/read/read.go index 8ff6c72..e35a9b9 100644 --- a/read/read.go +++ b/read/read.go @@ -126,7 +126,6 @@ func (buf *Buffer) RuneAt(offset int) (rune, int, error) { return utf8.RuneError, 0, buf.err } r, w := utf8.DecodeRune(buf.buffer[buf.start+offset:]) - return r, w, nil } @@ -166,7 +165,8 @@ func (buf *Buffer) fill(minBytes int) { // This is more efficient than only filling the data up to the point where // we can read the data at the 'minBytes' position. Ideally, the buffer is // filled completely with data to work with. - for buf.len < buf.cap { + availableLen := buf.cap - buf.start + for buf.len < availableLen { // Read bytes from our source, and append them to the end of the // current buffer data. n, err := buf.bufio.Read(buf.buffer[buf.len:buf.cap]) @@ -193,6 +193,7 @@ func (buf *Buffer) grow(minBytes int) { if buf.start > 0 && minBytes <= buf.cap { copy(buf.buffer, buf.buffer[buf.start:buf.start+buf.len]) buf.start = 0 + return } // Grow the buffer store by allocating a new one and copying the data.