From a80680f5a1c86dee7a096244fa3dffdc273a43f2 Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 27 Jun 2022 19:06:26 +0100 Subject: [PATCH] Fix water::DirectoryIterator for windows builds Signed-off-by: falkTX --- source/modules/water/files/File.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/source/modules/water/files/File.cpp b/source/modules/water/files/File.cpp index 5784aa484..5a373a415 100644 --- a/source/modules/water/files/File.cpp +++ b/source/modules/water/files/File.cpp @@ -1129,8 +1129,8 @@ File File::getSpecialLocation (const SpecialLocationType type) case tempDirectory: { - WCHAR wdest [2048]; - CHAR adest [2048]; + WCHAR wdest [MAX_PATH + 256]; + CHAR adest [MAX_PATH + 256]; wdest[0] = 0; GetTempPathW ((DWORD) numElementsInArray (wdest), wdest); @@ -1190,18 +1190,10 @@ public: return false; } - const size_t wlen = wcslen(findData.cFileName); - CARLA_SAFE_ASSERT_RETURN (wlen > 0, false); + CHAR apath [MAX_PATH + 256]; - const int len = WideCharToMultiByte (CP_UTF8, 0, findData.cFileName, (int) wlen, nullptr, 0, nullptr, nullptr); - CARLA_SAFE_ASSERT_RETURN (len > 0, false); - - if (CHAR* const path = new CHAR [len]) - { - WideCharToMultiByte (CP_UTF8, 0, findData.cFileName, (int) wlen, path, len, nullptr, nullptr); - filenameFound = path; - delete[] path; - } + if (WideCharToMultiByte (CP_UTF8, 0, findData.cFileName, -1, apath, numElementsInArray (apath), nullptr, nullptr)) + filenameFound = apath; if (isDir != nullptr) *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0); if (isReadOnly != nullptr) *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);