From 87ed0d31d4dceb5eda0d0a830382bf9f473944c5 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 1 Jan 2023 01:01:24 +0100 Subject: [PATCH] fix: Various invalid iterator and container accesses --- lib/libimhex/CMakeLists.txt | 2 +- lib/libimhex/include/hex/api/event.hpp | 2 ++ lib/libimhex/source/helpers/fs.cpp | 2 +- plugins/builtin/CMakeLists.txt | 2 +- plugins/builtin/source/content/views/view_data_inspector.cpp | 2 +- plugins/builtin/source/content/views/view_information.cpp | 2 +- plugins/builtin/source/content/views/view_tools.cpp | 5 +++-- plugins/windows/CMakeLists.txt | 2 +- 8 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index 3929d5f9c..5b114a308 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.16) project(libimhex) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 23) set(BUILD_SHARED_LIBS OFF) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../external/imgui ${CMAKE_CURRENT_BINARY_DIR}/external/imgui) diff --git a/lib/libimhex/include/hex/api/event.hpp b/lib/libimhex/include/hex/api/event.hpp index 3ce63dcba..19219224b 100644 --- a/lib/libimhex/include/hex/api/event.hpp +++ b/lib/libimhex/include/hex/api/event.hpp @@ -80,7 +80,9 @@ namespace hex { if (iter != s_tokenStore.end()) { s_events.remove(*iter->second); + s_tokenStore.erase(iter); } + } template diff --git a/lib/libimhex/source/helpers/fs.cpp b/lib/libimhex/source/helpers/fs.cpp index b05042bd9..d45a5a319 100644 --- a/lib/libimhex/source/helpers/fs.cpp +++ b/lib/libimhex/source/helpers/fs.cpp @@ -189,7 +189,7 @@ namespace hex::fs { #endif } - constexpr std::vector appendPath(std::vector paths, const std::fs::path &folder) { + std::vector appendPath(std::vector paths, const std::fs::path &folder) { for (auto &path : paths) path = path / folder; diff --git a/plugins/builtin/CMakeLists.txt b/plugins/builtin/CMakeLists.txt index f8486ebf6..a9707f067 100644 --- a/plugins/builtin/CMakeLists.txt +++ b/plugins/builtin/CMakeLists.txt @@ -69,7 +69,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE libimhex) # ---- No need to change anything from here downwards unless you know what you're doing ---- # -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 23) set(CMAKE_SHARED_LIBRARY_PREFIX "") set(CMAKE_SHARED_LIBRARY_SUFFIX ".hexplug") diff --git a/plugins/builtin/source/content/views/view_data_inspector.cpp b/plugins/builtin/source/content/views/view_data_inspector.cpp index 626327419..a05e6c8a4 100644 --- a/plugins/builtin/source/content/views/view_data_inspector.cpp +++ b/plugins/builtin/source/content/views/view_data_inspector.cpp @@ -42,7 +42,7 @@ namespace hex::plugin::builtin { } void ViewDataInspector::drawContent() { - if (this->m_dataValid) { + if (this->m_dataValid && !this->m_updateTask.isRunning()) { this->m_dataValid = false; this->m_cachedData = std::move(this->m_workData); } diff --git a/plugins/builtin/source/content/views/view_information.cpp b/plugins/builtin/source/content/views/view_information.cpp index b3be1d128..d6e363eed 100644 --- a/plugins/builtin/source/content/views/view_information.cpp +++ b/plugins/builtin/source/content/views/view_information.cpp @@ -140,7 +140,7 @@ namespace hex::plugin::builtin { std::array blockValueCounts = { 0 }; - const auto blockCount = provider->getSize() / this->m_blockSize; + const auto blockCount = (provider->getSize() / this->m_blockSize) + 1; this->m_blockTypeDistributions.fill({}); this->m_blockEntropy.clear(); diff --git a/plugins/builtin/source/content/views/view_tools.cpp b/plugins/builtin/source/content/views/view_tools.cpp index f58694a2a..acfb0a77d 100644 --- a/plugins/builtin/source/content/views/view_tools.cpp +++ b/plugins/builtin/source/content/views/view_tools.cpp @@ -22,12 +22,13 @@ namespace hex::plugin::builtin { if (ImGui::IsMouseClicked(0) && ImGui::IsItemActivated() && this->m_dragStartIterator == tools.end()) this->m_dragStartIterator = iter; + if (!ImGui::IsMouseDown(0)) + this->m_dragStartIterator = tools.end(); + if (!ImGui::IsItemHovered() && this->m_dragStartIterator == iter) { detached = true; } - if (!ImGui::IsMouseDown(0)) - this->m_dragStartIterator = tools.end(); } } } diff --git a/plugins/windows/CMakeLists.txt b/plugins/windows/CMakeLists.txt index 0ae1822d4..59ce978c1 100644 --- a/plugins/windows/CMakeLists.txt +++ b/plugins/windows/CMakeLists.txt @@ -23,7 +23,7 @@ if (WIN32) # ---- No need to change anything from here downwards unless you know what you're doing ---- # - set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD 23) set(CMAKE_SHARED_LIBRARY_PREFIX "") set(CMAKE_SHARED_LIBRARY_SUFFIX ".hexplug")