bug fix for wxBufferedInputStream::LastCount() after Read()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13483 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-01-09 20:18:20 +00:00
parent 42dcacf02b
commit e9f692911d

View File

@@ -719,25 +719,32 @@ char *wxInputStream::AllocSpaceWBack(size_t needed_size)
size_t wxInputStream::GetWBack(void *buf, size_t bsize) size_t wxInputStream::GetWBack(void *buf, size_t bsize)
{ {
size_t toget = m_wbacksize-m_wbackcur;
if (!m_wback) if (!m_wback)
return 0; return 0;
if (bsize < toget) // how many bytes do we have in the buffer?
toget = bsize; size_t toget = m_wbacksize - m_wbackcur;
memcpy(buf, (m_wback+m_wbackcur), toget); if ( bsize < toget )
{
// we won't read everything
toget = bsize;
}
// copy the data from the cache
memcpy(buf, m_wback + m_wbackcur, toget);
m_wbackcur += toget; m_wbackcur += toget;
if ( m_wbackcur == m_wbacksize ) if ( m_wbackcur == m_wbacksize )
{ {
// TODO: should we really free it here all the time? maybe keep it?
free(m_wback); free(m_wback);
m_wback = NULL; m_wback = NULL;
m_wbacksize = 0; m_wbacksize = 0;
m_wbackcur = 0; m_wbackcur = 0;
} }
// return the number of bytes copied
return toget; return toget;
} }
@@ -1028,20 +1035,27 @@ char wxBufferedInputStream::Peek()
wxInputStream& wxBufferedInputStream::Read(void *buf, size_t size) wxInputStream& wxBufferedInputStream::Read(void *buf, size_t size)
{ {
size_t retsize; // reset the error flag
retsize = GetWBack(buf, size);
m_lastcount = retsize;
if ( retsize == size )
{
m_lasterror = wxStream_NOERROR; m_lasterror = wxStream_NOERROR;
return *this;
} // first read from the already cached data
size -= retsize; m_lastcount = GetWBack(buf, size);
buf = (char *)buf + retsize;
// do we have to read anything more?
if ( m_lastcount < size )
{
size -= m_lastcount;
buf = (char *)buf + m_lastcount;
// the call to wxStreamBuffer::Read() below will reset our m_lastcount,
// so save it
size_t countOld = m_lastcount;
m_i_streambuf->Read(buf, size); m_i_streambuf->Read(buf, size);
m_lastcount += countOld;
}
return *this; return *this;
} }