From a0809fe85c2f1bf130c26ff77aea7dac19b6c05f Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sat, 26 Mar 2022 20:01:05 +0100 Subject: Windows: check result of WriteFile and don't block if it is failing (Coverity) --- src/Common/Format.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/Common') diff --git a/src/Common/Format.c b/src/Common/Format.c index f691c78d..4363f474 100644 --- a/src/Common/Format.c +++ b/src/Common/Format.c @@ -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); - - /* wait for the format process to finish */ - WaitForSingleObject (piProcInfo.hProcess, INFINITE); + 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)) -- cgit v1.2.3