Fail early if trying to read a string larger than the nif file size.

This is much better than failing after a few minutes with an out of memory error.
moveref
Arthur Moore 10 years ago
parent 912dcdc418
commit 018f4e6895

@ -83,6 +83,11 @@ Transformation NIFStream::getTrafo()
std::string NIFStream::getString(size_t length)
{
//Make sure we're not reading in too large of a string
unsigned int fileSize = inp->size();
if(fileSize != 0 && fileSize < length)
file->fail("Attempted to read a string with " + Ogre::StringConverter::toString(length) + "characters , but file is only "+Ogre::StringConverter::toString(fileSize)+ "bytes!");
std::vector<char> str (length+1, 0);
if(inp->read(&str[0], length) != length)

Loading…
Cancel
Save