X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/121fa06ab6af9129e776af13949fc251a3cafc49..8998887c224924d5f6f4601597c162d6429495e1:/src/common/sstream.cpp diff --git a/src/common/sstream.cpp b/src/common/sstream.cpp index 7ceedb65b5..1a87534dc3 100644 --- a/src/common/sstream.cpp +++ b/src/common/sstream.cpp @@ -38,6 +38,8 @@ off_t wxStringInputStream::OnSysSeek(off_t ofs, wxSeekMode mode) { + const size_t ofsMax = m_str.length()*sizeof(wxChar); + switch ( mode ) { case wxFromStart: @@ -45,7 +47,7 @@ off_t wxStringInputStream::OnSysSeek(off_t ofs, wxSeekMode mode) break; case wxFromEnd: - ofs += m_str.length()*sizeof(wxChar); + ofs += ofsMax; break; case wxFromCurrent: @@ -57,6 +59,9 @@ off_t wxStringInputStream::OnSysSeek(off_t ofs, wxSeekMode mode) return wxInvalidOffset; } + if ( ofs < 0 || wx_static_cast(size_t, ofs) >= ofsMax ) + return wxInvalidOffset; + m_pos = wx_static_cast(size_t, ofs); return ofs; @@ -96,6 +101,15 @@ size_t wxStringInputStream::OnSysRead(void *buffer, size_t size) // wxStringOutputStream implementation // ============================================================================ +// ---------------------------------------------------------------------------- +// seek/tell +// ---------------------------------------------------------------------------- + +off_t wxStringOutputStream::OnSysTell() const +{ + return wx_static_cast(off_t, m_pos); +} + // ---------------------------------------------------------------------------- // actual IO // ---------------------------------------------------------------------------- @@ -107,10 +121,13 @@ size_t wxStringOutputStream::OnSysWrite(const void *buffer, size_t size) const wxChar *p = wx_static_cast(const wxChar *, buffer); - m_str->Append(wxString(p, p + len + 1)); + m_str->Append(wxString(p, p + len)); // return number of bytes actually written - return len*sizeof(wxChar); + len *= sizeof(wxChar); + m_pos += len; + + return len; } #endif // wxUSE_STREAMS