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

@@ -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<void*>(reinterpret_cast<const void*>("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<void*>(reinterpret_cast<const void*>("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<void*>(reinterpret_cast<const void*>("0x%04llX")));
ImPlot::SetupMouseText(ImPlotLocation_NorthEast);
constexpr static std::array Names = { "iscntrl", "isprint", "isspace", "isblank",

View File

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

View File

@@ -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<T, Size>(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<T, Size>(buffer, endian));
}
template<std::integral T, size_t Size = sizeof(T)>
@@ -371,7 +370,7 @@ namespace hex::plugin::builtin {
},
[](const std::string &value, std::endian endian) -> std::vector<u8> {
std::vector<u8> 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";
}

View File

@@ -199,9 +199,9 @@ namespace hex::plugin::builtin {
std::shared_ptr<pl::ptrn::Pattern> jsonToPattern(pl::core::Evaluator *evaluator, auto function) {
auto object = std::make_shared<pl::ptrn::PatternStruct>(evaluator, 0, 0, 0);
std::vector<std::shared_ptr<pl::ptrn::Pattern>> patterns;
try {
std::vector<std::shared_ptr<pl::ptrn::Pattern>> 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<PatternEncodedString>(evaluator, evaluator->getReadOffset(), bytes.size(), 0);

View File

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

View File

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

View File

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

View File

@@ -13,7 +13,6 @@ namespace hex::plugin::builtin {
void drawColorPicker() {
static std::array<float, 4> pickedColor = { 0 };
static std::string rgba8;
struct BitValue {
int bits;

View File

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

View File

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

View File

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

View File

@@ -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<const void*>(source), sourceSize, 0 };
size_t outSize = ZSTD_DStreamOutSize();
std::vector<u8> 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<void*>(out), outSize, 0 };
size_t ret = ZSTD_decompressStream(dctx, &dataOut, &dataIn);
if (ZSTD_isError(ret)) {

View File

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

View File

@@ -47,7 +47,7 @@ namespace hex::script::loader {
if (library == "cimgui") {
return getExport<void*>(ImHexApi::System::getLibImHexModuleHandle(), symbolName);
} else if (library == "ImHex") {
return getExport<void*>(hex::getContainingModule((void*)&pInvokeOverride), symbolName);
return getExport<void*>(hex::getContainingModule(reinterpret_cast<void*>(&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<void*>(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<void*>(pInvokeOverride)).c_str());
#endif
hostfxr_set_error_writer([](const char_t *message) {

View File

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

View File

@@ -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<pl::ptrn::PatternBitfieldFieldEnum*>(&pattern); enumPattern != nullptr) {
if (const auto *enumPattern = dynamic_cast<pl::ptrn::PatternBitfieldFieldEnum*>(&pattern); enumPattern != nullptr) {
if (ImGui::BeginCombo("##Enum", pattern.getFormattedValue().c_str())) {
auto currValue = pattern.getValue().toUnsigned();
for (auto &[name, enumValue] : enumPattern->getEnumValues()) {

View File

@@ -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<pl::ptrn::IIterable*>(indicesPattern.get());
const auto *iterable = dynamic_cast<pl::ptrn::IIterable*>(indicesPattern.get());
if (iterable != nullptr && iterable->getEntryCount() > 0) {
auto content = iterable->getEntry(0);
while (content->getSize() == 0) {

View File

@@ -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<pl::ptrn::PatternBitfieldField*>(entry); bitfieldField != nullptr)
if (const auto *bitfieldField = dynamic_cast<pl::ptrn::PatternBitfieldField*>(entry); bitfieldField != nullptr)
bitSize = bitfieldField->getBitSize();
else
bitSize = entry->getSize() * 8;

View File

@@ -9,7 +9,7 @@
namespace hex::plugin::visualizers {
std::vector<u32> getIndices(pl::ptrn::Pattern *colorTablePattern, u64 width, u64 height);
ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, std::vector<u32>& indices, u64 width, u64 height);
ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, const std::vector<u32> &indices, u64 width, u64 height);
void drawImageVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
@@ -75,7 +75,7 @@ namespace hex::plugin::visualizers {
}
}
ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, std::vector<u32>& indices, u64 width, u64 height) {
ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, const std::vector<u32> &indices, u64 width, u64 height) {
std::vector<u32> colorTable = patternToArray<u32>(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<ImU8 *>(tmp);
auto *data = static_cast<const ImU8 *>(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<u32> getIndices(pl::ptrn::Pattern *pattern, u64 width, u64 height) {
auto indexCount = width * height / pattern->getSize();
std::vector<u32> indices;
auto *iterable = dynamic_cast<pl::ptrn::IIterable *>(pattern);
const auto *iterable = dynamic_cast<pl::ptrn::IIterable *>(pattern);
if (iterable == nullptr || iterable->getEntryCount() <= 0)
if (iterable == nullptr || iterable->getEntryCount() == 0)
return indices;
auto content = iterable->getEntry(0);
auto byteCount = content->getSize();

View File

@@ -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<ScanContext *>(iterator->context);
const auto &context = *static_cast<ScanContext *>(iterator->context);
return context.region.size;
};