From 385112a8b36f3fbe28a7a7b24bed714673d5b3c8 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 6 Nov 2002 10:46:30 +0000 Subject: [PATCH] Fixed wxMemoryStream to make it work without any associated stream. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17738 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/stream.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 4ce6675f05..d89517faa7 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -259,6 +259,7 @@ void wxStreamBuffer::GetFromBuffer(void *buffer, size_t size) void wxStreamBuffer::PutToBuffer(const void *buffer, size_t size) { size_t left = GetBytesLeft(); + if ( size > left ) { if ( m_fixed ) @@ -445,17 +446,22 @@ size_t wxStreamBuffer::Read(wxStreamBuffer *dbuf) size_t wxStreamBuffer::Write(const void *buffer, size_t size) { - wxOutputStream *outStream = GetOutputStream(); - - wxCHECK_MSG( outStream, 0, _T("should have a stream in wxStreamBuffer") ); - - // lasterror is reset before all new IO calls - m_stream->Reset(); + if (m_stream) + { + // lasterror is reset before all new IO calls + m_stream->Reset(); + } + + size_t ret = 0; if ( !HasBuffer() && m_fixed ) { + wxOutputStream *outStream = GetOutputStream(); + + wxCHECK_MSG( outStream, 0, _T("should have a stream in wxStreamBuffer") ); + // no buffer, just forward the call to the stream - m_stream->m_lastcount = outStream->OnSysWrite(buffer, size); + ret = outStream->OnSysWrite(buffer, size); } else // we [may] have a buffer, use it { @@ -473,6 +479,7 @@ size_t wxStreamBuffer::Write(const void *buffer, size_t size) // // FIXME: fine, but if it fails we should (re)try writing it by // chunks as this will (hopefully) always work (VZ) + if ( size > left && m_fixed ) { PutToBuffer(buffer, left); @@ -495,10 +502,16 @@ size_t wxStreamBuffer::Write(const void *buffer, size_t size) } } - m_stream->m_lastcount = orig_size - size; + ret = orig_size - size; } - return m_stream->m_lastcount; + if (m_stream) + { + // i am not entirely sure what we do this for + m_stream->m_lastcount = ret; + } + + return ret; } size_t wxStreamBuffer::Write(wxStreamBuffer *sbuf)