Win32/File.cpp: Avoid potential race in concurrent writes

Uninitialized data is better than overwritten data. Affects SPU Cache (unprotected writes).
This commit is contained in:
Eladash 2023-09-02 11:01:38 +03:00 committed by Elad Ashkenazi
parent 3f7afb8375
commit 66b6bae596

View File

@ -1303,12 +1303,12 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
DWORD nwritten = 0;
OVERLAPPED ovl{};
const u64 pos = m_pos;
const u64 pos = m_pos.fetch_add(size);
ovl.Offset = DWORD(pos);
ovl.OffsetHigh = DWORD(pos >> 32);
ensure(WriteFile(m_handle, data, size, &nwritten, &ovl)); // "file::write"
ensure(nwritten == size);
nwritten_sum += nwritten;
m_pos += nwritten;
if (nwritten < size)
{