From: Guillermo Rodriguez Garcia Date: Wed, 8 Dec 1999 09:58:42 +0000 (+0000) Subject: Fixed wxInputStream::Ungetch behaviour so that if you X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5ac8158ad90d6e4d88d1761f9d7807c70e5414d8 Fixed wxInputStream::Ungetch behaviour so that if you a) unget a buffer (AAABBB) b) read some data (AAA) c) unget a second buffer (CCC) it works OK now (you will get CCCBBB, instead of CCCAAABBB as before) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4870 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 84a0b26973..5c508e98a2 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -494,23 +494,30 @@ wxInputStream::~wxInputStream() char *wxInputStream::AllocSpaceWBack(size_t needed_size) { char *temp_b; - size_t old_size; + size_t toget; - old_size = m_wbacksize; - m_wbacksize += needed_size; + /* get number of bytes left from previous wback buffer */ + toget = m_wbacksize - m_wbackcur; - if (!m_wback) - temp_b = (char *)malloc(m_wbacksize); - else - temp_b = (char *)realloc(m_wback, m_wbacksize); + /* allocate a buffer large enough to hold prev + new data */ + temp_b = (char *) malloc(needed_size + toget); if (!temp_b) - return (char*)NULL; + return NULL; + + /* copy previous data (and free old buffer) if needed */ + if (m_wback) + { + memmove(temp_b + needed_size, m_wback + m_wbackcur, toget); + free(m_wback); + } + + /* done */ m_wback = temp_b; + m_wbackcur = 0; + m_wbacksize = needed_size + toget; - memmove(m_wback+needed_size, m_wback, old_size); - - return (char *)(m_wback); + return (char *) m_wback; } size_t wxInputStream::GetWBack(char *buf, size_t bsize) @@ -581,6 +588,7 @@ wxInputStream& wxInputStream::Read(void *buffer, size_t size) size -= retsize; buf += retsize; + // GRG: shouldn't we also add retsize to m_lastcount here? m_lastcount = OnSysRead(buf, size); return *this; }