X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cc437b9654244bfb8b638f98252aa34145323b9c..659d10cafe43bd53dc21b35f094ba77bb341cddc:/src/common/stream.cpp diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 94a1244b2b..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 @@ -1117,22 +1126,23 @@ IMPLEMENT_DYNAMIC_CLASS(wxCountingOutputStream, wxOutputStream) wxCountingOutputStream::wxCountingOutputStream () { - m_currentPos = 0; + m_currentPos = + m_lastPos = 0; } wxFileOffset wxCountingOutputStream::GetLength() const { - return m_lastcount; + return m_lastPos; } size_t wxCountingOutputStream::OnSysWrite(const void *WXUNUSED(buffer), size_t size) { m_currentPos += size; - if (m_currentPos > m_lastcount) - m_lastcount = m_currentPos; + if ( m_currentPos > m_lastPos ) + m_lastPos = m_currentPos; - return m_currentPos; + return size; } wxFileOffset wxCountingOutputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode) @@ -1146,12 +1156,12 @@ wxFileOffset wxCountingOutputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode break; case wxFromEnd: - new_pos = m_lastcount + new_pos; - wxCHECK_MSG( (wxFileOffset)new_pos == (wxFileOffset)(m_lastcount + pos), wxInvalidOffset, wxT("huge position not supported") ); + new_pos += m_lastPos; + wxCHECK_MSG( (wxFileOffset)new_pos == (wxFileOffset)(m_lastPos + pos), wxInvalidOffset, wxT("huge position not supported") ); break; case wxFromCurrent: - new_pos = m_currentPos + new_pos; + new_pos += m_currentPos; wxCHECK_MSG( (wxFileOffset)new_pos == (wxFileOffset)(m_currentPos + pos), wxInvalidOffset, wxT("huge position not supported") ); break; @@ -1162,8 +1172,8 @@ wxFileOffset wxCountingOutputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode m_currentPos = new_pos; - if (m_currentPos > m_lastcount) - m_lastcount = m_currentPos; + if ( m_currentPos > m_lastPos ) + m_lastPos = m_currentPos; return m_currentPos; }