diff --git a/include/wx/stream.h b/include/wx/stream.h index 9119658421..ed07ce61a8 100644 --- a/include/wx/stream.h +++ b/include/wx/stream.h @@ -64,7 +64,7 @@ public: bool operator!() const { return !IsOk(); } // reset the stream state - void Reset() { m_lasterror = wxSTREAM_NO_ERROR; } + void Reset(wxStreamError error = wxSTREAM_NO_ERROR) { m_lasterror = error; } // this doesn't make sense for all streams, always test its return value virtual size_t GetSize() const; diff --git a/interface/wx/stream.h b/interface/wx/stream.h index 36617cc091..4f3bb18a45 100644 --- a/interface/wx/stream.h +++ b/interface/wx/stream.h @@ -80,6 +80,18 @@ public: */ virtual bool IsSeekable() const; + /** + Resets the stream state. + + By default, resets the stream to good state, i.e. clears any errors. + Since wxWidgets 2.9.3 can be also used to explicitly set the state to + the specified error (the @a error argument didn't exist in the previous + versions). + + @see GetLastError() + */ + void Reset(wxStreamError error = wxSTREAM_NO_ERROR); + /** Returns the opposite of IsOk(). You can use this function to test the validity of the stream as if diff --git a/samples/docview/doc.cpp b/samples/docview/doc.cpp index 24f3984b16..e093d82ae3 100644 --- a/samples/docview/doc.cpp +++ b/samples/docview/doc.cpp @@ -79,6 +79,16 @@ DocumentIstream& DrawingDocument::LoadObject(DocumentIstream& istream) wxInt32 count = 0; stream >> count; + if ( count < 0 ) + { + wxLogWarning("Drawing document corrupted: invalid segments count."); +#if wxUSE_STD_IOSTREAM + istream.clear(std::ios::badbit); +#else + istream.Reset(wxSTREAM_READ_ERROR); +#endif + return istream; + } for ( int n = 0; n < count; n++ ) {