From 63455ce2befdf792f8ab422ec38bc3c4226d07d2 Mon Sep 17 00:00:00 2001 From: Polshakov Dmitry Date: Sat, 12 Feb 2022 17:39:47 +0300 Subject: [PATCH] fix: don't change list while iteration (#434) Co-authored-by: Dmitry Polshakov --- lib/libimhex/source/helpers/file.cpp | 3 ++- plugins/builtin/source/content/welcome_screen.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/libimhex/source/helpers/file.cpp b/lib/libimhex/source/helpers/file.cpp index d6311c098..49e9854a4 100644 --- a/lib/libimhex/source/helpers/file.cpp +++ b/lib/libimhex/source/helpers/file.cpp @@ -56,7 +56,8 @@ namespace hex { std::vector File::readBytes(size_t numBytes) { if (!isValid()) return {}; - std::vector bytes(numBytes ?: getSize()); + auto size = numBytes ?: getSize(); + std::vector bytes(size); auto bytesRead = fread(bytes.data(), 1, bytes.size(), this->m_file); bytes.resize(bytesRead); diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index 97fdb409c..535a573c4 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -415,8 +415,11 @@ namespace hex::plugin::builtin { } if (ImGui::BeginMenu("hex.builtin.view.hex_editor.menu.file.open_recent"_lang, !s_recentFilePaths.empty())) { - for (auto &path : s_recentFilePaths) { - if (ImGui::MenuItem(fs::path(path).filename().string().c_str())) { + // Copy to avoid chaning list while iteration + std::list recentFilePaths = s_recentFilePaths; + for (auto &path : recentFilePaths) { + auto filename = fs::path(path).filename().string(); + if (ImGui::MenuItem(filename.c_str())) { EventManager::post(path); } }