X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9bc3af3e642709425476f6232a19fe4f1bbb42b8..772513d82432ecf323bca55251551fd5c8a7562d:/src/common/stream.cpp diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 2f91128cac..fd50f8beac 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -5,7 +5,6 @@ // Modified by: VZ (23.11.00) to fix realloc()ing new[]ed memory, // general code review // Created: 11/07/98 -// RCS-ID: $Id$ // Copyright: (c) Guilhem Lavaux // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -917,7 +916,7 @@ bool wxInputStream::ReadAll(void *buffer_, size_t size) { char* buffer = static_cast(buffer_); - m_lastcount = 0; + size_t totalCount = 0; for ( ;; ) { @@ -928,7 +927,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 +938,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 +1075,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 +1083,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