]> git.saurik.com Git - wxWidgets.git/commitdiff
Prevent crashes in wxFFile(Input|Output)Stream: Do not call Eof() or Error()
authorDavid Elliott <dfe@tgwbd.org>
Tue, 16 Nov 2004 03:15:00 +0000 (03:15 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Tue, 16 Nov 2004 03:15:00 +0000 (03:15 +0000)
without first checking IsOpened().

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30558 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/wfstream.cpp

index e40bc2fcfa23f92d4cd511c5482b0499200b4e64..59d89d127ec6e766d306d426e2fde6806665b0a1 100644 (file)
@@ -236,7 +236,8 @@ size_t wxFFileInputStream::OnSysRead(void *buffer, size_t size)
 {
     ssize_t ret = m_file->Read(buffer, size);
 
-    if (m_file->Eof())
+    // It is not safe to call Eof() if the file is not opened.
+    if (!m_file->IsOpened() || m_file->Eof())
         m_lasterror = wxSTREAM_EOF;
     if (ret == wxInvalidOffset)
     {
@@ -314,7 +315,8 @@ wxFFileOutputStream::~wxFFileOutputStream()
 size_t wxFFileOutputStream::OnSysWrite(const void *buffer, size_t size)
 {
     size_t ret = m_file->Write(buffer, size);
-    if (m_file->Error())
+    // It is not safe to call Error() if the file is not opened.
+    if (!m_file->IsOpened() || m_file->Error())
         m_lasterror = wxSTREAM_WRITE_ERROR;
     else
         m_lasterror = wxSTREAM_NO_ERROR;