From e2041de9690f4257c2b2b01a4cf9704a6da23068 Mon Sep 17 00:00:00 2001 From: CedricMocquillon Date: Sat, 12 Dec 2020 21:47:50 +0100 Subject: [PATCH] Use the incremental approach to handle long path --- components/crashcatcher/windows_crashcatcher.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/components/crashcatcher/windows_crashcatcher.cpp b/components/crashcatcher/windows_crashcatcher.cpp index 3291631c10..129907fc3b 100644 --- a/components/crashcatcher/windows_crashcatcher.cpp +++ b/components/crashcatcher/windows_crashcatcher.cpp @@ -126,8 +126,13 @@ namespace Crash void CrashCatcher::startMonitorProcess(const std::string& crashLogPath) { - WCHAR executablePath[MAX_PATH + 1]; - GetModuleFileNameW(NULL, executablePath, MAX_PATH + 1); + std::wstring executablePath; + DWORD copied = 0; + do { + executablePath.resize(executablePath.size() + MAX_PATH); + copied = GetModuleFileNameW(nullptr, &executablePath[0], executablePath.size()); + } while (copied >= executablePath.size()); + executablePath.resize(copied); memset(mShm->mStartup.mLogFilePath, 0, sizeof(mShm->mStartup.mLogFilePath)); int length = crashLogPath.length(); @@ -152,7 +157,7 @@ namespace Crash PROCESS_INFORMATION pi; ZeroMemory(&pi, sizeof(pi)); - if (!CreateProcessW(executablePath, &argumetns[0], NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) + if (!CreateProcessW(&executablePath[0], &argumetns[0], NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) throw std::runtime_error("Could not start crash monitor process"); waitMonitor();