Skip to content

Commit 8077965

Browse files
committed
Fix crash in Pattern Language syntax highlighting for self-inheriting structs
``` rust struct Rec : Rec { }; ``` Prevent infinite recursion in appendInheritances by erasing processed inheritance entries during traversal, and safely iterate over m_inheritances in appendInheritances to avoid modification-during-iteration issues.
1 parent c8652b0 commit 8077965

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

plugins/builtin/source/content/text_highlighting/pattern_language.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,8 +1603,10 @@ namespace hex::plugin::builtin {
16031603
}
16041604

16051605
void TextHighlighter::recurseInheritances(std::string name) {
1606-
if (m_inheritances.contains(name)) {
1607-
for (auto inheritance: m_inheritances[name]) {
1606+
if (auto iterator = m_inheritances.find(name); iterator != m_inheritances.end()) {
1607+
auto inheritances = std::move(iterator->second);
1608+
m_inheritances.erase(iterator);
1609+
for (auto inheritance: inheritances) {
16081610
recurseInheritances(inheritance);
16091611
auto definitions = m_UDTVariables[inheritance];
16101612
if (definitions.empty())
@@ -1628,8 +1630,8 @@ namespace hex::plugin::builtin {
16281630
}
16291631

16301632
void TextHighlighter::appendInheritances() {
1631-
for (auto [name, inheritances]: m_inheritances)
1632-
recurseInheritances(name);
1633+
for (auto iterator = m_inheritances.begin(); iterator != m_inheritances.end(); iterator = m_inheritances.begin())
1634+
recurseInheritances(iterator->first);
16331635
}
16341636

16351637
// Get the string of the argument type. This works on function arguments and non-type template arguments.

0 commit comments

Comments
 (0)