]> git.saurik.com Git - wxWidgets.git/commitdiff
made wxFFile a bit more safe: don't crash when Tell() and Length() are called on...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Feb 2004 15:44:40 +0000 (15:44 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Feb 2004 15:44:40 +0000 (15:44 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25566 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/ffile.h
src/common/ffile.cpp

index e9eaf36db73b643cd49da2d534c46e2e1a908711..8f8ffde0147c4677b2509b9a7f3d7a3f33b3a800 100644 (file)
@@ -86,7 +86,8 @@ public:
     // get current file length
   size_t Length() const;
 
-  // simple accessors
+  // simple accessors: note that Eof() and Error() may only be called if
+  // IsOpened()!
     // is file opened?
   bool IsOpened() const { return m_fp != NULL; }
     // is end of file reached?
index 95105fbfedea2ebc60f4b60c317bdf2a54b1e84b..503e5bfa0d886350b3109fc2386bcac90209a2a6 100644 (file)
@@ -206,6 +206,9 @@ bool wxFFile::Seek(long ofs, wxSeekMode mode)
 
 size_t wxFFile::Tell() const
 {
+    wxCHECK_MSG( IsOpened(), (size_t)-1,
+                 _T("wxFFile::Tell(): file is closed!") );
+
     long rc = ftell(m_fp);
     if ( rc == -1 )
     {
@@ -218,6 +221,9 @@ size_t wxFFile::Tell() const
 
 size_t wxFFile::Length() const
 {
+    wxCHECK_MSG( IsOpened(), (size_t)-1,
+                 _T("wxFFile::Length(): file is closed!") );
+
     wxFFile& self = *(wxFFile *)this;   // const_cast
 
     size_t posOld = Tell();