From 90d8e03f2c2bcb54d36b8924204809a2c0650533 Mon Sep 17 00:00:00 2001 From: paxcut <53811119+paxcut@users.noreply.github.com> Date: Mon, 5 Jan 2026 16:57:04 -0700 Subject: [PATCH] Fixes by @AkiSakurai for bug thats caused crashing ImHex when creating recursive inheritances. (#2612) The previous code I approved was wrong and caused ImHex to grow until computer froze. This PR is a copy of the original fix in PR #2546 by @AkiSakurai --- .../text_highlighting/pattern_language.hpp | 2 +- .../text_highlighting/pattern_language.cpp | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/plugins/builtin/include/content/text_highlighting/pattern_language.hpp b/plugins/builtin/include/content/text_highlighting/pattern_language.hpp index 1fb947951..b764170f3 100644 --- a/plugins/builtin/include/content/text_highlighting/pattern_language.hpp +++ b/plugins/builtin/include/content/text_highlighting/pattern_language.hpp @@ -218,7 +218,7 @@ namespace hex::plugin::builtin { std::string getVariableTypeName(); /// Append the variable definitions of the parent to the child void appendInheritances(); - void recurseInheritances(std::string name, size_t depth = 0); + void recurseInheritances(std::string name); ///Loads a map of identifiers to their token id instances void loadInstances(); /// Replace auto with the actual type for template arguments and function parameters diff --git a/plugins/builtin/source/content/text_highlighting/pattern_language.cpp b/plugins/builtin/source/content/text_highlighting/pattern_language.cpp index 6ef7fa936..fa2f9ac93 100644 --- a/plugins/builtin/source/content/text_highlighting/pattern_language.cpp +++ b/plugins/builtin/source/content/text_highlighting/pattern_language.cpp @@ -1858,13 +1858,12 @@ namespace hex::plugin::builtin { } } - void TextHighlighter::recurseInheritances(std::string name, size_t depth) { - if (depth > m_inheritances.size()) - return; - if (m_inheritances.contains(name)) { - for (const auto &inheritance: m_inheritances[name]) { - recurseInheritances(inheritance, depth + 1); - + void TextHighlighter::recurseInheritances(std::string name) { + if (auto iterator = m_inheritances.find(name); iterator != m_inheritances.end()) { + auto inheritances = std::move(iterator->second); + m_inheritances.erase(iterator); + for (auto inheritance: inheritances) { + recurseInheritances(inheritance); auto definitions = m_UDTVariables[inheritance]; if (definitions.empty()) definitions = m_ImportedUDTVariables[inheritance]; @@ -1887,8 +1886,8 @@ namespace hex::plugin::builtin { } void TextHighlighter::appendInheritances() { - for (const auto &[name, inheritances]: m_inheritances) - recurseInheritances(name); + for (auto iterator = m_inheritances.begin(); iterator != m_inheritances.end(); iterator = m_inheritances.begin()) + recurseInheritances(iterator->first); } // Get the string of the argument type. This works on function arguments and non-type template arguments.