diff --git a/src/common/wfstream.cpp b/src/common/wfstream.cpp index e40bc2fcfa..59d89d127e 100644 --- a/src/common/wfstream.cpp +++ b/src/common/wfstream.cpp @@ -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;