mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-08-05 12:58:53 +00:00
Merge pull request #8 from lukesanantonio/fix-empty-file-segfault
Prevent a segfault when loading an empty file
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user