Handle exceptions in VFS C API.
PiperOrigin-RevId: 817688877 Change-Id: Ia2e306fe4cd1848eb5731212aa4e959080a9d377
This commit is contained in:
committed by
Copybara-Service
parent
b63252e4bb
commit
9e0885a4fa
@@ -1140,7 +1140,13 @@ std::vector<uint8_t> FileToMemory(const char* filename) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> buffer(long_filesize);
|
std::vector<uint8_t> buffer;
|
||||||
|
try {
|
||||||
|
buffer.resize(long_filesize);
|
||||||
|
} catch (...) {
|
||||||
|
fclose(fp);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
// go back to start of file
|
// go back to start of file
|
||||||
if (fseek(fp, 0, SEEK_SET) != 0) {
|
if (fseek(fp, 0, SEEK_SET) != 0) {
|
||||||
|
|||||||
@@ -251,7 +251,12 @@ int mj_addBufferVFS(mjVFS* vfs, const char* name, const void* buffer,
|
|||||||
if (!(file = cvfs->AddFile(FilePath(name), std::move(inbuffer), 0))) {
|
if (!(file = cvfs->AddFile(FilePath(name), std::move(inbuffer), 0))) {
|
||||||
return 2; // AddFile failed, repeated name
|
return 2; // AddFile failed, repeated name
|
||||||
}
|
}
|
||||||
file->filedata.reserve(nbuffer);
|
try {
|
||||||
|
file->filedata.reserve(nbuffer);
|
||||||
|
} catch (...) {
|
||||||
|
cvfs->DeleteFile(file->filename); // delete file on error
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
file->filestamp = vfs_memcpy(file->filedata, buffer, nbuffer);
|
file->filestamp = vfs_memcpy(file->filedata, buffer, nbuffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user