bnoazx005 / TDEngine2

TDEngine2 is a cross-platform game engine
Apache License 2.0
18 stars 4 forks source link

[Bug] A result of ReadToEnd of CTextFileReader contains a few extra '\0' at its end #4

Closed bnoazx005 closed 5 years ago

bnoazx005 commented 5 years ago

Bug report

ReadToEnd method of CTextFileReader returns a string, which is oversized because of extra '\0' symbols at its end. It seems ok when you don't try to insert it in the middle of another string. In this case the result string will be cropped.

Environment

Win32 (Win10) / Visual Studio 2017

Steps to reproduce the issue

//...
E_RESULT_CODE result;

ITextFileReader* pFileReader = mpFileSystem->Create("filename", result);

std::string textFileData = pFileReader->ReadToEnd();
std::string testString = "this is a test string, which you've never seen!";
std::string result = textFileData + testString; 
/* will contain "{textFileData}\0\0...\0"this is a test string, which you've never seen!" */
//...

What's the expected result?

The result that is generated with ReadToEnd should not contain '\0' at all.

What's the actual result?

The result of ReadToEnd contains a few extra '\0' at its end.