Fix EOLs buffer shortening in wxFFile::ReadAll()
As the comments in the function explain, fread() may return a shorter buffer than expected due to CRT's implicit conversion of DOS EOLs to \n. The logic for handling this was however broken: it NUL-terminated the buffer appropriately, but that had no effect when later used in wxString constructor, which used buffer's length for string length. This resulted in slightly larger strings with uninitialized tails that were mostly invisible to the user as the tail would disappear anywhere the string was handled as a NULL-terminated C string. It also caused occassional UTF-8 conversion failures when the tailing bytes didn't form a valid sequence. Fixed by using wxCharBuffer::shrink() to properly truncate the buffer.
This commit is contained in:
parent
ce01d8286b
commit
17e2f8c477
@ -111,7 +111,8 @@ bool wxFFile::ReadAll(wxString *str, const wxMBConv& conv)
|
||||
return false;
|
||||
}
|
||||
|
||||
buf.data()[length] = 0;
|
||||
// shrink the buffer to possibly shorter data as explained above:
|
||||
buf.shrink(length);
|
||||
|
||||
wxString strTmp(buf, conv);
|
||||
str->swap(strTmp);
|
||||
|
Loading…
Reference in New Issue
Block a user