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
This commit is contained in:
David Elliott 2004-11-16 03:15:00 +00:00
parent f12a90c7c2
commit b9d84e4c06

View File

@ -236,7 +236,8 @@ size_t wxFFileInputStream::OnSysRead(void *buffer, size_t size)
{ {
ssize_t ret = m_file->Read(buffer, 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; m_lasterror = wxSTREAM_EOF;
if (ret == wxInvalidOffset) if (ret == wxInvalidOffset)
{ {
@ -314,7 +315,8 @@ wxFFileOutputStream::~wxFFileOutputStream()
size_t wxFFileOutputStream::OnSysWrite(const void *buffer, size_t size) size_t wxFFileOutputStream::OnSysWrite(const void *buffer, size_t size)
{ {
size_t ret = m_file->Write(buffer, 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; m_lasterror = wxSTREAM_WRITE_ERROR;
else else
m_lasterror = wxSTREAM_NO_ERROR; m_lasterror = wxSTREAM_NO_ERROR;