- const size_t fileLen = Length();
- wxCharBuffer buf(fileLen + 1);
- if ( (fread(buf.data(), sizeof(char), fileLen, m_fp) < fileLen) || Error() )
+ wxCharBuffer buf(length + 1);
+
+ // 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(), sizeof(char), length, m_fp);
+
+ if ( Error() )