From a2bbf76cf4628d1ffd21b34654cd088b8c43ce1b Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 27 Jul 2017 20:49:49 +0200 Subject: [PATCH] StreamReader: fix out-of-range exception --- code/IOStreamBuffer.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/code/IOStreamBuffer.h b/code/IOStreamBuffer.h index 6ca37b6..d7528de 100644 --- a/code/IOStreamBuffer.h +++ b/code/IOStreamBuffer.h @@ -284,11 +284,17 @@ bool IOStreamBuffer::getNextDataLine( std::vector &buffer, T continuationT return true; } +static +inline +bool isEndOfCache( size_t pos, size_t cacheSize ) { + return ( pos == cacheSize ); +} + template inline bool IOStreamBuffer::getNextLine(std::vector &buffer) { buffer.resize(m_cacheSize); - if (m_cachePos == m_cacheSize || 0 == m_filePos) { + if ( isEndOfCache( m_cachePos, m_cacheSize ) || 0 == m_filePos) { if (!readNextBlock()) { return false; } @@ -300,11 +306,16 @@ bool IOStreamBuffer::getNextLine(std::vector &buffer) { ++m_cachePos; } ++m_cachePos; + if ( isEndOfCache( m_cachePos, m_cacheSize ) ) { + if ( !readNextBlock() ) { + return false; + } + } } size_t i = 0; - while (!IsLineEnd(m_cache[m_cachePos])) { - buffer[i] = m_cache[m_cachePos]; + while (!IsLineEnd(m_cache[ m_cachePos ])) { + buffer[i] = m_cache[ m_cachePos ]; m_cachePos++; i++; if (m_cachePos >= m_cacheSize) { -- 2.7.4