From 3b2e95b9d082da351a4e2072577e37dfa3a5f48e Mon Sep 17 00:00:00 2001 From: paxcut Date: Tue, 24 Mar 2026 06:43:41 -0700 Subject: [PATCH] fixed UB created by erasing map elements in range for loop. --- plugins/ui/source/ui/text_editor/render.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/ui/source/ui/text_editor/render.cpp b/plugins/ui/source/ui/text_editor/render.cpp index 06ddeba32..cfdddc730 100644 --- a/plugins/ui/source/ui/text_editor/render.cpp +++ b/plugins/ui/source/ui/text_editor/render.cpp @@ -540,17 +540,16 @@ namespace hex::ui { m_codeFolds.clear(); m_rowToFoldSymbol.clear(); - for (auto [key, isOpen]: m_codeFoldState){ - auto index = m_codeFoldKeys.find(key); - if (index->m_start != key.m_start || index->m_end != key.m_end) - m_codeFoldState.erase(key); - } + std::erase_if(m_codeFoldState, [this](const auto& entry) { + auto index = m_codeFoldKeys.find(entry.first); + return (index->m_start != entry.first.m_start || index->m_end != entry.first.m_end); + }); + + std::erase_if(m_codeFoldKeys, [](const auto& entry) { + return (entry.m_start >= entry.m_end); + }); for (auto key : m_codeFoldKeys) { - if (key.m_start >= key.m_end) { - m_codeFoldKeys.erase(key); - continue; - } auto rowStart = lineIndexToRow(key.m_start.m_line); auto rowEnd = lineIndexToRow(key.m_end.m_line);