From 2c3d8d4c0b92ac6878e2e8c35d10f6f39e1efd0a Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 30 Jul 2025 17:41:45 +0200 Subject: [PATCH] fix: CppCheck issues --- lib/libimhex/include/hex/api/imhex_api.hpp | 2 +- lib/libimhex/include/hex/helpers/opengl.hpp | 6 +++--- main/gui/source/messaging/win.cpp | 10 ++++++++-- .../include/content/providers/disk_provider.hpp | 10 ++++------ .../source/content/command_palette_commands.cpp | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index 6f129bf86..e3ce13ec4 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -772,7 +772,7 @@ EXPORT_MODULE namespace hex { void pop() const; [[nodiscard]] operator ImFont*() const; - [[nodiscard]] UnlocalizedString getUnlocalizedName() const { return m_fontName; } + [[nodiscard]] const UnlocalizedString& getUnlocalizedName() const { return m_fontName; } private: void push(float size, ImFont *font) const; diff --git a/lib/libimhex/include/hex/helpers/opengl.hpp b/lib/libimhex/include/hex/helpers/opengl.hpp index eb87e80ed..8e8a931dd 100644 --- a/lib/libimhex/include/hex/helpers/opengl.hpp +++ b/lib/libimhex/include/hex/helpers/opengl.hpp @@ -188,7 +188,7 @@ namespace hex::gl { T &getElement(int row,int col) { - return this->mat[row * Columns+col]; + return this->mat[row * Columns + col]; } Vector getColumn(int col) { @@ -205,12 +205,12 @@ namespace hex::gl { return result; } - void updateRow(int row, Vector values) { + void updateRow(int row, const Vector &values) { for (size_t i = 0; i < Columns; i++) this->mat[row * Columns + i] = values[i]; } - void updateColumn(int col, Vector values) { + void updateColumn(int col, const Vector &values) { for (size_t i = 0; i < Rows; i++) this->mat[i * Columns + col] = values[i]; } diff --git a/main/gui/source/messaging/win.cpp b/main/gui/source/messaging/win.cpp index 43f3900e5..40deb128c 100644 --- a/main/gui/source/messaging/win.cpp +++ b/main/gui/source/messaging/win.cpp @@ -69,11 +69,17 @@ namespace hex::messaging { } bool setupNative() { - constexpr static auto UniqueMutexId = L"ImHex/a477ea68-e334-4d07-a439-4f159c683763"; // Check if an ImHex instance is already running by opening a global mutex - HANDLE globalMutex = OpenMutexW(MUTEX_ALL_ACCESS, FALSE, UniqueMutexId); + static HANDLE globalMutex; + AT_FINAL_CLEANUP { + if (globalMutex != nullptr) { + CloseHandle(globalMutex); + } + }; + + globalMutex = OpenMutexW(MUTEX_ALL_ACCESS, FALSE, UniqueMutexId); if (globalMutex == nullptr) { // If no ImHex instance is running, create a new global mutex globalMutex = CreateMutexW(nullptr, FALSE, UniqueMutexId); diff --git a/plugins/builtin/include/content/providers/disk_provider.hpp b/plugins/builtin/include/content/providers/disk_provider.hpp index 4fd32fd53..efc07f019 100644 --- a/plugins/builtin/include/content/providers/disk_provider.hpp +++ b/plugins/builtin/include/content/providers/disk_provider.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace hex::plugin::builtin { @@ -63,12 +64,9 @@ namespace hex::plugin::builtin { std::string m_friendlyName; bool m_elevated = false; -#if defined(OS_WINDOWS) - void *m_diskHandle = reinterpret_cast(-1); -#else - std::string m_pathBuffer; - int m_diskHandle = -1; -#endif + wolv::io::NativeHandle m_diskHandle; + [[maybe_unused]] std::string m_pathBuffer; + size_t m_diskSize = 0; size_t m_sectorSize = 0; diff --git a/plugins/builtin/source/content/command_palette_commands.cpp b/plugins/builtin/source/content/command_palette_commands.cpp index 2653cf33f..674c0be57 100644 --- a/plugins/builtin/source/content/command_palette_commands.cpp +++ b/plugins/builtin/source/content/command_palette_commands.cpp @@ -58,7 +58,7 @@ namespace hex::plugin::builtin { } } - std::string formatAs(Value other) { + std::string formatAs(const Value &other) { return std::visit([&, this](T value) -> std::string { auto unit = other.getUnit();