1
0
mirror of synced 2025-01-19 01:24:15 +01:00

fix: don't change list while iteration (#434)

Co-authored-by: Dmitry Polshakov <dmitry.polshakov@dsr-corporation.com>
This commit is contained in:
Polshakov Dmitry 2022-02-12 17:39:47 +03:00 committed by GitHub
parent 585058b500
commit 63455ce2be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -56,7 +56,8 @@ namespace hex {
std::vector<u8> File::readBytes(size_t numBytes) { std::vector<u8> File::readBytes(size_t numBytes) {
if (!isValid()) return {}; if (!isValid()) return {};
std::vector<u8> bytes(numBytes ?: getSize()); auto size = numBytes ?: getSize();
std::vector<u8> bytes(size);
auto bytesRead = fread(bytes.data(), 1, bytes.size(), this->m_file); auto bytesRead = fread(bytes.data(), 1, bytes.size(), this->m_file);
bytes.resize(bytesRead); bytes.resize(bytesRead);

View File

@ -415,8 +415,11 @@ namespace hex::plugin::builtin {
} }
if (ImGui::BeginMenu("hex.builtin.view.hex_editor.menu.file.open_recent"_lang, !s_recentFilePaths.empty())) { if (ImGui::BeginMenu("hex.builtin.view.hex_editor.menu.file.open_recent"_lang, !s_recentFilePaths.empty())) {
for (auto &path : s_recentFilePaths) { // Copy to avoid chaning list while iteration
if (ImGui::MenuItem(fs::path(path).filename().string().c_str())) { std::list<fs::path> recentFilePaths = s_recentFilePaths;
for (auto &path : recentFilePaths) {
auto filename = fs::path(path).filename().string();
if (ImGui::MenuItem(filename.c_str())) {
EventManager::post<RequestOpenFile>(path); EventManager::post<RequestOpenFile>(path);
} }
} }