]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/file.cpp
simplify code so it always returns the same object
[wxWidgets.git] / src / common / file.cpp
index b2cd1bed5f6a0ff54889792d1773bd8c6bf97f47..e553b2c8335684745e81cfc636f69073b79fce4f 100644 (file)
@@ -295,20 +295,24 @@ bool wxFile::ReadAll(wxString *str, const wxMBConv& conv)
 {
     wxCHECK_MSG( str, false, wxS("Output string must be non-NULL") );
 
-    size_t length = wx_truncate_cast(size_t, Length());
+    ssize_t length = Length();
     wxCHECK_MSG( (wxFileOffset)length == Length(), false, wxT("huge file not supported") );
 
     wxCharBuffer buf(length);
     char* p = buf.data();
     for ( ;; )
     {
-        static const unsigned READSIZE = 4096;
+        static const ssize_t READSIZE = 4096;
 
         ssize_t nread = Read(p, length > READSIZE ? READSIZE : length);
         if ( nread == wxInvalidOffset )
             return false;
 
         p += nread;
+        if ( length <= nread )
+            break;
+
+        length -= nread;
     }
 
     *p = 0;