build: Fix cppcheck issues

This commit is contained in:
WerWolv
2025-07-10 13:57:08 +02:00
parent e58ce527c6
commit da2aa85a8a
40 changed files with 87 additions and 230 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -731,7 +731,7 @@ EXPORT_MODULE namespace hex {
add(impl::Entry {
unlocalizedCategory,
unlocalizedName,
[=, ...args = std::forward<Args>(args)]() mutable {
[unlocalizedName, ...args = std::forward<Args>(args)]() mutable {
auto node = std::make_unique<T>(std::forward<Args>(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);
}

View File

@@ -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<T>) {
m_value = nullptr; // cppcheck-suppress nullPointer
} else {
m_value = { };
}

View File

@@ -1,60 +0,0 @@
#pragma once
#include "imgui.h"
#include <vector>
namespace hex::ft {
class Bitmap {
ImU32 m_width;
ImU32 m_height;
ImU32 m_pitch;
std::vector <ImU8> 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<ImU8>(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 <ImU8> &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;
};
}

View File

@@ -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<T, Size> m_data;
std::array<T, Size> m_data = { };
};
template<typename T, size_t Rows, size_t Columns>

View File

@@ -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<T> operator*() const { return *pointer; }
[[nodiscard]] operator T() const { return pointer; }
T pointer;

View File

@@ -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<bool> m_running;
int m_socketFd;
int m_socketFd = -1;
};
}

View File

@@ -13,7 +13,7 @@ namespace hex::prv::undo {
class Operation : public ICloneable<Operation> {
public:
virtual ~Operation() = default;
~Operation() override = default;
virtual void undo(Provider *provider) = 0;
virtual void redo(Provider *provider) = 0;

View File

@@ -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 });

View File

@@ -83,12 +83,8 @@ namespace hex {
m_functions.getFeaturesFunction = getPluginFunction<PluginFunctions::GetSubCommandsFunc>("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 {

View File

@@ -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();
}

View File

@@ -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 <ImU8> 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<std::vector<ImU8>> fir(3, std::vector<ImU8>(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);
}
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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<std::pair<u64, u8>> patchesToMove;

View File

@@ -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;