From a2c3617dcc6022ec900fc411cc01c9be6c27a453 Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Fri, 26 Apr 2024 09:24:34 +0200 Subject: [PATCH] Patch against a probable msvc compiler bug in HelloImGuiIniAnyParentFolder using template lambda leads to memory corruption inside . However, going back to standard template function does work. This happens only with MSVC. Clang's ASAN does not raise any warning on other platforms --- .../hello_imgui_ini_any_parent_folder.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/hello_imgui/internal/hello_imgui_ini_any_parent_folder.cpp b/src/hello_imgui/internal/hello_imgui_ini_any_parent_folder.cpp index cf52804f..4ba6c7a4 100644 --- a/src/hello_imgui/internal/hello_imgui_ini_any_parent_folder.cpp +++ b/src/hello_imgui/internal/hello_imgui_ini_any_parent_folder.cpp @@ -14,8 +14,7 @@ namespace HelloImGui // // Utilities that read any settings in a hello_imgui.ini file located in the current folder or any of its parents // - - auto _folderAndAllParents = [](const std::string& folder) -> std::vector + std::vector _folderAndAllParents(const std::string& folder) { std::vector result; std::string currentFolder = folder; @@ -31,20 +30,19 @@ namespace HelloImGui return result; }; - auto _allHelloImGuiIniFilesToSearch = []() -> std::vector + std::vector _allHelloImGuiIniFilesToSearch() { std::vector allIniFileToSearch; std::string currentFolder = std::filesystem::current_path().string(); - for (const auto& folder: _folderAndAllParents(currentFolder)) + for (const auto& folder : _folderAndAllParents(currentFolder)) allIniFileToSearch.push_back(folder + "/hello_imgui.ini"); return allIniFileToSearch; }; template - auto _readIniValue = [] - (const std::string& iniFilePath, const std::string& sectionName, const std::string& valueName) -> std::optional + std::optional _readIniValue(const std::string& iniFilePath, const std::string& sectionName, const std::string& valueName) { if (! std::filesystem::exists(iniFilePath)) return std::nullopt; @@ -53,6 +51,7 @@ namespace HelloImGui try { + std::optional result = std::nullopt; ini::IniFile ini; ini.load(iniFilePath); @@ -70,9 +69,8 @@ namespace HelloImGui } }; - template - auto _readIniValueInParentFolders = [] - (const std::string& sectionName, const std::string& valueName) -> std::optional + template + std::optional _readIniValueInParentFolders(const std::string& sectionName, const std::string& valueName) { for (const auto& iniFile: _allHelloImGuiIniFilesToSearch()) {