diff --git a/lib/external/libwolv b/lib/external/libwolv index a50a748ce..a8f68e722 160000 --- a/lib/external/libwolv +++ b/lib/external/libwolv @@ -1 +1 @@ -Subproject commit a50a748ce71ea59a7b346f839e538c0bca9b7e8c +Subproject commit a8f68e7222e94a5c202842d4bcfed4a600855eda diff --git a/lib/external/pattern_language b/lib/external/pattern_language index 9647e3839..9954c25d9 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit 9647e38395804fd62cb663617bdbed0648f11c57 +Subproject commit 9954c25d9c180823ce89051b1d97c892176c46fa diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index 97b126c43..4584ddb9e 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -40,7 +40,6 @@ set(LIBIMHEX_SOURCES source/helpers/imgui_hooks.cpp source/helpers/semantic_version.cpp source/helpers/keys.cpp - source/helpers/freetype.cpp source/helpers/udp_server.cpp source/test/tests.cpp diff --git a/lib/libimhex/include/hex/api/achievement_manager.hpp b/lib/libimhex/include/hex/api/achievement_manager.hpp index d99779670..b76a75df1 100644 --- a/lib/libimhex/include/hex/api/achievement_manager.hpp +++ b/lib/libimhex/include/hex/api/achievement_manager.hpp @@ -311,11 +311,15 @@ EXPORT_MODULE namespace hex { } [[nodiscard]] bool isUnlockable() const { - return std::all_of(this->parents.begin(), this->parents.end(), [](auto &parent) { return parent->achievement->isUnlocked(); }); + return std::ranges::all_of(this->parents, [](const auto &parent) { + return parent->achievement->isUnlocked(); + }); } [[nodiscard]] bool isVisible() const { - return std::all_of(this->visibilityParents.begin(), this->visibilityParents.end(), [](auto &parent) { return parent->achievement->isUnlocked(); }); + return std::ranges::all_of(this->visibilityParents, [](const auto &parent) { + return parent->achievement->isUnlocked(); + }); } [[nodiscard]] bool isUnlocked() const { diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index 023e638ed..6c7b1ed86 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -731,7 +731,7 @@ EXPORT_MODULE namespace hex { add(impl::Entry { unlocalizedCategory, unlocalizedName, - [=, ...args = std::forward(args)]() mutable { + [unlocalizedName, ...args = std::forward(args)]() mutable { auto node = std::make_unique(std::forward(args)...); node->setUnlocalizedName(unlocalizedName); return node; @@ -1072,7 +1072,7 @@ EXPORT_MODULE namespace hex { * @param unlocalizedName The unlocalized name of the formatter * @param callback The function to call to format the data */ - void addFindExportFormatter(const UnlocalizedString &unlocalizedName, const std::string fileExtension, const impl::FindExporterCallback &callback); + void addFindExportFormatter(const UnlocalizedString &unlocalizedName, const std::string &fileExtension, const impl::FindExporterCallback &callback); } diff --git a/lib/libimhex/include/hex/helpers/auto_reset.hpp b/lib/libimhex/include/hex/helpers/auto_reset.hpp index 96117823f..7a8628fb4 100644 --- a/lib/libimhex/include/hex/helpers/auto_reset.hpp +++ b/lib/libimhex/include/hex/helpers/auto_reset.hpp @@ -33,7 +33,7 @@ namespace hex { m_valid = true; } - ~AutoReset() { + ~AutoReset() override { ImHexApi::System::impl::removeAutoResetObject(this); } @@ -85,8 +85,8 @@ namespace hex { m_value.reset(); } else if constexpr (requires { m_value.clear(); }) { m_value.clear(); - } else if constexpr (requires(T t) { t = nullptr; }) { - m_value = nullptr; + } else if constexpr (std::is_pointer_v) { + m_value = nullptr; // cppcheck-suppress nullPointer } else { m_value = { }; } diff --git a/lib/libimhex/include/hex/helpers/freetype.hpp b/lib/libimhex/include/hex/helpers/freetype.hpp deleted file mode 100644 index 71eea3b18..000000000 --- a/lib/libimhex/include/hex/helpers/freetype.hpp +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once -#include "imgui.h" -#include - -namespace hex::ft { - - class Bitmap { - ImU32 m_width; - ImU32 m_height; - ImU32 m_pitch; - std::vector m_data; - public: - Bitmap(ImU32 width, ImU32 height, ImU32 pitch, ImU8 *data) : m_width(width), m_height(height), m_pitch(pitch), m_data(std::vector(data, data + pitch * height)) {} - - Bitmap(ImU32 width, ImU32 height, ImU32 pitch) : m_width(width), m_height(height), m_pitch(pitch) { m_data.resize(pitch * height); } - - void clear() { m_data.clear(); } - - ImU32 getWidth() const { return m_width; } - - ImU32 getHeight() const { return m_height; } - - ImU32 getPitch() const { return m_pitch; } - - const std::vector &getData() const { return m_data; } - - ImU8 *getData() { return m_data.data(); } - - void lcdFilter(); - }; - - class RGBA { - public: - - static ImU32 addAlpha(ImU8 r, ImU8 g, ImU8 b) { - color.rgbaVec[0] = r; - color.rgbaVec[1] = g; - color.rgbaVec[2] = b; - color.rgbaVec[3] = (r + g + b) / 3;//luminance - return color.rgba; - } - - RGBA(ImU8 r, ImU8 g, ImU8 b, ImU8 a) { - color.rgbaVec[0] = r; - color.rgbaVec[1] = b; - color.rgbaVec[2] = g; - color.rgbaVec[3] = a; - } - - explicit RGBA(ImU32 rgba) { - color.rgba = rgba; - } - - union RGBAU { - ImU8 rgbaVec[4]; - ImU32 rgba; - }; - inline static RGBAU color; - }; -} \ No newline at end of file diff --git a/lib/libimhex/include/hex/helpers/opengl.hpp b/lib/libimhex/include/hex/helpers/opengl.hpp index 27b2e802c..eb87e80ed 100644 --- a/lib/libimhex/include/hex/helpers/opengl.hpp +++ b/lib/libimhex/include/hex/helpers/opengl.hpp @@ -79,7 +79,7 @@ namespace hex::gl { return *this; } - auto operator-=(Vector other) { + auto operator-=(const Vector &other) { for (size_t i = 0; i < Size; i++) m_data[i] -= other.m_data[i]; @@ -156,7 +156,7 @@ namespace hex::gl { } private: - std::array m_data; + std::array m_data = { }; }; template diff --git a/lib/libimhex/include/hex/helpers/types.hpp b/lib/libimhex/include/hex/helpers/types.hpp index a17573303..69c9d0a11 100644 --- a/lib/libimhex/include/hex/helpers/types.hpp +++ b/lib/libimhex/include/hex/helpers/types.hpp @@ -74,7 +74,7 @@ namespace hex { [[nodiscard]] T get() const { return pointer; } [[nodiscard]] T operator->() const { return pointer; } - [[nodiscard]] T operator*() const { return *pointer; } + [[nodiscard]] std::remove_pointer_t operator*() const { return *pointer; } [[nodiscard]] operator T() const { return pointer; } T pointer; diff --git a/lib/libimhex/include/hex/helpers/udp_server.hpp b/lib/libimhex/include/hex/helpers/udp_server.hpp index 088d64e23..ef49b76d2 100644 --- a/lib/libimhex/include/hex/helpers/udp_server.hpp +++ b/lib/libimhex/include/hex/helpers/udp_server.hpp @@ -49,11 +49,11 @@ namespace hex { private: void run(); - u16 m_port; + u16 m_port = 0; Callback m_callback; std::thread m_thread; std::atomic m_running; - int m_socketFd; + int m_socketFd = -1; }; } \ No newline at end of file diff --git a/lib/libimhex/include/hex/providers/undo_redo/operations/operation.hpp b/lib/libimhex/include/hex/providers/undo_redo/operations/operation.hpp index 270501b78..6889b16e5 100644 --- a/lib/libimhex/include/hex/providers/undo_redo/operations/operation.hpp +++ b/lib/libimhex/include/hex/providers/undo_redo/operations/operation.hpp @@ -13,7 +13,7 @@ namespace hex::prv::undo { class Operation : public ICloneable { public: - virtual ~Operation() = default; + ~Operation() override = default; virtual void undo(Provider *provider) = 0; virtual void redo(Provider *provider) = 0; diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 43625c2be..16fa0a90c 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -1105,7 +1105,7 @@ namespace hex { impl::s_exportMenuEntries->push_back({ unlocalizedName, callback }); } - void addFindExportFormatter(const UnlocalizedString &unlocalizedName, const std::string fileExtension, const impl::FindExporterCallback &callback) { + void addFindExportFormatter(const UnlocalizedString &unlocalizedName, const std::string &fileExtension, const impl::FindExporterCallback &callback) { log::debug("Registered new export formatter: {}", unlocalizedName.get()); impl::s_findExportEntries->push_back({ unlocalizedName, fileExtension, callback }); diff --git a/lib/libimhex/source/api/plugin_manager.cpp b/lib/libimhex/source/api/plugin_manager.cpp index 714e08596..b7116a832 100644 --- a/lib/libimhex/source/api/plugin_manager.cpp +++ b/lib/libimhex/source/api/plugin_manager.cpp @@ -83,12 +83,8 @@ namespace hex { m_functions.getFeaturesFunction = getPluginFunction("getFeatures"); } - Plugin::Plugin(const std::string &name, const hex::PluginFunctions &functions) { - m_handle = 0; - m_functions = functions; - m_path = name; - m_addedManually = true; - } + Plugin::Plugin(const std::string &name, const hex::PluginFunctions &functions) : + m_handle(0), m_path(name), m_addedManually(true), m_functions(functions) { } Plugin::Plugin(Plugin &&other) noexcept { diff --git a/lib/libimhex/source/api/task_manager.cpp b/lib/libimhex/source/api/task_manager.cpp index 34efcc672..15184a096 100644 --- a/lib/libimhex/source/api/task_manager.cpp +++ b/lib/libimhex/source/api/task_manager.cpp @@ -404,7 +404,7 @@ namespace hex { if (s_tasks.empty()) { std::scoped_lock lock(s_deferredCallsMutex); - for (auto &call : s_tasksFinishedCallbacks) + for (const auto &call : s_tasksFinishedCallbacks) call(); s_tasksFinishedCallbacks.clear(); } diff --git a/lib/libimhex/source/helpers/freetype.cpp b/lib/libimhex/source/helpers/freetype.cpp deleted file mode 100644 index b65a855de..000000000 --- a/lib/libimhex/source/helpers/freetype.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "hex/helpers/freetype.hpp" -#include "imgui.h" - -namespace hex::ft { - - void Bitmap::lcdFilter() { - if (m_width * m_height == 0) - return; - std::vector h = {8, 0x4D, 0x55, 0x4D, 8}; - auto paddedWidth = m_width + 4; - auto fWidth = paddedWidth + ((3 - (paddedWidth % 3)) % 3); - auto fPitch = (fWidth + 3) & (-4); - Bitmap f(fWidth, m_height, fPitch); - //std::vector> fir(3, std::vector(3, 0)); - // first output: h[0]*input[0]/255.0f; - // 2nd output: (h[1]*input[0] + h[0]*input[1])/255.0f; - // 3rd output: (h[2]*input[0] + h[1]*input[1] + h[0]*input[2])/255.0f; - // 4th output: (h[1]*input[0] + h[2]*input[1] + h[1]*input[2] + h[0]*input[3])/255.0f; - // ith output: (h[0]*input[5+i] + h[1]*input[i+6] + h[2]*input[i+7] + h[1]*input[i+8] + h[0]*input[i+9])/255.0f; - // aap output: (h[0]*input[N-4] + h[1]*input[N-3] + h[2]*input[N-2] + h[1]*input[N-1])/255.0f; - // ap output: (h[0]*input[N-3] + h[1]*input[N-2] + h[2]*input[N-1])/255.0f; - // p output: (h[0]*input[N-2] + h[1]*input[N-1] )/255.0f; - // last output: h[0]*input[N-1]/255.0f; - for (ImU32 y = 0; y < m_height; y++) { - auto fp = y * fPitch; - auto yp = y * m_pitch; - bool done = false; - for (ImU32 x = 0; x < 4; x++) { - ImU32 head = 0; - ImU32 tail = 0; - if (m_width >= x + 1) { - for (ImU32 i = 0; i < x + 1; i++) { - head += h[x - i] * m_data[yp + i]; - tail += h[i] * m_data[yp + m_width - 1 - x + i]; - } - f.m_data[fp + x] = head >> 8; - f.m_data[fp + paddedWidth - 1 - x] = tail >> 8; - } else { - done = true; - break; - } - } - if (done) - continue; - for (ImU32 x = 4; x < paddedWidth - 4; x++) { - ImU32 head = 0; - for (ImS32 i = 0; i < 5; i++) { - head += h[i] * m_data[yp + i + x - 4]; - } - f.m_data[fp + x] = head >> 8; - } - } - clear(); - m_width = f.m_width; - m_height = f.m_height; - m_pitch = f.m_pitch; - m_data = std::move(f.m_data); - } - -} \ No newline at end of file diff --git a/lib/libimhex/source/helpers/http_requests_native.cpp b/lib/libimhex/source/helpers/http_requests_native.cpp index ad0bd7c26..bf60b05fd 100644 --- a/lib/libimhex/source/helpers/http_requests_native.cpp +++ b/lib/libimhex/source/helpers/http_requests_native.cpp @@ -59,6 +59,7 @@ namespace hex { m_url = std::move(other.m_url); m_headers = std::move(other.m_headers); m_body = std::move(other.m_body); + m_timeout = other.m_timeout; return *this; } @@ -121,7 +122,7 @@ namespace hex { curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data); } - void setupFileUpload(CURL *curl, wolv::io::File &file, const std::string &fileName, const std::string &mimeName) { + void setupFileUpload(CURL *curl, const wolv::io::File &file, const std::string &fileName, const std::string &mimeName) { curl_mime *mime = curl_mime_init(curl); curl_mimepart *part = curl_mime_addpart(mime); diff --git a/lib/libimhex/source/helpers/opengl.cpp b/lib/libimhex/source/helpers/opengl.cpp index 01ce11e04..5dea0d7dd 100644 --- a/lib/libimhex/source/helpers/opengl.cpp +++ b/lib/libimhex/source/helpers/opengl.cpp @@ -277,6 +277,10 @@ namespace hex::gl { Texture& Texture::operator=(Texture &&other) noexcept { m_texture = other.m_texture; other.m_texture = 0; + + m_width = other.m_width; + m_height = other.m_height; + return *this; } diff --git a/lib/libimhex/source/helpers/patches.cpp b/lib/libimhex/source/helpers/patches.cpp index 31d171317..1285e0b15 100644 --- a/lib/libimhex/source/helpers/patches.cpp +++ b/lib/libimhex/source/helpers/patches.cpp @@ -45,10 +45,6 @@ namespace hex { return m_patches.rbegin()->first; } - void resizeRaw(u64 newSize) override { - std::ignore = newSize; - } - void insertRaw(u64 offset, u64 size) override { std::vector> patchesToMove; diff --git a/lib/libimhex/source/test/tests.cpp b/lib/libimhex/source/test/tests.cpp index 811a51664..c33b9165c 100644 --- a/lib/libimhex/source/test/tests.cpp +++ b/lib/libimhex/source/test/tests.cpp @@ -20,7 +20,7 @@ namespace hex::test { if(!initPluginImpl("Built-in")) return false; } - hex::Plugin *plugin = hex::PluginManager::getPlugin(name); + const auto *plugin = hex::PluginManager::getPlugin(name); if (plugin == nullptr) { hex::log::fatal("Plugin '{}' was not found !", name); return false; diff --git a/main/gui/source/messaging/macos.cpp b/main/gui/source/messaging/macos.cpp index 67edfef1c..f8964c8b1 100644 --- a/main/gui/source/messaging/macos.cpp +++ b/main/gui/source/messaging/macos.cpp @@ -18,7 +18,7 @@ namespace hex::messaging { fullEventData.insert(fullEventData.end(), args.begin(), args.end()); - u8 *data = &fullEventData[0]; + const u8 *data = &fullEventData[0]; auto dataSize = fullEventData.size(); macosSendMessageToMainInstance(data, dataSize); diff --git a/plugins/builtin/include/content/helpers/diagrams.hpp b/plugins/builtin/include/content/helpers/diagrams.hpp index d844d0d99..bf64e0eac 100644 --- a/plugins/builtin/include/content/helpers/diagrams.hpp +++ b/plugins/builtin/include/content/helpers/diagrams.hpp @@ -379,7 +379,7 @@ namespace hex { ImPlot::SetupAxes("hex.ui.common.address"_lang, "hex.builtin.information_section.info_analysis.entropy"_lang, ImPlotAxisFlags_Lock | ImPlotAxisFlags_NoHighlight | ImPlotAxisFlags_NoSideSwitch, ImPlotAxisFlags_Lock | ImPlotAxisFlags_NoHighlight | ImPlotAxisFlags_NoSideSwitch); - ImPlot::SetupAxisFormat(ImAxis_X1, impl::IntegerAxisFormatter, (void*)("0x%04llX")); + ImPlot::SetupAxisFormat(ImAxis_X1, impl::IntegerAxisFormatter, const_cast(reinterpret_cast("0x%04llX"))); ImPlot::SetupMouseText(ImPlotLocation_NorthEast); // Set the axis limit to [first block : last block] @@ -754,7 +754,7 @@ namespace hex { ImPlotAxisFlags_Lock | ImPlotAxisFlags_NoHighlight | ImPlotAxisFlags_NoSideSwitch); ImPlot::SetupAxisScale(ImAxis_Y1, ImPlotScale_Log10); ImPlot::SetupAxesLimits(-1, 256, 1, double(*std::ranges::max_element(m_valueCounts)) * 1.1F, ImGuiCond_Always); - ImPlot::SetupAxisFormat(ImAxis_X1, impl::IntegerAxisFormatter, (void*)("0x%02llX")); + ImPlot::SetupAxisFormat(ImAxis_X1, impl::IntegerAxisFormatter, const_cast(reinterpret_cast("0x%02llX"))); ImPlot::SetupAxisTicks(ImAxis_X1, 0, 255, 17); ImPlot::SetupMouseText(ImPlotLocation_NorthEast); @@ -854,7 +854,7 @@ namespace hex { 100.1F, ImGuiCond_Always); ImPlot::SetupLegend(ImPlotLocation_South, ImPlotLegendFlags_Horizontal | ImPlotLegendFlags_Outside); - ImPlot::SetupAxisFormat(ImAxis_X1, impl::IntegerAxisFormatter, (void*)("0x%04llX")); + ImPlot::SetupAxisFormat(ImAxis_X1, impl::IntegerAxisFormatter, const_cast(reinterpret_cast("0x%04llX"))); ImPlot::SetupMouseText(ImPlotLocation_NorthEast); constexpr static std::array Names = { "iscntrl", "isprint", "isspace", "isblank", diff --git a/plugins/builtin/source/content/command_palette_commands.cpp b/plugins/builtin/source/content/command_palette_commands.cpp index 5f196560c..2653cf33f 100644 --- a/plugins/builtin/source/content/command_palette_commands.cpp +++ b/plugins/builtin/source/content/command_palette_commands.cpp @@ -37,7 +37,7 @@ namespace hex::plugin::builtin { m_unit = Unit::Unitless; } else { std::tie(m_unit, m_multiplier) = parseUnit(value.substr(index)); - value = value.substr(0, index); + value.resize(index); } } else { m_unit = Unit::Unitless; diff --git a/plugins/builtin/source/content/data_inspector.cpp b/plugins/builtin/source/content/data_inspector.cpp index 65c94d8b3..00dc60474 100644 --- a/plugins/builtin/source/content/data_inspector.cpp +++ b/plugins/builtin/source/content/data_inspector.cpp @@ -105,9 +105,8 @@ namespace hex::plugin::builtin { if (buffer.size() < Size) return { }; - auto format = (style == Style::Decimal) ? "{0:d}" : ((style == Style::Hexadecimal) ? hex::format("0x{{0:0{}X}}", Size * 2) : hex::format("0o{{0:0{}o}}", Size * 3)); - - return hex::format(format, bufferToInteger(buffer, endian)); + const auto formatString = (style == Style::Decimal) ? "{0:d}" : ((style == Style::Hexadecimal) ? hex::format("0x{{0:0{}X}}", Size * 2) : hex::format("0o{{0:0{}o}}", Size * 3)); + return hex::format(formatString, bufferToInteger(buffer, endian)); } template @@ -371,7 +370,7 @@ namespace hex::plugin::builtin { }, [](const std::string &value, std::endian endian) -> std::vector { std::vector bytes; - auto wideString = wolv::util::utf8ToWstring(value.c_str()); + auto wideString = wolv::util::utf8ToWstring(value); if (!wideString.has_value()) return bytes; @@ -733,7 +732,7 @@ namespace hex::plugin::builtin { } else { value = hex::format("{0:%a, %d.%m.%Y %H:%M:%S}", *time); } - } catch (fmt::format_error &e) { + } catch (const fmt::format_error &e) { value = "Invalid"; } diff --git a/plugins/builtin/source/content/pl_builtin_types.cpp b/plugins/builtin/source/content/pl_builtin_types.cpp index 140137660..16a4b89e8 100644 --- a/plugins/builtin/source/content/pl_builtin_types.cpp +++ b/plugins/builtin/source/content/pl_builtin_types.cpp @@ -199,9 +199,9 @@ namespace hex::plugin::builtin { std::shared_ptr jsonToPattern(pl::core::Evaluator *evaluator, auto function) { auto object = std::make_shared(evaluator, 0, 0, 0); - std::vector> patterns; try { + std::vector> patterns; jsonToPattern(evaluator, function(), patterns); object->setEntries(patterns); @@ -280,7 +280,6 @@ namespace hex::plugin::builtin { auto bytes = params[0].toBytes(); auto encodingDefinition = params[1].toString(); - std::string value; EncodingFile encodingFile(EncodingFile::Type::Thingy, encodingDefinition); auto pattern = std::make_shared(evaluator, evaluator->getReadOffset(), bytes.size(), 0); diff --git a/plugins/builtin/source/content/providers/gdb_provider.cpp b/plugins/builtin/source/content/providers/gdb_provider.cpp index 3457cdaa8..17a4f5022 100644 --- a/plugins/builtin/source/content/providers/gdb_provider.cpp +++ b/plugins/builtin/source/content/providers/gdb_provider.cpp @@ -99,6 +99,7 @@ namespace hex::plugin::builtin { socket.writeString(packet); auto receivedPacket = socket.readString(6); + std::ignore = receivedPacket; } bool enableNoAckMode(const wolv::net::SocketClient &socket) { @@ -157,7 +158,7 @@ namespace hex::plugin::builtin { if (size <= CacheLineSize) { std::scoped_lock lock(m_cacheLock); - const auto &cacheLine = std::find_if(m_cache.begin(), m_cache.end(), [&](auto &line) { + const auto &cacheLine = std::ranges::find_if(m_cache, [&](const auto &line) { return line.address == alignedOffset; }); diff --git a/plugins/builtin/source/content/providers/intel_hex_provider.cpp b/plugins/builtin/source/content/providers/intel_hex_provider.cpp index 3d6e71cf2..7ffa6796c 100644 --- a/plugins/builtin/source/content/providers/intel_hex_provider.cpp +++ b/plugins/builtin/source/content/providers/intel_hex_provider.cpp @@ -102,7 +102,7 @@ namespace hex::plugin::builtin { if (!data.empty() && checksum != 0x00) throw std::runtime_error("Checksum mismatch"); - while (std::isspace(string[offset]) && offset < string.length()) + while (offset < string.length() && std::isspace(string[offset])) offset++; // Construct region @@ -145,7 +145,7 @@ namespace hex::plugin::builtin { } } - while (std::isspace(string[offset]) && offset < string.length()) + while (offset < string.length() && std::isspace(string[offset])) offset++; } diff --git a/plugins/builtin/source/content/providers/motorola_srec_provider.cpp b/plugins/builtin/source/content/providers/motorola_srec_provider.cpp index 96cf6e014..7009f52c9 100644 --- a/plugins/builtin/source/content/providers/motorola_srec_provider.cpp +++ b/plugins/builtin/source/content/providers/motorola_srec_provider.cpp @@ -57,21 +57,21 @@ namespace hex::plugin::builtin { return value; }; - enum class RecordType { - Header = 0x00, - Data16 = 0x01, - Data24 = 0x02, - Data32 = 0x03, - Reserved = 0x04, - Count16 = 0x05, - Count24 = 0x06, - StartAddress32 = 0x07, - StartAddress24 = 0x08, - StartAddress16 = 0x09, - } recordType; - - bool endOfFile = false; try { + enum class RecordType { + Header = 0x00, + Data16 = 0x01, + Data24 = 0x02, + Data32 = 0x03, + Reserved = 0x04, + Count16 = 0x05, + Count24 = 0x06, + StartAddress32 = 0x07, + StartAddress24 = 0x08, + StartAddress16 = 0x09, + } recordType; + bool endOfFile = false; + while (offset < string.length()) { // Parse record start if (c() != 'S') @@ -159,7 +159,7 @@ namespace hex::plugin::builtin { break; } - while (std::isspace(string[offset]) && offset < string.length()) + while (offset < string.length() && std::isspace(string[offset])) offset++; } } catch (const std::runtime_error &e) { diff --git a/plugins/builtin/source/content/tools/color_picker.cpp b/plugins/builtin/source/content/tools/color_picker.cpp index 542284b5d..7b6e2fd0f 100644 --- a/plugins/builtin/source/content/tools/color_picker.cpp +++ b/plugins/builtin/source/content/tools/color_picker.cpp @@ -13,7 +13,6 @@ namespace hex::plugin::builtin { void drawColorPicker() { static std::array pickedColor = { 0 }; - static std::string rgba8; struct BitValue { int bits; diff --git a/plugins/builtin/source/content/tools/euclidean_alg.cpp b/plugins/builtin/source/content/tools/euclidean_alg.cpp index dafc69a3e..1d14f9bbe 100644 --- a/plugins/builtin/source/content/tools/euclidean_alg.cpp +++ b/plugins/builtin/source/content/tools/euclidean_alg.cpp @@ -9,8 +9,6 @@ namespace hex::plugin::builtin { void drawEuclidianAlgorithm() { - static u64 a, b; - static i64 gcdResult = 0; static i64 lcmResult = 0; static i64 p = 0, q = 0; @@ -37,6 +35,8 @@ namespace hex::plugin::builtin { ImGui::NewLine(); if (ImGuiExt::BeginBox()) { + static u64 a = 0, b = 0; + bool hasChanged = false; hasChanged = ImGui::InputScalar("A", ImGuiDataType_U64, &a) || hasChanged; hasChanged = ImGui::InputScalar("B", ImGuiDataType_U64, &b) || hasChanged; diff --git a/plugins/builtin/source/content/tools/file_tool_combiner.cpp b/plugins/builtin/source/content/tools/file_tool_combiner.cpp index 523d6865d..3fc25041b 100644 --- a/plugins/builtin/source/content/tools/file_tool_combiner.cpp +++ b/plugins/builtin/source/content/tools/file_tool_combiner.cpp @@ -30,7 +30,7 @@ namespace hex::plugin::builtin { if (ImGui::BeginListBox("##files", { -FLT_MIN, 10 * ImGui::GetTextLineHeightWithSpacing() })) { u32 index = 0; - for (auto &file : files) { + for (const auto &file : files) { if (ImGui::Selectable(wolv::util::toUTF8String(file).c_str(), index == selectedIndex)) selectedIndex = index; index++; @@ -41,7 +41,7 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); - ImGui::BeginDisabled(selectedIndex <= 0); + ImGui::BeginDisabled(selectedIndex == 0); { if (ImGui::ArrowButton("move_up", ImGuiDir_Up)) { std::iter_swap(files.begin() + selectedIndex, files.begin() + selectedIndex - 1); diff --git a/plugins/builtin/source/content/tools/ieee_decoder.cpp b/plugins/builtin/source/content/tools/ieee_decoder.cpp index 4bdadce36..b5efa7393 100644 --- a/plugins/builtin/source/content/tools/ieee_decoder.cpp +++ b/plugins/builtin/source/content/tools/ieee_decoder.cpp @@ -74,9 +74,9 @@ namespace hex::plugin::builtin { i64 precision; } ieee754 = {}; - std::string specialNumbers[] = { - "inf" , "Inf", "INF" , "nan" , "Nan" , "NAN", - "qnan","Qnan", "QNAN", "snan", "Snan", "SNAN" + constexpr static std::array SpecialNumbers = { + "inf" , "Inf", "INF" , "nan" , "Nan" , "NAN", + "qnan","Qnan", "QNAN", "snan", "Snan", "SNAN" }; @@ -345,7 +345,7 @@ namespace hex::plugin::builtin { } }; - const static auto FloatToBits = [&specialNumbers](IEEE754 &ieee754, std::string decimalFloatingPointNumberString, int totalBitCount) { + const static auto FloatToBits = [](IEEE754 &ieee754, std::string decimalFloatingPointNumberString, int totalBitCount) { // Always obtain sign first. if (decimalFloatingPointNumberString[0] == '-') { @@ -362,7 +362,7 @@ namespace hex::plugin::builtin { // Detect and use special numbers. for (u32 i = 0; i < 12; i++) { - if (decimalFloatingPointNumberString == specialNumbers[i]) { + if (decimalFloatingPointNumberString == SpecialNumbers[i]) { inputType = InputType(i/3); matchFound = true; break; diff --git a/plugins/decompress/source/content/pl_functions.cpp b/plugins/decompress/source/content/pl_functions.cpp index 2fc87ae77..ef11686ba 100644 --- a/plugins/decompress/source/content/pl_functions.cpp +++ b/plugins/decompress/source/content/pl_functions.cpp @@ -238,15 +238,15 @@ namespace hex::plugin::decompress { if (blockSize == ZSTD_CONTENTSIZE_UNKNOWN) { // Data uses stream compression - ZSTD_inBuffer dataIn = { (void*)source, sourceSize, 0 }; + ZSTD_inBuffer dataIn = { static_cast(source), sourceSize, 0 }; size_t outSize = ZSTD_DStreamOutSize(); std::vector outVec(outSize); - const u8* out = outVec.data(); + u8* out = outVec.data(); size_t lastRet = 0; while (dataIn.pos < dataIn.size) { - ZSTD_outBuffer dataOut = { (void*)out, outSize, 0 }; + ZSTD_outBuffer dataOut = { reinterpret_cast(out), outSize, 0 }; size_t ret = ZSTD_decompressStream(dctx, &dataOut, &dataIn); if (ZSTD_isError(ret)) { diff --git a/plugins/disassembler/source/content/disassemblers/capstone_architectures.cpp b/plugins/disassembler/source/content/disassemblers/capstone_architectures.cpp index 5a9a70bc1..8eabdfc30 100644 --- a/plugins/disassembler/source/content/disassemblers/capstone_architectures.cpp +++ b/plugins/disassembler/source/content/disassemblers/capstone_architectures.cpp @@ -111,10 +111,6 @@ namespace hex::plugin::disasm { class ArchitectureARM64 : public CapstoneArchitecture { public: ArchitectureARM64(cs_mode mode = cs_mode(0)) : CapstoneArchitecture(BuiltinArchitecture::ARM64, mode) {} - - void drawSettings() override { - CapstoneArchitecture::drawSettings(); - } }; class ArchitectureMIPS : public CapstoneArchitecture { @@ -213,19 +209,11 @@ namespace hex::plugin::disasm { class ArchitectureSystemZ : public CapstoneArchitecture { public: ArchitectureSystemZ(cs_mode mode = cs_mode(0)) : CapstoneArchitecture(BuiltinArchitecture::SYSZ, mode) {} - - void drawSettings() override { - CapstoneArchitecture::drawSettings(); - } }; class ArchitectureXCore : public CapstoneArchitecture { public: ArchitectureXCore(cs_mode mode = cs_mode(0)) : CapstoneArchitecture(BuiltinArchitecture::XCORE, mode) {} - - void drawSettings() override { - CapstoneArchitecture::drawSettings(); - } }; class ArchitectureM68K : public CapstoneArchitecture { @@ -262,10 +250,6 @@ namespace hex::plugin::disasm { class ArchitectureTMS320C64X : public CapstoneArchitecture { public: ArchitectureTMS320C64X(cs_mode mode = cs_mode(0)) : CapstoneArchitecture(BuiltinArchitecture::TMS320C64X, mode) {} - - void drawSettings() override { - CapstoneArchitecture::drawSettings(); - } }; class ArchitectureM680X : public CapstoneArchitecture { public: @@ -305,10 +289,6 @@ namespace hex::plugin::disasm { class ArchitectureEVM : public CapstoneArchitecture { public: ArchitectureEVM(cs_mode mode = cs_mode(0)) : CapstoneArchitecture(BuiltinArchitecture::EVM, mode) {} - - void drawSettings() override { - CapstoneArchitecture::drawSettings(); - } }; #if CS_API_MAJOR >= 5 @@ -316,10 +296,6 @@ namespace hex::plugin::disasm { class ArchitectureWASM : public CapstoneArchitecture { public: ArchitectureWASM(cs_mode mode = cs_mode(0)) : CapstoneArchitecture(BuiltinArchitecture::WASM, mode) {} - - void drawSettings() override { - CapstoneArchitecture::drawSettings(); - } }; class ArchitectureRISCV : public CapstoneArchitecture { diff --git a/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp b/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp index d95dd6e93..7462f011a 100644 --- a/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp +++ b/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp @@ -47,7 +47,7 @@ namespace hex::script::loader { if (library == "cimgui") { return getExport(ImHexApi::System::getLibImHexModuleHandle(), symbolName); } else if (library == "ImHex") { - return getExport(hex::getContainingModule((void*)&pInvokeOverride), symbolName); + return getExport(hex::getContainingModule(reinterpret_cast(&pInvokeOverride)), symbolName); } return nullptr; @@ -141,9 +141,9 @@ namespace hex::script::loader { } #if defined (OS_WINDOWS) - hostfxr_set_runtime_property_value(ctx, STRING("PINVOKE_OVERRIDE"), utf8ToUtf16(hex::format("{}", (void*)pInvokeOverride)).c_str()); + hostfxr_set_runtime_property_value(ctx, STRING("PINVOKE_OVERRIDE"), utf8ToUtf16(hex::format("{}", reinterpret_cast(pInvokeOverride))).c_str()); #else - hostfxr_set_runtime_property_value(ctx, STRING("PINVOKE_OVERRIDE"), hex::format("{}", (void*)pInvokeOverride).c_str()); + hostfxr_set_runtime_property_value(ctx, STRING("PINVOKE_OVERRIDE"), hex::format("{}", reinterpret_cast(pInvokeOverride)).c_str()); #endif hostfxr_set_error_writer([](const char_t *message) { diff --git a/plugins/ui/include/popups/popup_file_chooser.hpp b/plugins/ui/include/popups/popup_file_chooser.hpp index d4448bc82..85e044440 100644 --- a/plugins/ui/include/popups/popup_file_chooser.hpp +++ b/plugins/ui/include/popups/popup_file_chooser.hpp @@ -74,6 +74,7 @@ namespace hex::ui { m_selectedFiles.insert(fileIt); } else { if (selected) { + // cppcheck-suppress eraseDereference m_selectedFiles.erase(fileIt); } else { m_selectedFiles.insert(fileIt); diff --git a/plugins/ui/source/ui/pattern_drawer.cpp b/plugins/ui/source/ui/pattern_drawer.cpp index 423770a85..c976e643e 100644 --- a/plugins/ui/source/ui/pattern_drawer.cpp +++ b/plugins/ui/source/ui/pattern_drawer.cpp @@ -360,7 +360,7 @@ namespace hex::ui { bool shouldReset = false; if (ImGui::Button(hex::format(" {} {}", ICON_VS_EYE_WATCH, value).c_str(), ImVec2(width, ImGui::GetTextLineHeight()))) { - auto previousPattern = m_currVisualizedPattern; + const auto *previousPattern = m_currVisualizedPattern; m_currVisualizedPattern = &pattern; auto lastVisualizerError = m_visualizerDrawer.getLastVisualizerError(); if (!lastVisualizerError.empty() || m_currVisualizedPattern != previousPattern) @@ -575,7 +575,7 @@ namespace hex::ui { auto value = pattern.getValue(); auto valueString = pattern.toString(); - if (auto enumPattern = dynamic_cast(&pattern); enumPattern != nullptr) { + if (const auto *enumPattern = dynamic_cast(&pattern); enumPattern != nullptr) { if (ImGui::BeginCombo("##Enum", pattern.getFormattedValue().c_str())) { auto currValue = pattern.getValue().toUnsigned(); for (auto &[name, enumValue] : enumPattern->getEnumValues()) { diff --git a/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp b/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp index 7de45c7f8..096783e79 100644 --- a/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp @@ -941,7 +941,7 @@ namespace hex::plugin::visualizers { s_shouldReset = true; processInputEvents(s_rotation, s_translation, s_scaling, s_nearLimit, s_farLimit); - auto *iterable = dynamic_cast(indicesPattern.get()); + const auto *iterable = dynamic_cast(indicesPattern.get()); if (iterable != nullptr && iterable->getEntryCount() > 0) { auto content = iterable->getEntry(0); while (content->getSize() == 0) { diff --git a/plugins/visualizers/source/content/pl_visualizers/digital_signal.cpp b/plugins/visualizers/source/content/pl_visualizers/digital_signal.cpp index 0d727017b..92079775f 100644 --- a/plugins/visualizers/source/content/pl_visualizers/digital_signal.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/digital_signal.cpp @@ -31,7 +31,7 @@ namespace hex::plugin::visualizers { bitfield->forEachEntry(0, bitfield->getEntryCount(), [&](u64, pl::ptrn::Pattern *entry) { size_t bitSize; - if (auto bitfieldField = dynamic_cast(entry); bitfieldField != nullptr) + if (const auto *bitfieldField = dynamic_cast(entry); bitfieldField != nullptr) bitSize = bitfieldField->getBitSize(); else bitSize = entry->getSize() * 8; diff --git a/plugins/visualizers/source/content/pl_visualizers/image.cpp b/plugins/visualizers/source/content/pl_visualizers/image.cpp index 21fa26b94..4ef1a0a8e 100644 --- a/plugins/visualizers/source/content/pl_visualizers/image.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/image.cpp @@ -9,7 +9,7 @@ namespace hex::plugin::visualizers { std::vector getIndices(pl::ptrn::Pattern *colorTablePattern, u64 width, u64 height); - ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, std::vector& indices, u64 width, u64 height); + ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, const std::vector &indices, u64 width, u64 height); void drawImageVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { @@ -75,7 +75,7 @@ namespace hex::plugin::visualizers { } } - ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, std::vector& indices, u64 width, u64 height) { + ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, const std::vector &indices, u64 width, u64 height) { std::vector colorTable = patternToArray(colorTablePattern); auto colorCount = colorTable.size(); auto indexCount = indices.size(); @@ -89,7 +89,7 @@ namespace hex::plugin::visualizers { image[i] = colorTable[index]; } void *tmp = image.data(); - ImU8 *data = static_cast(tmp); + auto *data = static_cast(tmp); ImGuiExt::Texture texture = ImGuiExt::Texture::fromBitmap(data, indexCount*4, width, height, ImGuiExt::Texture::Filter::Nearest); return texture; } @@ -97,9 +97,9 @@ namespace hex::plugin::visualizers { std::vector getIndices(pl::ptrn::Pattern *pattern, u64 width, u64 height) { auto indexCount = width * height / pattern->getSize(); std::vector indices; - auto *iterable = dynamic_cast(pattern); + const auto *iterable = dynamic_cast(pattern); - if (iterable == nullptr || iterable->getEntryCount() <= 0) + if (iterable == nullptr || iterable->getEntryCount() == 0) return indices; auto content = iterable->getEntry(0); auto byteCount = content->getSize(); diff --git a/plugins/yara_rules/source/content/yara_rule.cpp b/plugins/yara_rules/source/content/yara_rule.cpp index 43888df9b..b69933aee 100644 --- a/plugins/yara_rules/source/content/yara_rule.cpp +++ b/plugins/yara_rules/source/content/yara_rule.cpp @@ -86,6 +86,8 @@ namespace hex::plugin::yara { YaraRule::Rule newRule; newRule.identifier = rule->identifier; newRule.matches.push_back({ "", Region::Invalid(), true }); + + resultContext.matchedRules.emplace_back(std::move(newRule)); } break; @@ -171,7 +173,7 @@ namespace hex::plugin::yara { return context.buffer.data(); }; iterator.file_size = [](YR_MEMORY_BLOCK_ITERATOR *iterator) -> u64 { - auto &context = *static_cast(iterator->context); + const auto &context = *static_cast(iterator->context); return context.region.size; };