Windows: check result of WriteFile and don't block if it is failing (Coverity)

This commit is contained in:
Mounir IDRASSI 2022-03-26 20:01:05 +01:00
parent 05fd14006d
commit a0809fe85c
No known key found for this signature in database
GPG Key ID: 02C30AE90FAE4A6F

View File

@ -1216,10 +1216,16 @@ BOOL ExternalFormatFs (int driveNo, int clusterSize, int fsType)
DWORD dwExitCode, dwWritten;
LPCSTR newLine = "\n";
WriteFile(hChildStd_IN_Wr, (LPCVOID) newLine, 1, &dwWritten, NULL);
if (WriteFile(hChildStd_IN_Wr, (LPCVOID) newLine, 1, &dwWritten, NULL))
{
/* wait for the format process to finish */
WaitForSingleObject (piProcInfo.hProcess, INFINITE);
}
else
{
/* we failed to write "\n". Maybe process exited too quickly. We wait 1 second */
WaitForSingleObject (piProcInfo.hProcess, 1000);
}
/* check if it was successfull */
if (GetExitCodeProcess (piProcInfo.hProcess, &dwExitCode))