Prevent a segfault when loading an empty file

If the size of the file is zero, we just signal an error and return false.
This commit is contained in:
Luke San Antonio 2016-06-23 14:17:37 -04:00
parent cf6e07b1ec
commit b310b4a32e

View File

@ -2286,6 +2286,13 @@ bool TinyGLTFLoader::LoadASCIIFromFile(Scene *scene, std::string *err,
size_t sz = static_cast<size_t>(f.tellg());
std::vector<char> buf(sz);
if (sz == 0) {
if (err) {
(*err) = "Empty file.";
}
return false;
}
f.seekg(0, f.beg);
f.read(&buf.at(0), static_cast<std::streamsize>(sz));
f.close();