error checks around performing the resize

this throws on windows and causes undefined mappings on linux
This commit is contained in:
Green Sky
2025-01-24 00:27:58 +01:00
parent db73c90e34
commit 1780bd097a
2 changed files with 13 additions and 3 deletions

View File

@@ -24,8 +24,18 @@ struct File2RWMapped : public File2I {
_file_size = std::filesystem::file_size(native_file_path);
if (file_size >= 0 && _file_size != file_size) {
_file_size = file_size;
std::filesystem::resize_file(native_file_path, file_size); // ensure size, usually sparse
try {
std::filesystem::resize_file(native_file_path, file_size); // ensure size, usually sparse
} catch (...) {
std::cerr << "FileRWMapped error: resizing file failed\n";
return;
}
_file_size = std::filesystem::file_size(native_file_path);
if (_file_size != file_size) {
std::cerr << "FileRWMapped error: resizing file failed (size mismatch)\n";
return;
}
}
std::error_code err;