{
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)
{
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;