From dc26fb8ef735749c952ec5e0d1aa2cbf3aed8ab8 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 4 Jan 2020 11:06:12 -0800 Subject: [PATCH] Windows: Make TEMP dir detection long path aware. --- UI/MainScreen.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 86afd47b5e..7fccb89a58 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -96,8 +96,14 @@ static bool IsTempPath(const std::string &str) { // Normalize slashes. item = ReplaceAll(str, "/", "\\"); - wchar_t tempPath[MAX_PATH]; - GetTempPath(MAX_PATH, tempPath); + std::wstring tempPath(MAX_PATH, '\0'); + size_t sz = GetTempPath((DWORD)tempPath.size(), &tempPath[0]); + if (sz >= tempPath.size()) { + tempPath.resize(sz); + sz = GetTempPath((DWORD)tempPath.size(), &tempPath[0]); + } + // Need to resize off the null terminator either way. + tempPath.resize(sz); if (testPath(ConvertWStringToUTF8(tempPath))) return true; #endif