From fdc7e9a8181e9bcd15e282b5c357d246d19b2f46 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Sun, 7 Oct 2012 17:26:41 -0400 Subject: [PATCH] Commit Dick's INPUTSTREAM_LINE_READER patch. --- common/richio.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/common/richio.cpp b/common/richio.cpp index 5c1b0c29d0..0b3a1f8ef8 100644 --- a/common/richio.cpp +++ b/common/richio.cpp @@ -195,9 +195,8 @@ INPUTSTREAM_LINE_READER::INPUTSTREAM_LINE_READER( wxInputStream* aStream ) : unsigned INPUTSTREAM_LINE_READER::ReadLine() throw( IO_ERROR ) { length = 0; - line[0] = 0; - while( !m_stream->Eof() ) + for(;;) { if( length >= maxLineLength ) THROW_IO_ERROR( _( "Maximum line length exceeded" ) ); @@ -205,15 +204,19 @@ unsigned INPUTSTREAM_LINE_READER::ReadLine() throw( IO_ERROR ) if( length + 1 > capacity ) expandCapacity( capacity * 2 ); - line[ length ] = m_stream->GetC(); - length++; + // this read may fail, docs say to test LastRead() before trusting cc. + char cc = m_stream->GetC(); - if( line[ length - 1 ] == '\n' ) + if( !m_stream->LastRead() ) + break; + + line[ length++ ] = cc; + + if( cc == '\n' ) break; } line[ length ] = 0; - length -= 1; // lineNum is incremented even if there was no line read, because this // leads to better error reporting when we hit an end of file.