FileSystem: Fix crash on file open fail in WriteAtomicRenamedFile()

This commit is contained in:
Stenzek 2024-08-09 12:32:39 +10:00
parent b2ca23e9da
commit 8ad133dbc0
No known key found for this signature in database

View file

@ -1235,6 +1235,9 @@ bool FileSystem::WriteAtomicRenamedFile(std::string filename, const void* data,
Error* error /*= nullptr*/)
{
AtomicRenamedFile fp = CreateAtomicRenamedFile(std::move(filename), "wb", error);
if (!fp)
return false;
if (data_length > 0 && std::fwrite(data, 1u, data_length, fp.get()) != data_length) [[unlikely]]
{
Error::SetErrno(error, "fwrite() failed: ", errno);