X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/13111b2ac81e694d6b69822dff61838ae66052b2..ec7cd4c478ae1a192c21a89a41bd499e5bc0908a:/src/common/datstrm.cpp?ds=sidebyside diff --git a/src/common/datstrm.cpp b/src/common/datstrm.cpp index 433c90472a..e0bd854d4c 100644 --- a/src/common/datstrm.cpp +++ b/src/common/datstrm.cpp @@ -86,15 +86,27 @@ double wxDataInputStream::ReadDouble() wxString wxDataInputStream::ReadString() { - wxString s; size_t len; len = Read32(); - m_input->Read(s.GetWriteBuf(len), len); - s.UngetWriteBuf(); - - return s; + if (len > 0) + { +#if wxUSE_UNICODE + char *tmp = new char[len + 1]; + m_input->Read(tmp, len); + tmp[len] = 0; + wxString s(tmp); + delete[] tmp; +#else + wxString s; + m_input->Read(s.GetWriteBuf(len), len); + s.UngetWriteBuf(); +#endif + return s; + } + else + return wxEmptyString; } wxDataInputStream& wxDataInputStream::operator>>(wxString& s) @@ -195,8 +207,9 @@ void wxDataOutputStream::Write8(wxUint8 i) void wxDataOutputStream::WriteString(const wxString& string) { const wxWX2MBbuf buf = string.mb_str(); - Write32(string.Length()); - m_output->Write(buf, string.Len()); + Write32(string.Len()); + if (string.Len() > 0) + m_output->Write(buf, string.Len()); } // Must be at global scope for VC++ 5 @@ -224,7 +237,7 @@ wxDataOutputStream& wxDataOutputStream::operator<<(const wxChar *string) return *this; } -wxDataOutputStream& wxDataOutputStream::operator<<(wxString& string) +wxDataOutputStream& wxDataOutputStream::operator<<(const wxString& string) { WriteString(string); return *this;