MI Refactor CMIUtilSystemWindows::GetExecutablesPath()

Summary:
My understanding of the Windows API call GetLastError() is that it should only be checked when ::GetModuleFileName()  returns 0 on error.
Otherwise GetExecutablesPath() could return an error despite nLen being valid if GetLastError() was inconsistent.
Patch updates function to only call GetOSLastError() when nLen == 0

Patch from ewan@codeplay.com

Reviewers: EwanCrawford

Subscribers: lldb-commits, deepak2427

Differential Revision: http://reviews.llvm.org/D9154

llvm-svn: 235515
This commit is contained in:
Ilia K 2015-04-22 15:43:43 +00:00
parent badf3a6356
commit 5a931869d4
1 changed files with 4 additions and 6 deletions

View File

@ -110,15 +110,13 @@ CMIUtilSystemWindows::GetExecutablesPath(CMIUtilString &vrwFileNamePath) const
bool bOk = MIstatus::success; bool bOk = MIstatus::success;
HMODULE hModule = ::GetModuleHandle(nullptr); HMODULE hModule = ::GetModuleHandle(nullptr);
char pPath[MAX_PATH]; char pPath[MAX_PATH];
const DWORD nLen = ::GetModuleFileName(hModule, &pPath[0], MAX_PATH); if (!::GetModuleFileName(hModule, &pPath[0], MAX_PATH))
const CMIUtilString strLastErr(GetOSLastError());
if ((nLen != 0) && (strLastErr == "Unknown OS error"))
vrwFileNamePath = &pPath[0];
else
{ {
bOk = MIstatus::failure; bOk = MIstatus::failure;
vrwFileNamePath = strLastErr; vrwFileNamePath = GetOSLastError();
} }
else
vrwFileNamePath = &pPath[0];
return bOk; return bOk;
} }