From b9d84e4c0602cfae0b72112bb987d19cc7d6d682 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Tue, 16 Nov 2004 03:15:00 +0000 Subject: [PATCH] Prevent crashes in wxFFile(Input|Output)Stream: Do not call Eof() or Error() 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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;