]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/ffile.cpp
fixing overrelease and out-of-bounds write, fixes #13725
[wxWidgets.git] / src / common / ffile.cpp
index 7d669169a661237ec52c0298711320476df3ed7b..ae196692041bcc9726fc2c5f530a178e5e394841 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        ffile.cpp
+// Name:        src/common/ffile.cpp
 // Purpose:     wxFFile encapsulates "FILE *" IO stream
 // Author:      Vadim Zeitlin
 // Modified by:
@@ -117,7 +117,9 @@ bool wxFFile::ReadAll(wxString *str, const wxMBConv& conv)
     }
 
     buf.data()[length] = 0;
-    *str = wxString(buf, conv);
+
+    wxString strTmp(buf, conv);
+    str->swap(strTmp);
 
     return true;
 }
@@ -244,7 +246,7 @@ wxFileOffset wxFFile::Length() const
     wxCHECK_MSG( IsOpened(), wxInvalidOffset,
                  wxT("wxFFile::Length(): file is closed!") );
 
-    wxFFile& self = *(wxFFile *)this;   // const_cast
+    wxFFile& self = *const_cast<wxFFile *>(this);
 
     wxFileOffset posOld = Tell();
     if ( posOld != wxInvalidOffset )