Skip to content

Commit

Permalink
Patch against a probable msvc compiler bug in HelloImGuiIniAnyParentF…
Browse files Browse the repository at this point in the history
…older

using template lambda leads to memory corruption inside <xtree>.
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
  • Loading branch information
pthom committed Apr 26, 2024
1 parent 4ace340 commit a2c3617
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/hello_imgui/internal/hello_imgui_ini_any_parent_folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::string>
std::vector<std::string> _folderAndAllParents(const std::string& folder)
{
std::vector<std::string> result;
std::string currentFolder = folder;
Expand All @@ -31,20 +30,19 @@ namespace HelloImGui
return result;
};

auto _allHelloImGuiIniFilesToSearch = []() -> std::vector<std::string>
std::vector<std::string> _allHelloImGuiIniFilesToSearch()
{
std::vector<std::string> 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<typename T>
auto _readIniValue = []
(const std::string& iniFilePath, const std::string& sectionName, const std::string& valueName) -> std::optional<T>
std::optional<T> _readIniValue(const std::string& iniFilePath, const std::string& sectionName, const std::string& valueName)
{
if (! std::filesystem::exists(iniFilePath))
return std::nullopt;
Expand All @@ -53,6 +51,7 @@ namespace HelloImGui

try
{

std::optional<T> result = std::nullopt;
ini::IniFile ini;
ini.load(iniFilePath);
Expand All @@ -70,9 +69,8 @@ namespace HelloImGui
}
};

template<typename T>
auto _readIniValueInParentFolders = []
(const std::string& sectionName, const std::string& valueName) -> std::optional<T>
template <typename T>
std::optional<T> _readIniValueInParentFolders(const std::string& sectionName, const std::string& valueName)
{
for (const auto& iniFile: _allHelloImGuiIniFilesToSearch())
{
Expand Down

0 comments on commit a2c3617

Please sign in to comment.