- const size_t fileLen = Length();
- wxCharBuffer buf(fileLen + 1);
- if ( (fread(buf.data(), sizeof(char), fileLen, m_fp) < fileLen) || Error() )
+ wxCharBuffer buf(length);
+
+ // note that real length may be less than file length for text files with DOS EOLs
+ // ('\r's get dropped by CRT when reading which means that we have
+ // realLen = fileLen - numOfLinesInTheFile)
+ length = fread(buf.data(), 1, length, m_fp);
+
+ if ( Error() )