From 1b495a94e632986d756f78b2dc2d643da351819e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 20 May 2013 15:26:22 +0000 Subject: [PATCH 1/1] Fix last count value after ReadAll() and WriteAll(). This corrects the bugs introduced when applying the patch adding these functions in r74034: we can't simply use m_lastcount directly in them because it's also modified by each call to Read() and Write(), so do use the temporary variable. See #12056. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74038 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/stream.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 2f91128cac..1b1c6baf04 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -917,7 +917,7 @@ bool wxInputStream::ReadAll(void *buffer_, size_t size) { char* buffer = static_cast(buffer_); - m_lastcount = 0; + size_t totalCount = 0; for ( ;; ) { @@ -928,7 +928,7 @@ bool wxInputStream::ReadAll(void *buffer_, size_t size) if ( !lastCount ) break; - m_lastcount += lastCount; + totalCount += lastCount; // ... Or if an error occurred on the stream. if ( !IsOk() ) @@ -939,14 +939,19 @@ bool wxInputStream::ReadAll(void *buffer_, size_t size) // "==" test, but be safe and avoid overflowing size even in case of // bugs in LastRead()). if ( lastCount >= size ) - return true; + { + size = 0; + break; + } // Advance the buffer before trying to read the rest of data. size -= lastCount; buffer += lastCount; } - return false; + m_lastcount = totalCount; + + return size == 0; } wxFileOffset wxInputStream::SeekI(wxFileOffset pos, wxSeekMode mode) @@ -1071,7 +1076,7 @@ bool wxOutputStream::WriteAll(const void *buffer_, size_t size) // This exactly mirrors ReadAll(), see there for more comments. const char* buffer = static_cast(buffer_); - m_lastcount = 0; + size_t totalCount = 0; for ( ;; ) { @@ -1079,19 +1084,23 @@ bool wxOutputStream::WriteAll(const void *buffer_, size_t size) if ( !lastCount ) break; - m_lastcount += lastCount; + totalCount += lastCount; if ( !IsOk() ) break; if ( lastCount >= size ) - return true; + { + size = 0; + break; + } size -= lastCount; buffer += lastCount; } - return false; + m_lastcount = totalCount; + return size == 0; } wxFileOffset wxOutputStream::TellO() const -- 2.47.2