From 87feeb225d2b8b75e84f4c13324621bd0077c3a5 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 00:06:21 -0400 Subject: [PATCH 01/14] working on cleaning up warnings when -Wconversion is enabled, there's... a lot --- cmake/Modules/AddWarnings.cmake | 2 +- include/Value.h | 10 +++++ include/edb.h | 6 +-- include/util/Container.h | 8 ++-- include/util/Math.h | 2 +- plugins/Analyzer/AnalyzerWidget.cpp | 14 +++---- plugins/Backtrace/DialogBacktrace.cpp | 8 ++-- plugins/BinaryInfo/symbols.cpp | 8 ++-- .../unix/linux/PlatformProcess.cpp | 13 ++++-- .../unix/linux/PlatformThread.cpp | 2 +- .../linux/arch/x86-generic/PlatformState.cpp | 40 +++++++++---------- plugins/HeapAnalyzer/DialogHeap.cpp | 7 +++- plugins/InstructionInspector/Plugin.cpp | 4 +- plugins/ODbgRegisterView/DialogEditGPR.cpp | 6 +-- .../DialogEditSimdRegister.cpp | 7 ++-- plugins/ODbgRegisterView/GprEdit.cpp | 14 +++---- .../ODbgRegisterView/MultiBitFieldWidget.cpp | 4 +- plugins/ODbgRegisterView/Plugin.cpp | 3 +- plugins/ODbgRegisterView/ValueField.cpp | 4 +- .../DialogProcessProperties.cpp | 25 +++++++++--- src/BinaryString.cpp | 8 ++-- src/SymbolManager.cpp | 2 +- src/arch/x86-generic/ArchProcessor.cpp | 16 ++++---- src/edb.cpp | 32 ++++++++++----- src/widgets/QDisassemblyView.cpp | 6 +-- 25 files changed, 150 insertions(+), 101 deletions(-) diff --git a/cmake/Modules/AddWarnings.cmake b/cmake/Modules/AddWarnings.cmake index d80db5a83..8088c5b62 100644 --- a/cmake/Modules/AddWarnings.cmake +++ b/cmake/Modules/AddWarnings.cmake @@ -14,7 +14,7 @@ function(TARGET_ADD_WARNINGS TARGET) -Wunused -Woverloaded-virtual -pedantic - #-Wconversion + -Wconversion #-Wsign-conversion #-Wnull-dereference -Wdouble-promotion diff --git a/include/Value.h b/include/Value.h index 8d51df8c1..042e7514c 100644 --- a/include/Value.h +++ b/include/Value.h @@ -28,6 +28,14 @@ namespace v1 { EDB_EXPORT bool debuggeeIs32Bit(); } +// TODO(eteran): honestly, this whole file is filled with conversions, so the warnings about conversions are not really helpful. +// Of course, we should audit the code to make sure that all conversions are intentional and safe. For now, suppress the warnings +// about conversions in this file as it's just too loud when they are enabled. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wsign-conversion" + + namespace detail { template @@ -854,6 +862,8 @@ static_assert(sizeof(value_type80) * 8 == 80, "value_type80 size is broken!"); } +#pragma GCC diagnostic pop + // GPR on x86 using value8 = detail::value_type; using value16 = detail::value_type; diff --git a/include/edb.h b/include/edb.h index 313481156..331172e5e 100644 --- a/include/edb.h +++ b/include/edb.h @@ -62,7 +62,7 @@ namespace v1 { EDB_EXPORT extern IDebugger *debugger_core; EDB_EXPORT extern QWidget *debugger_ui; -// the symbol mananger +// the symbol manager EDB_EXPORT ISymbolManager &symbol_manager(); // the memory region manager @@ -74,7 +74,7 @@ EDB_EXPORT ArchProcessor &arch_processor(); // widgets EDB_EXPORT QAbstractScrollArea *disassembly_widget(); -// breakpoint managment +// breakpoint management EDB_EXPORT std::shared_ptr find_breakpoint(address_t address); EDB_EXPORT std::shared_ptr find_triggered_breakpoint(address_t address); EDB_EXPORT QString get_breakpoint_condition(address_t address); @@ -175,7 +175,7 @@ EDB_EXPORT void update_ui(); // these are here and not members of state because // they may require using the debugger core plugin and -// we don't want to force a dependancy between the two +// we don't want to force a dependency between the two EDB_EXPORT void pop_value(State *state); EDB_EXPORT void push_value(State *state, reg_t value); diff --git a/include/util/Container.h b/include/util/Container.h index f74b1609d..9413d1562 100644 --- a/include/util/Container.h +++ b/include/util/Container.h @@ -15,16 +15,16 @@ namespace util { template constexpr void shl(std::array &buffer, U value = T()) { - static_assert(std::is_convertible_v, "U must be convertible to the type contained in the array!"); + static_assert(std::is_convertible_v, "U must be convertible to the type contained in the array!"); std::rotate(buffer.begin(), buffer.begin() + 1, buffer.end()); - buffer[N - 1] = value; + buffer[N - 1] = static_cast(value); } template constexpr void shr(std::array &buffer, U value = T()) { - static_assert(std::is_convertible_v, "U must be convertible to the type contained in the array!"); + static_assert(std::is_convertible_v, "U must be convertible to the type contained in the array!"); std::rotate(buffer.rbegin(), buffer.rbegin() + 1, buffer.rend()); - buffer[0] = value; + buffer[0] = static_cast(value); } template diff --git a/include/util/Math.h b/include/util/Math.h index 7765e24d0..ba856fa16 100644 --- a/include/util/Math.h +++ b/include/util/Math.h @@ -20,7 +20,7 @@ int percentage(N1 regions_finished, N2 regions_total, N3 bytes_done, N4 bytes_to const auto region_step = 1.0f / static_cast(regions_total) * 100.0f; // how many regions are done? - const float regions_complete = region_step * regions_finished; + const float regions_complete = region_step * static_cast(regions_finished); // how much of the current region is done? const float region_percent = region_step * static_cast(bytes_done) / static_cast(bytes_total); diff --git a/plugins/Analyzer/AnalyzerWidget.cpp b/plugins/Analyzer/AnalyzerWidget.cpp index 26053d09a..372b327a4 100644 --- a/plugins/Analyzer/AnalyzerWidget.cpp +++ b/plugins/Analyzer/AnalyzerWidget.cpp @@ -72,7 +72,7 @@ void AnalyzerWidget::paintEvent(QPaintEvent *event) { const QSet specified_functions = edb::v1::analyzer()->specifiedFunctions(); const IAnalyzer::FunctionMap functions = edb::v1::analyzer()->functions(region); - const auto byte_width = static_cast(width()) / region->size(); + const auto byte_width = static_cast(width()) / static_cast(region->size()); if (!cache_ || width() != cache_->width() || height() != cache_->height() || cacheNumFuncs_ != functions.size()) { @@ -85,8 +85,8 @@ void AnalyzerWidget::paintEvent(QPaintEvent *event) { for (auto it = functions.begin(); it != functions.end(); ++it) { const Function &f = it.value(); - const auto first_offset = static_cast((f.entryAddress() - region->start()) * byte_width); - const auto last_offset = static_cast((f.endAddress() - region->start()) * byte_width); + const auto first_offset = static_cast(static_cast(f.entryAddress() - region->start()) * byte_width); + const auto last_offset = static_cast(static_cast(f.endAddress() - region->start()) * byte_width); if (!specified_functions.contains(f.entryAddress())) { painter.fillRect(first_offset, 0, last_offset - first_offset, height(), QBrush(Qt::darkGreen)); @@ -97,7 +97,7 @@ void AnalyzerWidget::paintEvent(QPaintEvent *event) { // highlight header of binary (probably not going to be too noticeable but just in case) if (std::unique_ptr binary_info = edb::v1::get_binary_info(region)) { - painter.fillRect(0, 0, static_cast(binary_info->headerSize() * byte_width), height(), QBrush(Qt::darkBlue)); + painter.fillRect(0, 0, static_cast(static_cast(binary_info->headerSize()) * byte_width), height(), QBrush(Qt::darkBlue)); } } @@ -108,7 +108,7 @@ void AnalyzerWidget::paintEvent(QPaintEvent *event) { if (auto scroll_area = qobject_cast(edb::v1::disassembly_widget())) { if (QScrollBar *scrollbar = scroll_area->verticalScrollBar()) { QFontMetrics fm(font()); - const auto offset = static_cast(scrollbar->value() * byte_width); + const auto offset = static_cast(static_cast(scrollbar->value()) * byte_width); const QString triangle(QChar(0x25b4)); @@ -148,12 +148,12 @@ void AnalyzerWidget::mousePressEvent(QMouseEvent *event) { if (const std::shared_ptr region = edb::v1::current_cpu_view_region()) { const IAnalyzer::FunctionMap functions = edb::v1::analyzer()->functions(region); if (region->size() != 0 && !functions.empty()) { - const auto byte_width = static_cast(width()) / region->size(); + const auto byte_width = static_cast(width()) / static_cast(region->size()); const edb::address_t start = region->start(); const edb::address_t end = region->end(); - edb::address_t offset = start + static_cast(event->x() / byte_width); + edb::address_t offset = start + static_cast(event->x() / byte_width); const edb::address_t address = qBound(start, offset, end - 1); edb::v1::jump_to_address(address); diff --git a/plugins/Backtrace/DialogBacktrace.cpp b/plugins/Backtrace/DialogBacktrace.cpp index 25dbeaba2..ae0d8cd2b 100644 --- a/plugins/Backtrace/DialogBacktrace.cpp +++ b/plugins/Backtrace/DialogBacktrace.cpp @@ -14,6 +14,7 @@ #include #include +#include namespace BacktracePlugin { namespace { @@ -154,10 +155,11 @@ void DialogBacktrace::populateTable() { // Get the call stack and populate the table with entries. CallStack call_stack; const size_t size = call_stack.size(); - for (size_t i = 0; i < size; i++) { + for (size_t i = 0; i < size && i <= static_cast(std::numeric_limits::max()); i++) { + const int row = static_cast(i); // Create the row to insert info - table_->insertRow(i); + table_->insertRow(row); // Get the stack frame so that we can insert its info CallStack::StackFrame *frame = call_stack[i]; @@ -192,7 +194,7 @@ void DialogBacktrace::populateTable() { flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable; item->setFlags(flags); - table_->setItem(i, j, item); + table_->setItem(row, j, item); } } diff --git a/plugins/BinaryInfo/symbols.cpp b/plugins/BinaryInfo/symbols.cpp index d6540cf7e..ea8320c80 100644 --- a/plugins/BinaryInfo/symbols.cpp +++ b/plugins/BinaryInfo/symbols.cpp @@ -39,7 +39,7 @@ struct elf32_model : elf_model<32> { static constexpr uint32_t elf_r_sym(uint32_t x) { return ELF32_R_SYM(x); } static constexpr uint32_t elf_r_type(uint32_t x) { return ELF32_R_TYPE(x); } static constexpr uint8_t elf_st_type(uint8_t x) { return ELF32_ST_TYPE(x); } - static constexpr uint8_t elf_st_bind(uint8_t x) { return ELF32_ST_BIND(x); } + static constexpr uint8_t elf_st_bind(uint8_t x) { return static_cast(ELF32_ST_BIND(x)); } struct symbol { elf_addr address; @@ -68,7 +68,7 @@ struct elf64_model : elf_model<64> { static constexpr uint64_t elf_r_sym(uint64_t x) { return ELF64_R_SYM(x); } static constexpr uint64_t elf_r_type(uint64_t x) { return ELF64_R_TYPE(x); } static constexpr uint8_t elf_st_type(uint8_t x) { return ELF64_ST_TYPE(x); } - static constexpr uint8_t elf_st_bind(uint8_t x) { return ELF64_ST_BIND(x); } + static constexpr uint8_t elf_st_bind(uint8_t x) { return static_cast(ELF64_ST_BIND(x)); } struct symbol { elf_addr address; @@ -241,7 +241,7 @@ void collect_symbols(const void *p, Size size, std::vector & auto symbol_tab = reinterpret_cast(base + linked->sh_offset); auto string_tab = reinterpret_cast(base + sections_begin[linked->sh_link].sh_offset); - const elf_addr symbol_address = base_address + (n * M::plt_entry_size); + const elf_addr symbol_address = static_cast(base_address + (n * M::plt_entry_size)); const char *sym_name = §ion_strings[section->sh_name]; if (strlen(sym_name) > (sizeof(".rela.") - 1) && memcmp(sym_name, ".rela.", (sizeof(".rela.") - 1)) == 0) { @@ -280,7 +280,7 @@ void collect_symbols(const void *p, Size size, std::vector & auto symbol_tab = reinterpret_cast(base + linked->sh_offset); auto string_tab = reinterpret_cast(base + sections_begin[linked->sh_link].sh_offset); - const elf_addr symbol_address = base_address + (n * M::plt_entry_size); + const elf_addr symbol_address = static_cast(base_address + (n * M::plt_entry_size)); const char *sym_name = §ion_strings[section->sh_name]; if (strlen(sym_name) > (sizeof(".rel.") - 1) && memcmp(sym_name, ".rel.", (sizeof(".rel.") - 1)) == 0) { diff --git a/plugins/DebuggerCore/unix/linux/PlatformProcess.cpp b/plugins/DebuggerCore/unix/linux/PlatformProcess.cpp index 6e9cf21e7..13aee6ecd 100644 --- a/plugins/DebuggerCore/unix/linux/PlatformProcess.cpp +++ b/plugins/DebuggerCore/unix/linux/PlatformProcess.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -232,7 +233,7 @@ bool get_program_headers(const IProcess *process, edb::address_t *phdr_memaddr, *phdr_memaddr = entry.a_un.a_val; break; case AT_PHNUM: - *num_phdr = entry.a_un.a_val; + *num_phdr = static_cast(std::min(entry.a_un.a_val, static_cast(std::numeric_limits::max()))); break; } } @@ -244,7 +245,7 @@ bool get_program_headers(const IProcess *process, edb::address_t *phdr_memaddr, *phdr_memaddr = entry.a_un.a_val; break; case AT_PHNUM: - *num_phdr = entry.a_un.a_val; + *num_phdr = static_cast(std::min(entry.a_un.a_val, static_cast(std::numeric_limits::max()))); break; } } @@ -389,8 +390,12 @@ std::size_t PlatformProcess::patchBytes(edb::address_t address, const void *buf, Patch patch; patch.address = address; - patch.origBytes.resize(len); - patch.newBytes = QByteArray(static_cast(buf), len); + if (len > static_cast(std::numeric_limits::max())) { + return 0; + } + const int len_int = static_cast(len); + patch.origBytes.resize(len_int); + patch.newBytes = QByteArray(static_cast(buf), len_int); size_t read_ret = readBytes(address, patch.origBytes.data(), len); if (read_ret != len) { diff --git a/plugins/DebuggerCore/unix/linux/PlatformThread.cpp b/plugins/DebuggerCore/unix/linux/PlatformThread.cpp index 46eb4f2cd..6a2524ac0 100644 --- a/plugins/DebuggerCore/unix/linux/PlatformThread.cpp +++ b/plugins/DebuggerCore/unix/linux/PlatformThread.cpp @@ -61,7 +61,7 @@ int PlatformThread::priority() const { struct user_stat thread_stat; int n = get_user_task_stat(process_->pid(), tid_, &thread_stat); if (n >= 18) { - return thread_stat.priority; + return static_cast(thread_stat.priority); } return 0; diff --git a/plugins/DebuggerCore/unix/linux/arch/x86-generic/PlatformState.cpp b/plugins/DebuggerCore/unix/linux/arch/x86-generic/PlatformState.cpp index 8daf508f2..63513882c 100644 --- a/plugins/DebuggerCore/unix/linux/arch/x86-generic/PlatformState.cpp +++ b/plugins/DebuggerCore/unix/linux/arch/x86-generic/PlatformState.cpp @@ -175,7 +175,7 @@ int PlatformState::X87::tag(size_t n) const { edb::value16 PlatformState::X87::restoreTagWord(uint16_t twd) const { uint16_t tagWord = 0; for (size_t n = 0; n < MAX_FPU_REG_COUNT; ++n) { - tagWord |= makeTag(n, twd) << (2 * n); + tagWord |= static_cast(makeTag(n, twd) << (2 * n)); } return edb::value16(tagWord); @@ -193,7 +193,7 @@ std::uint16_t PlatformState::X87::reducedTagWord() const { result = (result | (result >> 2)) & 0x0f0f; // 0000123400005678 result = (result | (result >> 4)) & 0x00ff; // 0000000012345678 - return result; + return static_cast(result); } void PlatformState::fillFrom(const UserFPRegsStructX86 ®s) { @@ -481,23 +481,23 @@ void PlatformState::fillStruct(UserRegsStructX86 ®s) const { util::mark_memory(®s, sizeof(regs)); if (x86.gpr32Filled) { - regs.eax = x86.GPRegs[X86::EAX]; - regs.ecx = x86.GPRegs[X86::ECX]; - regs.edx = x86.GPRegs[X86::EDX]; - regs.ebx = x86.GPRegs[X86::EBX]; - regs.esp = x86.GPRegs[X86::ESP]; - regs.ebp = x86.GPRegs[X86::EBP]; - regs.esi = x86.GPRegs[X86::ESI]; - regs.edi = x86.GPRegs[X86::EDI]; + regs.eax = static_cast(x86.GPRegs[X86::EAX]); + regs.ecx = static_cast(x86.GPRegs[X86::ECX]); + regs.edx = static_cast(x86.GPRegs[X86::EDX]); + regs.ebx = static_cast(x86.GPRegs[X86::EBX]); + regs.esp = static_cast(x86.GPRegs[X86::ESP]); + regs.ebp = static_cast(x86.GPRegs[X86::EBP]); + regs.esi = static_cast(x86.GPRegs[X86::ESI]); + regs.edi = static_cast(x86.GPRegs[X86::EDI]); regs.xes = x86.segRegs[X86::ES]; regs.xcs = x86.segRegs[X86::CS]; regs.xss = x86.segRegs[X86::SS]; regs.xds = x86.segRegs[X86::DS]; regs.xfs = x86.segRegs[X86::FS]; regs.xgs = x86.segRegs[X86::GS]; - regs.orig_eax = x86.orig_ax; - regs.eflags = x86.flags; - regs.eip = x86.IP; + regs.orig_eax = static_cast(x86.orig_ax); + regs.eflags = static_cast(x86.flags); + regs.eip = static_cast(x86.IP); } } @@ -575,8 +575,8 @@ void PlatformState::fillStruct(UserFPRegsStructX86 ®s) const { regs.swd = x87.statusWord; regs.cwd = x87.controlWord; regs.twd = x87.tagWord; - regs.fip = x87.instPtrOffset; - regs.foo = x87.dataPtrOffset; + regs.fip = static_cast(x87.instPtrOffset); + regs.foo = static_cast(x87.dataPtrOffset); regs.fcs = x87.instPtrSelector; regs.fos = x87.dataPtrSelector; for (size_t n = 0; n < MAX_FPU_REG_COUNT; ++n) { @@ -620,8 +620,8 @@ void PlatformState::fillStruct(UserFPXRegsStructX86 ®s) const { regs.swd = x87.statusWord; regs.twd = x87.reducedTagWord(); regs.cwd = x87.controlWord; - regs.fip = x87.instPtrOffset; - regs.foo = x87.dataPtrOffset; + regs.fip = static_cast(x87.instPtrOffset); + regs.foo = static_cast(x87.dataPtrOffset); regs.fcs = x87.instPtrSelector; regs.fos = x87.dataPtrSelector; regs.fop = x87.opCode; @@ -648,8 +648,8 @@ size_t PlatformState::fillStruct(X86XState ®s) const { regs.swd = x87.statusWord; regs.cwd = x87.controlWord; regs.twd = x87.reducedTagWord(); - regs.fioff = x87.instPtrOffset; - regs.fooff = x87.dataPtrOffset; + regs.fioff = static_cast(x87.instPtrOffset); + regs.fooff = static_cast(x87.dataPtrOffset); if (is64Bit()) { std::memcpy(®s.fiseg, reinterpret_cast(&x87.instPtrOffset) + 4, 4); std::memcpy(®s.foseg, reinterpret_cast(&x87.dataPtrOffset) + 4, 4); @@ -1120,7 +1120,7 @@ edb::reg_t PlatformState::flags() const { * @return */ int PlatformState::fpuStackPointer() const { - return x87.stackPointer(); + return static_cast(x87.stackPointer()); } /** diff --git a/plugins/HeapAnalyzer/DialogHeap.cpp b/plugins/HeapAnalyzer/DialogHeap.cpp index a9d96efd5..07547d35d 100644 --- a/plugins/HeapAnalyzer/DialogHeap.cpp +++ b/plugins/HeapAnalyzer/DialogHeap.cpp @@ -34,6 +34,7 @@ #include #include #include +#include namespace HeapAnalyzerPlugin { namespace { @@ -384,11 +385,13 @@ void DialogHeap::collectBlocks(edb::address_t start_address, edb::address_t end_ QString utf16Data; int asciisz; int utf16sz; + const auto max_string_length = + static_cast(std::min(currentChunk.chunkSize(), std::numeric_limits::max())); if (edb::v1::get_ascii_string_at_address( block_start(currentChunkAddress), asciiData, min_string_length, - currentChunk.chunkSize(), + max_string_length, asciisz)) { data = asciiData; @@ -397,7 +400,7 @@ void DialogHeap::collectBlocks(edb::address_t start_address, edb::address_t end_ block_start(currentChunkAddress), utf16Data, min_string_length, - currentChunk.chunkSize(), + max_string_length, utf16sz)) { data = utf16Data; data_type = ResultViewModel::Result::Utf16; diff --git a/plugins/InstructionInspector/Plugin.cpp b/plugins/InstructionInspector/Plugin.cpp index 9341c2f8c..795d0f1db 100644 --- a/plugins/InstructionInspector/Plugin.cpp +++ b/plugins/InstructionInspector/Plugin.cpp @@ -769,7 +769,7 @@ std::string runOBJDUMP(const std::vector &bytes, edb::address_t ad return "; Failed to create binary file"; } - const int size = bytes.size(); + const qint64 size = static_cast(bytes.size()); if (binary.write(reinterpret_cast(bytes.data()), size) != size) { return "; Failed to write to binary file"; @@ -890,7 +890,7 @@ std::string runNDISASM(const std::vector &bytes, edb::address_t ad return "; Failed to create binary file"; } - const int size = bytes.size(); + const qint64 size = static_cast(bytes.size()); if (binary.write(reinterpret_cast(bytes.data()), size) != size) { return "; Failed to write to binary file"; diff --git a/plugins/ODbgRegisterView/DialogEditGPR.cpp b/plugins/ODbgRegisterView/DialogEditGPR.cpp index fb31438eb..3f12eee7f 100644 --- a/plugins/ODbgRegisterView/DialogEditGPR.cpp +++ b/plugins/ODbgRegisterView/DialogEditGPR.cpp @@ -32,7 +32,7 @@ DialogEditGPR::DialogEditGPR(QWidget *parent, Qt::WindowFlags f) auto &label = columnLabel(static_cast(FIRST_ENTRY_COL + c)); label = new QLabel(this); label->setAlignment(Qt::AlignCenter); - allContentsGrid->addWidget(label, GPR_LABELS_ROW, FIRST_ENTRY_COL + c); + allContentsGrid->addWidget(label, GPR_LABELS_ROW, static_cast(FIRST_ENTRY_COL + c)); } { @@ -41,7 +41,7 @@ DialogEditGPR::DialogEditGPR(QWidget *parent, Qt::WindowFlags f) for (std::size_t f = 0; f < formatNames.size(); ++f) { auto &label = rowLabel(static_cast(FIRST_ENTRY_ROW + f)); label = new QLabel(formatNames[f], this); - allContentsGrid->addWidget(label, FIRST_ENTRY_ROW + f, FORMAT_LABELS_COL); + allContentsGrid->addWidget(label, static_cast(FIRST_ENTRY_ROW + f), FORMAT_LABELS_COL); } } @@ -58,7 +58,7 @@ DialogEditGPR::DialogEditGPR(QWidget *parent, Qt::WindowFlags f) entry = new GprEdit(offsetsInInteger[c], integerSizes[c], formats[f], this); connect(entry, &GprEdit::textEdited, this, &DialogEditGPR::onTextEdited); entry->installEventFilter(this); - allContentsGrid->addWidget(entry, FIRST_ENTRY_ROW + f, FIRST_ENTRY_COL + c); + allContentsGrid->addWidget(entry, static_cast(FIRST_ENTRY_ROW + f), static_cast(FIRST_ENTRY_COL + c)); } } } diff --git a/plugins/ODbgRegisterView/DialogEditSimdRegister.cpp b/plugins/ODbgRegisterView/DialogEditSimdRegister.cpp index 0ca8d3a8d..7b421b486 100644 --- a/plugins/ODbgRegisterView/DialogEditSimdRegister.cpp +++ b/plugins/ODbgRegisterView/DialogEditSimdRegister.cpp @@ -36,8 +36,9 @@ void DialogEditSimdRegister::setupEntries(const QString &label, std::arrayaddWidget(new QLabel(label, this), row, ENTRIES_FIRST_COL - 1); for (std::size_t entryIndex = 0; entryIndex < NumEntries; ++entryIndex) { auto &entry = entries[entryIndex]; - const int bytesPerEntry = NumBytes / NumEntries; - entry = new NumberEdit(ENTRIES_FIRST_COL + bytesPerEntry * (NumEntries - 1 - entryIndex), bytesPerEntry, this); + const int bytesPerEntry = static_cast(NumBytes / NumEntries); + const int entryColumn = ENTRIES_FIRST_COL + bytesPerEntry * static_cast(NumEntries - 1 - entryIndex); + entry = new NumberEdit(entryColumn, bytesPerEntry, this); entry->setNaturalWidthInChars(naturalWidthInChars); connect(entry, &NumberEdit::textEdited, this, slot); entry->installEventFilter(this); @@ -441,7 +442,7 @@ template void DialogEditSimdRegister::onIntegerEdited(QObject *sender, const std::array &elements) { const auto changedElementEdit = qobject_cast(sender); std::size_t elementIndex = std::find(elements.begin(), elements.end(), changedElementEdit) - elements.begin(); - Integer value = readInteger(elements[elementIndex]); + Integer value = static_cast(readInteger(elements[elementIndex])); std::memcpy(&value_[elementIndex * sizeof(value)], &value, sizeof(value)); updateAllEntriesExcept(elements[elementIndex]); } diff --git a/plugins/ODbgRegisterView/GprEdit.cpp b/plugins/ODbgRegisterView/GprEdit.cpp index c66cdbac9..cba5f0661 100644 --- a/plugins/ODbgRegisterView/GprEdit.cpp +++ b/plugins/ODbgRegisterView/GprEdit.cpp @@ -29,19 +29,19 @@ const QULongValidator wordUnsignedValidator(0, UINT16_MAX); const QULongValidator dwordUnsignedValidator(0, UINT32_MAX); const QULongValidator qwordUnsignedValidator(0, UINT64_MAX); -const std::map hexValidators = { +const std::map hexValidators = { {1, &byteHexValidator}, {2, &wordHexValidator}, {4, &dwordHexValidator}, {8, &qwordHexValidator}}; -const std::map signedValidators = { +const std::map signedValidators = { {1, &byteSignedValidator}, {2, &wordSignedValidator}, {4, &dwordSignedValidator}, {8, &qwordSignedValidator}}; -const std::map unsignedValidators = { +const std::map unsignedValidators = { {1, &byteUnsignedValidator}, {2, &wordUnsignedValidator}, {4, &dwordUnsignedValidator}, @@ -54,15 +54,15 @@ void GprEdit::setupFormat(Format newFormat) { switch (format_) { case Format::Hex: setValidator(hexValidators.at(integerSize_)); - naturalWidthInChars_ = 2 * integerSize_; + naturalWidthInChars_ = static_cast(2 * integerSize_); break; case Format::Signed: setValidator(signedValidators.at(integerSize_)); - naturalWidthInChars_ = 1 + std::lround(integerSize_ * std::log10(256.)); + naturalWidthInChars_ = static_cast(1 + std::lround(static_cast(integerSize_) * std::log10(256.0))); break; case Format::Unsigned: setValidator(unsignedValidators.at(integerSize_)); - naturalWidthInChars_ = std::lround(integerSize_ * std::log10(256.)); + naturalWidthInChars_ = static_cast(std::lround(static_cast(integerSize_) * std::log10(256.0))); break; case Format::Character: setMaxLength(1); @@ -73,7 +73,7 @@ void GprEdit::setupFormat(Format newFormat) { } GprEdit::GprEdit(std::size_t offsetInInteger, std::size_t integerSize, Format format, QWidget *parent) - : QLineEdit(parent), naturalWidthInChars_(2 * integerSize), integerSize_(integerSize), offsetInInteger_(offsetInInteger) { + : QLineEdit(parent), naturalWidthInChars_(static_cast(2 * integerSize)), integerSize_(integerSize), offsetInInteger_(offsetInInteger) { setupFormat(format); } diff --git a/plugins/ODbgRegisterView/MultiBitFieldWidget.cpp b/plugins/ODbgRegisterView/MultiBitFieldWidget.cpp index 0538c7788..bffb736e3 100644 --- a/plugins/ODbgRegisterView/MultiBitFieldWidget.cpp +++ b/plugins/ODbgRegisterView/MultiBitFieldWidget.cpp @@ -21,7 +21,7 @@ MultiBitFieldWidget::MultiBitFieldWidget(const QModelIndex &index, const BitFiel const auto &text = bfd.setValueTexts[i]; if (!text.isEmpty()) { auto action = new_action(text, this, [this, i]() { - setValue(i); + setValue(static_cast(i)); }); menuItems_.push_front(action); @@ -70,7 +70,7 @@ void MultiBitFieldWidget::adjustToData() { if (!action) { continue; } - if (byteArr.isEmpty() || equal_(word, value)) { + if (byteArr.isEmpty() || equal_(static_cast(word), value)) { action->setVisible(false); } else { action->setVisible(true); diff --git a/plugins/ODbgRegisterView/Plugin.cpp b/plugins/ODbgRegisterView/Plugin.cpp index bb5b7ea9f..71f0d4667 100644 --- a/plugins/ODbgRegisterView/Plugin.cpp +++ b/plugins/ODbgRegisterView/Plugin.cpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace ODbgRegisterView { // Q_DECLARE_NAMESPACE_TR(ODbgRegisterView) @@ -54,7 +55,7 @@ void Plugin::setupDocks() { void Plugin::saveSettings() const { QSettings settings; - const int size = registerViews_.size(); + const int size = static_cast(std::min(registerViews_.size(), static_cast(std::numeric_limits::max()))); const auto arrayKey = pluginName + "/" + views; settings.remove(arrayKey); settings.beginWriteArray(arrayKey, size); diff --git a/plugins/ODbgRegisterView/ValueField.cpp b/plugins/ODbgRegisterView/ValueField.cpp index 7b4022fe6..95a550f5f 100644 --- a/plugins/ODbgRegisterView/ValueField.cpp +++ b/plugins/ODbgRegisterView/ValueField.cpp @@ -466,13 +466,13 @@ void ValueField::invert() { } void ValueField::setZero() { - change_gpr(index_, model(), [](int) { + change_gpr(index_, model(), [](std::uint64_t) { return 0; }); } void ValueField::setToOne() { - change_gpr(index_, model(), [](int) { + change_gpr(index_, model(), [](std::uint64_t) { return 1; }); } diff --git a/plugins/ProcessProperties/DialogProcessProperties.cpp b/plugins/ProcessProperties/DialogProcessProperties.cpp index b84b8d168..e423f95e0 100644 --- a/plugins/ProcessProperties/DialogProcessProperties.cpp +++ b/plugins/ProcessProperties/DialogProcessProperties.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) #include @@ -117,13 +118,19 @@ bool tcp_socket_processor(QString *symlink, int sock, const QStringList &lst) { bool ok; const uint32_t local_address = ntohl(lst[1].toUInt(&ok, 16)); if (ok) { - const uint16_t local_port = lst[2].toUInt(&ok, 16); + const uint local_port_value = lst[2].toUInt(&ok, 16); + ok = ok && local_port_value <= std::numeric_limits::max(); + const uint16_t local_port = static_cast(local_port_value); if (ok) { const uint32_t remote_address = ntohl(lst[3].toUInt(&ok, 16)); if (ok) { - const uint16_t remote_port = lst[4].toUInt(&ok, 16); + const uint remote_port_value = lst[4].toUInt(&ok, 16); + ok = ok && remote_port_value <= std::numeric_limits::max(); + const uint16_t remote_port = static_cast(remote_port_value); if (ok) { - const uint8_t state = lst[5].toUInt(&ok, 16); + const uint state_value = lst[5].toUInt(&ok, 16); + ok = ok && state_value <= std::numeric_limits::max(); + const uint8_t state = static_cast(state_value); Q_UNUSED(state) if (ok) { const int inode = lst[13].toUInt(&ok, 10); @@ -162,13 +169,19 @@ bool udp_socket_processor(QString *symlink, int sock, const QStringList &lst) { bool ok; const uint32_t local_address = ntohl(lst[1].toUInt(&ok, 16)); if (ok) { - const uint16_t local_port = lst[2].toUInt(&ok, 16); + const uint local_port_value = lst[2].toUInt(&ok, 16); + ok = ok && local_port_value <= std::numeric_limits::max(); + const uint16_t local_port = static_cast(local_port_value); if (ok) { const uint32_t remote_address = ntohl(lst[3].toUInt(&ok, 16)); if (ok) { - const uint16_t remote_port = lst[4].toUInt(&ok, 16); + const uint remote_port_value = lst[4].toUInt(&ok, 16); + ok = ok && remote_port_value <= std::numeric_limits::max(); + const uint16_t remote_port = static_cast(remote_port_value); if (ok) { - const uint8_t state = lst[5].toUInt(&ok, 16); + const uint state_value = lst[5].toUInt(&ok, 16); + ok = ok && state_value <= std::numeric_limits::max(); + const uint8_t state = static_cast(state_value); Q_UNUSED(state) if (ok) { const int inode = lst[13].toUInt(&ok, 10); diff --git a/src/BinaryString.cpp b/src/BinaryString.cpp index 8cbd846f2..59ba784a7 100644 --- a/src/BinaryString.cpp +++ b/src/BinaryString.cpp @@ -138,12 +138,12 @@ void BinaryString::on_txtUTF16_textEdited(const QString &text) { const uint16_t ch = i.unicode(); #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN - textAscii += ch & 0xff; - textAscii += (ch >> 8) & 0xff; + textAscii += static_cast(ch & 0xff); + textAscii += static_cast((ch >> 8) & 0xff); textHex += QString::asprintf("%02x %02x ", ch & 0xff, (ch >> 8) & 0xff); #else - textAscii += (ch >> 8) & 0xff; - textAscii += ch & 0xff; + textAscii += static_cast((ch >> 8) & 0xff); + textAscii += static_cast(ch & 0xff); textHex += QString::asprintf("%02x %02x ", (ch >> 8) & 0xff, ch & 0xff); #endif } diff --git a/src/SymbolManager.cpp b/src/SymbolManager.cpp index 8007c8b7f..cb316724f 100644 --- a/src/SymbolManager.cpp +++ b/src/SymbolManager.cpp @@ -220,7 +220,7 @@ bool SymbolManager::processSymbolFile(const QString &f, edb::address_t base, con sym->name_no_prefix = QString::fromStdString(sym_name).trimmed(); sym->name = QStringLiteral("%1!%2").arg(prefix, sym->name_no_prefix); sym->address = sym_start; - sym->size = sym_end; + sym->size = static_cast(sym_end - sym_start); sym->type = sym_type; // fixup the base address based on where it is loaded diff --git a/src/arch/x86-generic/ArchProcessor.cpp b/src/arch/x86-generic/ArchProcessor.cpp index 786dcf77b..56f758108 100644 --- a/src/arch/x86-generic/ArchProcessor.cpp +++ b/src/arch/x86-generic/ArchProcessor.cpp @@ -41,16 +41,16 @@ namespace ILP32 { constexpr std::int32_t toInt(std::uint64_t x) { - return x; + return static_cast(x); } constexpr std::uint32_t toUInt(std::uint64_t x) { - return x; + return static_cast(x); } constexpr std::int32_t toLong(std::uint64_t x) { - return x; + return static_cast(x); } constexpr std::uint32_t toULong(std::uint64_t x) { - return x; + return static_cast(x); } } @@ -58,16 +58,16 @@ constexpr std::uint32_t toULong(std::uint64_t x) { namespace LP64 { constexpr std::int32_t toInt(std::uint64_t x) { - return x; + return static_cast(x); } constexpr std::uint32_t toUInt(std::uint64_t x) { - return x; + return static_cast(x); } constexpr std::int64_t toLong(std::uint64_t x) { - return x; + return static_cast(x); } constexpr std::uint64_t toULong(std::uint64_t x) { - return x; + return static_cast(x); } } diff --git a/src/edb.cpp b/src/edb.cpp index 4696ff67f..1886bf24e 100644 --- a/src/edb.cpp +++ b/src/edb.cpp @@ -43,7 +43,10 @@ #include #include +#include #include +#include +#include IDebugger *edb::v1::debugger_core = nullptr; QWidget *edb::v1::debugger_ui = nullptr; @@ -75,7 +78,7 @@ bool function_symbol_base(edb::address_t address, QString *value, int *offset) { if (const std::shared_ptr s = edb::v1::symbol_manager().findNearSymbol(address)) { *value = s->name; - *offset = address - s->address; + *offset = static_cast(std::min(address - s->address, std::numeric_limits::max())); return true; } @@ -814,8 +817,9 @@ bool get_instruction_bytes(address_t address, uint8_t *buf, int *size) { Q_ASSERT(*size >= 0); if (IProcess *process = edb::v1::debugger_core->process()) { - *size = process->readBytes(address, buf, *size); - if (*size) { + const size_t bytes_read = process->readBytes(address, buf, static_cast(*size)); + *size = static_cast(std::min(bytes_read, static_cast(std::numeric_limits::max()))); + if (*size != 0) { return true; } } @@ -996,7 +1000,7 @@ std::shared_ptr primary_code_region() { //------------------------------------------------------------------------------ void pop_value(State *state) { Q_ASSERT(state); - state->adjustStack(pointer_size()); + state->adjustStack(static_cast(pointer_size())); } //------------------------------------------------------------------------------ @@ -1112,8 +1116,15 @@ QByteArray get_md5(const QVector &bytes) { // Desc: //------------------------------------------------------------------------------ QByteArray get_md5(const void *p, size_t n) { - auto b = QByteArray::fromRawData(reinterpret_cast(p), n); - return QCryptographicHash::hash(b, QCryptographicHash::Md5); + QCryptographicHash hasher(QCryptographicHash::Md5); + const char *data = reinterpret_cast(p); + while (n != 0) { + const int chunk_size = static_cast(std::min(n, static_cast(std::numeric_limits::max()))); + hasher.addData(data, chunk_size); + data += chunk_size; + n -= static_cast(chunk_size); + } + return hasher.result(); } //------------------------------------------------------------------------------ @@ -1150,7 +1161,7 @@ QString symlink_target(const QString &s) { //------------------------------------------------------------------------------ quint32 int_version(const QString &s) { - ulong ret = 0; + quint32 ret = 0; const QStringList list = s.split("."); if (list.size() == 3) { bool ok[3]; @@ -1381,7 +1392,10 @@ QVector read_pages(address_t address, size_t page_count) { if (IProcess *process = edb::v1::debugger_core->process()) { try { const size_t page_size = debugger_core->pageSize(); - QVector pages(page_count * page_size); + if (page_size != 0 && page_count > static_cast(std::numeric_limits::max()) / page_size) { + throw std::bad_alloc(); + } + QVector pages(static_cast(page_count * page_size)); if (process->readPages(address, pages.data(), page_count)) { return pages; @@ -1524,7 +1538,7 @@ QString format_bytes(const void *buffer, size_t count) { QString bytes; if (count != 0) { - bytes.reserve(count * 4); + bytes.reserve(static_cast(count) * 4); auto it = static_cast(buffer); auto end = it + count; diff --git a/src/widgets/QDisassemblyView.cpp b/src/widgets/QDisassemblyView.cpp index 6f40e9e73..07c2f65de 100644 --- a/src/widgets/QDisassemblyView.cpp +++ b/src/widgets/QDisassemblyView.cpp @@ -717,7 +717,7 @@ int QDisassemblyView::updateDisassembly(int lines_to_render) { instructions_.clear(); showAddresses_.clear(); - int bufsize = instructionBuffer_.size(); + int bufsize = static_cast(instructionBuffer_.size()); uint8_t *inst_buf = instructionBuffer_.data(); const edb::address_t start_address = addressOffset_ + verticalScrollBar()->value(); @@ -1765,7 +1765,7 @@ int QDisassemblyView::line4() const { // Desc: //------------------------------------------------------------------------------ int QDisassemblyView::addressLength() const { - const int address_len = edb::v1::pointer_size() * CHAR_BIT / 4; + const int address_len = static_cast(edb::v1::pointer_size() * CHAR_BIT / 4); return address_len + (showAddressSeparator_ ? 1 : 0); } @@ -1819,7 +1819,7 @@ Result QDisassemblyView::getInstructionSize(edb::address_t address if (region_->end() != 0 && address + buf_size > region_->end()) { if (address <= region_->end()) { - buf_size = region_->end() - address; + buf_size = static_cast(region_->end() - address); } else { buf_size = 0; } From f4318ff6253d102ee9ff8c3150100c077113ae7f Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 00:20:14 -0400 Subject: [PATCH 02/14] working out some more warnings --- lib/libELF/include/libELF/elf_syminfo.h | 4 +- src/arch/x86-generic/ArchProcessor.cpp | 40 ++++++++------- src/arch/x86-generic/RegisterViewModel.cpp | 60 +++++++++++----------- src/arch/x86-generic/RegisterViewModel.h | 26 +++++----- src/widgets/QDisassemblyView.cpp | 18 +++---- 5 files changed, 75 insertions(+), 73 deletions(-) diff --git a/lib/libELF/include/libELF/elf_syminfo.h b/lib/libELF/include/libELF/elf_syminfo.h index 78b264770..ebc75084b 100644 --- a/lib/libELF/include/libELF/elf_syminfo.h +++ b/lib/libELF/include/libELF/elf_syminfo.h @@ -66,12 +66,12 @@ constexpr auto ELF32_ST_INFO(T1 bind, T2 type) { /* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field. */ template constexpr uint8_t ELF64_ST_BIND(T val) { - return ELF32_ST_BIND(val); + return static_cast(ELF32_ST_BIND(val)); } template constexpr uint8_t ELF64_ST_TYPE(T val) { - return ELF32_ST_TYPE(val); + return static_cast(ELF32_ST_TYPE(val)); } template diff --git a/src/arch/x86-generic/ArchProcessor.cpp b/src/arch/x86-generic/ArchProcessor.cpp index 56f758108..022ab1373 100644 --- a/src/arch/x86-generic/ArchProcessor.cpp +++ b/src/arch/x86-generic/ArchProcessor.cpp @@ -104,15 +104,15 @@ enum SegmentRegisterIndex { GS, }; -constexpr size_t MAX_DEBUG_REGS_COUNT = 8; -constexpr size_t GPR32_COUNT = 8; -constexpr size_t GPR64_COUNT = 16; -constexpr size_t SSE32_COUNT = GPR32_COUNT; -constexpr size_t SSE64_COUNT = GPR64_COUNT; -constexpr size_t AVX32_COUNT = SSE32_COUNT; -constexpr size_t AVX64_COUNT = SSE64_COUNT; -constexpr size_t MAX_FPU_REGS_COUNT = 8; -constexpr size_t MAX_MMX_REGS_COUNT = MAX_FPU_REGS_COUNT; +constexpr int MAX_DEBUG_REGS_COUNT = 8; +constexpr int GPR32_COUNT = 8; +constexpr int GPR64_COUNT = 16; +constexpr int SSE32_COUNT = GPR32_COUNT; +constexpr int SSE64_COUNT = GPR64_COUNT; +constexpr int AVX32_COUNT = SSE32_COUNT; +constexpr int AVX64_COUNT = SSE64_COUNT; +constexpr int MAX_FPU_REGS_COUNT = 8; +constexpr int MAX_MMX_REGS_COUNT = MAX_FPU_REGS_COUNT; using edb::v1::debuggeeIs32Bit; using edb::v1::debuggeeIs64Bit; @@ -180,7 +180,7 @@ QString format_integer(int pointer_level, edb::reg_t arg, QChar type) { case 'b': return arg ? "true" : "false"; case 'c': - if (arg < 0x80u && (std::isprint(arg) || std::isspace(arg))) { + if (arg < 0x80u && (std::isprint(static_cast(arg)) || std::isspace(static_cast(arg)))) { return QStringLiteral("'%1'").arg(static_cast(arg)); } else { return QStringLiteral("'\\x%1'").arg(static_cast(arg), 2, 16); @@ -971,7 +971,7 @@ RegisterViewModel &getModel() { void updateGPRs(RegisterViewModel &model, const State &state, bool is64Bit) { if (is64Bit) { - for (std::size_t i = 0; i < GPR64_COUNT; ++i) { + for (int i = 0; i < GPR64_COUNT; ++i) { const auto reg = state.gpRegister(i); if (!reg) { continue; @@ -995,7 +995,7 @@ void updateGPRs(RegisterViewModel &model, const State &state, bool is64Bit) { model.updateGPR(i, reg.value(), comment); } } else { - for (std::size_t i = 0; i < GPR32_COUNT; ++i) { + for (int i = 0; i < GPR32_COUNT; ++i) { const auto reg = state.gpRegister(i); if (!reg) { continue; @@ -1124,12 +1124,12 @@ void updateSegRegs(RegisterViewModel &model, const State &state) { comment = "(?)"; } } - model.updateSegReg(i, sregValue, comment); + model.updateSegReg(static_cast(i), sregValue, comment); } } void updateFPURegs(RegisterViewModel &model, const State &state) { - for (std::size_t i = 0; i < MAX_FPU_REGS_COUNT; ++i) { + for (int i = 0; i < MAX_FPU_REGS_COUNT; ++i) { const auto reg = state.fpuRegister(i); const auto comment = float_type(reg) == FloatValueClass::PseudoDenormal ? QObject::tr("pseudo-denormal") : ""; model.updateFPUReg(i, reg, comment); @@ -1188,7 +1188,7 @@ void updateFPURegs(RegisterViewModel &model, const State &state) { } void updateDebugRegs(RegisterViewModel &model, const State &state) { - for (std::size_t i = 0; i < MAX_DEBUG_REGS_COUNT; ++i) { + for (int i = 0; i < MAX_DEBUG_REGS_COUNT; ++i) { const edb::reg_t reg = state.debugRegister(i); if (edb::v1::debuggeeIs32Bit()) { model.updateDR(i, edb::value32(reg)); @@ -1199,7 +1199,7 @@ void updateDebugRegs(RegisterViewModel &model, const State &state) { } void updateMMXRegs(RegisterViewModel &model, const State &state) { - for (std::size_t i = 0; i < MAX_MMX_REGS_COUNT; ++i) { + for (int i = 0; i < MAX_MMX_REGS_COUNT; ++i) { const auto reg = state.archRegister(edb::string_hash("mmx"), i); if (!!reg) { @@ -1216,9 +1216,9 @@ void updateSSEAVXRegs(RegisterViewModel &model, const State &state, bool hasSSE, return; } - const std::size_t max = edb::v1::debuggeeIs32Bit() ? AVX32_COUNT : AVX64_COUNT; + const int max = edb::v1::debuggeeIs32Bit() ? AVX32_COUNT : AVX64_COUNT; - for (std::size_t i = 0; i < max; ++i) { + for (int i = 0; i < max; ++i) { if (hasAVX) { const auto reg = state.archRegister(edb::string_hash("ymm"), i); if (!reg) { @@ -1649,7 +1649,9 @@ bool ArchProcessor::isFilling(const edb::Instruction &inst) const { if (!ret) { if (edb::v1::config().zeros_are_filling) { - ret = (QByteArray::fromRawData(reinterpret_cast(inst.bytes()), inst.byteSize()) == QByteArray::fromRawData("\x00\x00", 2)); + auto lhs = QByteArray::fromRawData(reinterpret_cast(inst.bytes()), static_cast(inst.byteSize())); + auto rhs = QByteArray::fromRawData("\x00\x00", 2); + ret = (lhs == rhs); } } } else { diff --git a/src/arch/x86-generic/RegisterViewModel.cpp b/src/arch/x86-generic/RegisterViewModel.cpp index 719ff62e9..cbae6b104 100644 --- a/src/arch/x86-generic/RegisterViewModel.cpp +++ b/src/arch/x86-generic/RegisterViewModel.cpp @@ -36,13 +36,13 @@ struct Regs<64> { static constexpr char namePrefix() { return 'R'; } }; -constexpr std::size_t FPU_REG_COUNT = 8; -constexpr std::size_t MMX_REG_COUNT = FPU_REG_COUNT; -constexpr std::size_t SSE_REG_COUNT32 = 8; -constexpr std::size_t SSE_REG_COUNT64 = 16; -constexpr std::size_t AVX_REG_COUNT32 = 8; -constexpr std::size_t AVX_REG_COUNT64 = 16; -constexpr std::size_t DBG_REG_COUNT = 8; +constexpr int FPU_REG_COUNT = 8; +constexpr int MMX_REG_COUNT = FPU_REG_COUNT; +constexpr int SSE_REG_COUNT32 = 8; +constexpr int SSE_REG_COUNT64 = 16; +constexpr int AVX_REG_COUNT32 = 8; +constexpr int AVX_REG_COUNT64 = 16; +constexpr int DBG_REG_COUNT = 8; enum { RIP_ROW, @@ -263,7 +263,7 @@ void addSegRegs(RegisterViewModelBase::Category *cat) { template void addFPURegs(RegisterViewModelBase::Category *fpuRegs) { - for (std::size_t i = 0; i < FPU_REG_COUNT; ++i) { + for (int i = 0; i < FPU_REG_COUNT; ++i) { fpuRegs->addRegister(std::make_unique(QStringLiteral("R%1").arg(i))); } fpuRegs->addRegister(std::make_unique("FCR", FCRDescription)); @@ -280,7 +280,7 @@ void addFPURegs(RegisterViewModelBase::Category *fpuRegs) { template void addDebugRegs(RegisterViewModelBase::Category *dbgRegs) { using Rs = Regs; - for (std::size_t i = 0; i < 4; ++i) { + for (int i = 0; i < 4; ++i) { dbgRegs->addRegister(std::make_unique(QStringLiteral("DR%1").arg(i))); } @@ -304,13 +304,13 @@ const std::vector SSEAVXFormats = { void addMMXRegs(RegisterViewModelBase::SIMDCategory *mmxRegs) { using namespace RegisterViewModelBase; // TODO: MMXReg should have possibility to be shown in byte/word/dword signed/unsigned/hex formats - for (std::size_t i = 0; i < MMX_REG_COUNT; ++i) { + for (int i = 0; i < MMX_REG_COUNT; ++i) { mmxRegs->addRegister(std::make_unique(QStringLiteral("MM%1").arg(i), MMXFormats)); } } void addSSERegs(RegisterViewModelBase::SIMDCategory *sseRegs, unsigned regCount) { - for (std::size_t i = 0; i < regCount; ++i) { + for (int i = 0; i < regCount; ++i) { sseRegs->addRegister(std::make_unique(QStringLiteral("XMM%1").arg(i), SSEAVXFormats)); } @@ -318,7 +318,7 @@ void addSSERegs(RegisterViewModelBase::SIMDCategory *sseRegs, unsigned regCount) } void addAVXRegs(RegisterViewModelBase::SIMDCategory *avxRegs, unsigned regCount) { - for (std::size_t i = 0; i < regCount; ++i) { + for (int i = 0; i < regCount; ++i) { avxRegs->addRegister(std::make_unique(QStringLiteral("YMM%1").arg(i), SSEAVXFormats)); } avxRegs->addRegister(std::make_unique("MXCSR", MXCSRDescription)); @@ -426,12 +426,12 @@ void updateRegister(RegisterViewModelBase::Category *cat, int row, ValueType val static_cast(reg)->update(value, comment); } -void RegisterViewModel::updateGPR(std::size_t i, edb::value32 val, const QString &comment) { +void RegisterViewModel::updateGPR(int i, edb::value32 val, const QString &comment) { Q_ASSERT(int(i) < gprs32->childCount()); updateRegister(gprs32, static_cast(i), val, comment); } -void RegisterViewModel::updateGPR(std::size_t i, edb::value64 val, const QString &comment) { +void RegisterViewModel::updateGPR(int i, edb::value64 val, const QString &comment) { Q_ASSERT(int(i) < gprs64->childCount()); updateRegister(gprs64, static_cast(i), val, comment); } @@ -452,7 +452,7 @@ void RegisterViewModel::updateFlags(edb::value32 value, const QString &comment) updateRegister(genStatusRegs32, EFLAGS_ROW, value, comment); } -void RegisterViewModel::updateSegReg(std::size_t i, edb::value16 value, const QString &comment) { +void RegisterViewModel::updateSegReg(int i, edb::value16 value, const QString &comment) { updateRegister(segRegs, i, value, comment); } @@ -467,7 +467,7 @@ RegisterViewModelBase::FPUCategory *RegisterViewModel::getFPUcat() const { } } -void RegisterViewModel::updateFPUReg(std::size_t i, edb::value80 value, const QString &comment) { +void RegisterViewModel::updateFPUReg(int i, edb::value80 value, const QString &comment) { const auto cat = getFPUcat(); Q_ASSERT(int(i) < cat->childCount()); updateRegister(cat, static_cast(i), value, comment); @@ -537,7 +537,7 @@ void RegisterViewModel::updateFDS(edb::value16 value, const QString &comment) { updateRegister(getFPUcat(), FDS_ROW, value, comment, "FDS"); } -void RegisterViewModel::updateDR(std::size_t i, edb::value32 value, const QString &comment) { +void RegisterViewModel::updateDR(int i, edb::value32 value, const QString &comment) { Q_ASSERT(i < DBG_REG_COUNT); if (i < 4) { updateRegister(dbgRegs32, i, value, comment); @@ -545,7 +545,7 @@ void RegisterViewModel::updateDR(std::size_t i, edb::value32 value, const QStrin updateRegister(dbgRegs32, i - 2, value, comment); } } -void RegisterViewModel::updateDR(std::size_t i, edb::value64 value, const QString &comment) { +void RegisterViewModel::updateDR(int i, edb::value64 value, const QString &comment) { Q_ASSERT(i < DBG_REG_COUNT); if (i < 4) { updateRegister(dbgRegs64, i, value, comment); @@ -554,14 +554,14 @@ void RegisterViewModel::updateDR(std::size_t i, edb::value64 value, const QStrin } } -void RegisterViewModel::updateMMXReg(std::size_t i, edb::value64 value, const QString &comment) { +void RegisterViewModel::updateMMXReg(int i, edb::value64 value, const QString &comment) { Q_ASSERT(i < MMX_REG_COUNT); if (!mmxRegs->childCount()) { return; } updateRegister(mmxRegs, static_cast(i), value, comment); } -void RegisterViewModel::invalidateMMXReg(std::size_t i) { +void RegisterViewModel::invalidateMMXReg(int i) { Q_ASSERT(i < MMX_REG_COUNT); if (!mmxRegs->childCount()) { return; @@ -571,11 +571,11 @@ void RegisterViewModel::invalidateMMXReg(std::size_t i) { std::tuple + int /*maxRegs*/> RegisterViewModel::getSSEparams() const { RegisterViewModelBase::Category *sseCat = nullptr; RegisterViewModelBase::Category *avxCat = nullptr; - unsigned sseRegMax = 0; + int sseRegMax = 0; switch (mode) { case CpuMode::IA32: sseRegMax = SSE_REG_COUNT32; @@ -593,10 +593,10 @@ RegisterViewModel::getSSEparams() const { return std::make_tuple(sseCat, avxCat, sseRegMax); } -void RegisterViewModel::updateSSEReg(std::size_t i, edb::value128 value, const QString &comment) { +void RegisterViewModel::updateSSEReg(int i, edb::value128 value, const QString &comment) { RegisterViewModelBase::Category *sseCat; RegisterViewModelBase::Category *avxCat; - unsigned sseRegMax; + int sseRegMax; std::tie(sseCat, avxCat, sseRegMax) = getSSEparams(); Q_ASSERT(i < sseRegMax); if (!sseCat->childCount()) { @@ -608,10 +608,10 @@ void RegisterViewModel::updateSSEReg(std::size_t i, edb::value128 value, const Q invalidate(avxCat, i); } } -void RegisterViewModel::invalidateSSEReg(std::size_t i) { +void RegisterViewModel::invalidateSSEReg(int i) { RegisterViewModelBase::Category *sseCat; RegisterViewModelBase::Category *avxCat; - std::size_t sseRegMax; + int sseRegMax; std::tie(sseCat, avxCat, sseRegMax) = getSSEparams(); Q_ASSERT(i < sseRegMax); @@ -626,10 +626,10 @@ void RegisterViewModel::invalidateSSEReg(std::size_t i) { } } -void RegisterViewModel::updateAVXReg(std::size_t i, edb::value256 value, const QString &comment) { +void RegisterViewModel::updateAVXReg(int i, edb::value256 value, const QString &comment) { RegisterViewModelBase::Category *sseCat; RegisterViewModelBase::Category *avxCat; - unsigned avxRegMax; + int avxRegMax; std::tie(sseCat, avxCat, avxRegMax) = getSSEparams(); if (i >= avxRegMax) { qWarning() << Q_FUNC_INFO << ": i>AVXmax"; @@ -640,10 +640,10 @@ void RegisterViewModel::updateAVXReg(std::size_t i, edb::value256 value, const Q // update actual registers updateRegister(avxCat, static_cast(i), value, comment); } -void RegisterViewModel::invalidateAVXReg(std::size_t i) { +void RegisterViewModel::invalidateAVXReg(int i) { RegisterViewModelBase::Category *sseCat; RegisterViewModelBase::Category *avxCat; - std::size_t avxRegMax; + int avxRegMax; std::tie(sseCat, avxCat, avxRegMax) = getSSEparams(); Q_ASSERT(i < avxRegMax); // invalidate aliases diff --git a/src/arch/x86-generic/RegisterViewModel.h b/src/arch/x86-generic/RegisterViewModel.h index f90ee19e7..fa6e8abfe 100644 --- a/src/arch/x86-generic/RegisterViewModel.h +++ b/src/arch/x86-generic/RegisterViewModel.h @@ -52,14 +52,14 @@ class RegisterViewModel : public RegisterViewModelBase::Model { // NOTE: all these functions only change data, they don't emit dataChanged! // Use dataUpdateFinished() to have dataChanged emitted. - void updateGPR(std::size_t i, edb::value32 val, const QString &comment = QString()); - void updateGPR(std::size_t i, edb::value64 val, const QString &comment = QString()); + void updateGPR(int i, edb::value32 val, const QString &comment = QString()); + void updateGPR(int i, edb::value64 val, const QString &comment = QString()); void updateIP(edb::value32, const QString &comment = QString()); void updateIP(edb::value64, const QString &comment = QString()); void updateFlags(edb::value32, const QString &comment = QString()); void updateFlags(edb::value64, const QString &comment = QString()); - void updateSegReg(std::size_t i, edb::value16, const QString &comment = QString()); - void updateFPUReg(std::size_t i, edb::value80, const QString &comment = QString()); + void updateSegReg(int i, edb::value16, const QString &comment = QString()); + void updateFPUReg(int i, edb::value80, const QString &comment = QString()); void updateFCR(edb::value16, const QString &comment = QString()); void updateFSR(edb::value16, const QString &comment = QString()); void updateFTR(edb::value16, const QString &comment = QString()); @@ -75,14 +75,14 @@ class RegisterViewModel : public RegisterViewModelBase::Model { void updateFIS(edb::value16, const QString &comment = QString()); void updateFDS(edb::value16, const QString &comment = QString()); void updateFOP(edb::value16, const QString &comment = QString()); - void updateDR(std::size_t i, edb::value32, const QString &comment = QString()); - void updateDR(std::size_t i, edb::value64, const QString &comment = QString()); - void updateMMXReg(std::size_t i, edb::value64, const QString &comment = QString()); - void invalidateMMXReg(std::size_t i); - void updateSSEReg(std::size_t i, edb::value128, const QString &comment = QString()); - void invalidateSSEReg(std::size_t i); - void updateAVXReg(std::size_t i, edb::value256, const QString &comment = QString()); - void invalidateAVXReg(std::size_t i); + void updateDR(int i, edb::value32, const QString &comment = QString()); + void updateDR(int i, edb::value64, const QString &comment = QString()); + void updateMMXReg(int i, edb::value64, const QString &comment = QString()); + void invalidateMMXReg(int i); + void updateSSEReg(int i, edb::value128, const QString &comment = QString()); + void invalidateSSEReg(int i); + void updateAVXReg(int i, edb::value256, const QString &comment = QString()); + void invalidateAVXReg(int i); void updateMXCSR(edb::value32, const QString &comment = QString()); void invalidateMXCSR(); @@ -93,7 +93,7 @@ class RegisterViewModel : public RegisterViewModelBase::Model { void show32BitModeCategories(); void hideGenericCategories(); void showGenericCategories(); - [[nodiscard]] std::tuple getSSEparams() const; + [[nodiscard]] std::tuple getSSEparams() const; [[nodiscard]] RegisterViewModelBase::FPUCategory *getFPUcat() const; private: diff --git a/src/widgets/QDisassemblyView.cpp b/src/widgets/QDisassemblyView.cpp index 07c2f65de..189bf7ed5 100644 --- a/src/widgets/QDisassemblyView.cpp +++ b/src/widgets/QDisassemblyView.cpp @@ -103,7 +103,7 @@ bool near_line(int x, int linex) { //------------------------------------------------------------------------------ int instruction_size(const uint8_t *buffer, std::size_t size) { edb::Instruction inst(buffer, buffer + size, 0); - return inst.byteSize(); + return static_cast(inst.byteSize()); } //------------------------------------------------------------------------------ @@ -111,7 +111,7 @@ int instruction_size(const uint8_t *buffer, std::size_t size) { // Desc: //------------------------------------------------------------------------------ QString format_instruction_bytes(const edb::Instruction &inst) { - auto bytes = QByteArray::fromRawData(reinterpret_cast(inst.bytes()), inst.byteSize()); + auto bytes = QByteArray::fromRawData(reinterpret_cast(inst.bytes()), static_cast(inst.byteSize())); return edb::v1::format_bytes(bytes); } @@ -189,7 +189,7 @@ void QDisassemblyView::keyPressEvent(QKeyEvent *event) { if (selected != 0 && idx > 0 && idx < showAddresses_.size() - 1 - partialLastLine_) { setSelectedAddress(showAddresses_[idx + 1]); } else { - const int current_offset = selected - addressOffset_; + const auto current_offset = static_cast(selected - addressOffset_); if (current_offset + 1 >= static_cast(region_->size())) { return; } @@ -208,7 +208,7 @@ void QDisassemblyView::keyPressEvent(QKeyEvent *event) { // we already know the previous instruction setSelectedAddress(showAddresses_[idx - 1]); } else { - const int current_offset = selected - addressOffset_; + const auto current_offset = static_cast(selected - addressOffset_); if (current_offset <= 0) { return; } @@ -226,7 +226,7 @@ void QDisassemblyView::keyPressEvent(QKeyEvent *event) { } else { scrollbarActionTriggered(QAbstractSlider::SliderPageStepSub); } - updateDisassembly(instructions_.size()); + updateDisassembly(static_cast(instructions_.size())); if (showAddresses_.size() > selectedLine) { setSelectedAddress(showAddresses_[selectedLine]); @@ -303,7 +303,7 @@ int QDisassemblyView::previousInstruction(IAnalyzer *analyzer, int current_addre } } - current_address = (function_start - addressOffset_); + current_address = static_cast(function_start - addressOffset_); return current_address; } } @@ -363,7 +363,7 @@ int QDisassemblyView::followingInstruction(int current_address) const { } const edb::Instruction inst(buf, buf + buf_size, current_address); - return current_address + inst.byteSize(); + return static_cast(current_address + inst.byteSize()); } //------------------------------------------------------------------------------ @@ -547,7 +547,7 @@ void QDisassemblyView::setAddressOffset(edb::address_t address) { // Desc: //------------------------------------------------------------------------------ void QDisassemblyView::scrollTo(edb::address_t address) { - verticalScrollBar()->setValue(address - addressOffset_); + verticalScrollBar()->setValue(static_cast(address - addressOffset_)); } //------------------------------------------------------------------------------ @@ -1681,7 +1681,7 @@ int QDisassemblyView::lineHeight() const { //------------------------------------------------------------------------------ void QDisassemblyView::updateScrollbars() { if (region_) { - const int total_lines = region_->size(); + const auto total_lines = static_cast(region_->size()); const int viewable_lines = viewport()->height() / lineHeight(); const int scroll_max = (total_lines > viewable_lines) ? total_lines - 1 : 0; From c3c8571869ed10aa3bde2b4aba746769e7af7fc9 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 00:24:47 -0400 Subject: [PATCH 03/14] more warning squashing... --- src/arch/x86-generic/RegisterViewModel.cpp | 18 ++++++++-------- src/edb.cpp | 24 +++++----------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/arch/x86-generic/RegisterViewModel.cpp b/src/arch/x86-generic/RegisterViewModel.cpp index cbae6b104..63a654e2d 100644 --- a/src/arch/x86-generic/RegisterViewModel.cpp +++ b/src/arch/x86-generic/RegisterViewModel.cpp @@ -309,7 +309,7 @@ void addMMXRegs(RegisterViewModelBase::SIMDCategory *mmxRegs) { } } -void addSSERegs(RegisterViewModelBase::SIMDCategory *sseRegs, unsigned regCount) { +void addSSERegs(RegisterViewModelBase::SIMDCategory *sseRegs, int regCount) { for (int i = 0; i < regCount; ++i) { sseRegs->addRegister(std::make_unique(QStringLiteral("XMM%1").arg(i), SSEAVXFormats)); } @@ -317,7 +317,7 @@ void addSSERegs(RegisterViewModelBase::SIMDCategory *sseRegs, unsigned regCount) sseRegs->addRegister(std::make_unique("MXCSR", MXCSRDescription)); } -void addAVXRegs(RegisterViewModelBase::SIMDCategory *avxRegs, unsigned regCount) { +void addAVXRegs(RegisterViewModelBase::SIMDCategory *avxRegs, int regCount) { for (int i = 0; i < regCount; ++i) { avxRegs->addRegister(std::make_unique(QStringLiteral("YMM%1").arg(i), SSEAVXFormats)); } @@ -428,12 +428,12 @@ void updateRegister(RegisterViewModelBase::Category *cat, int row, ValueType val void RegisterViewModel::updateGPR(int i, edb::value32 val, const QString &comment) { Q_ASSERT(int(i) < gprs32->childCount()); - updateRegister(gprs32, static_cast(i), val, comment); + updateRegister(gprs32, i, val, comment); } void RegisterViewModel::updateGPR(int i, edb::value64 val, const QString &comment) { Q_ASSERT(int(i) < gprs64->childCount()); - updateRegister(gprs64, static_cast(i), val, comment); + updateRegister(gprs64, i, val, comment); } void RegisterViewModel::updateIP(edb::value64 value, const QString &comment) { @@ -470,7 +470,7 @@ RegisterViewModelBase::FPUCategory *RegisterViewModel::getFPUcat() const { void RegisterViewModel::updateFPUReg(int i, edb::value80 value, const QString &comment) { const auto cat = getFPUcat(); Q_ASSERT(int(i) < cat->childCount()); - updateRegister(cat, static_cast(i), value, comment); + updateRegister(cat, i, value, comment); } void RegisterViewModel::updateFCR(edb::value16 value, const QString &comment) { @@ -559,7 +559,7 @@ void RegisterViewModel::updateMMXReg(int i, edb::value64 value, const QString &c if (!mmxRegs->childCount()) { return; } - updateRegister(mmxRegs, static_cast(i), value, comment); + updateRegister(mmxRegs, i, value, comment); } void RegisterViewModel::invalidateMMXReg(int i) { Q_ASSERT(i < MMX_REG_COUNT); @@ -602,7 +602,7 @@ void RegisterViewModel::updateSSEReg(int i, edb::value128 value, const QString & if (!sseCat->childCount()) { return; } - updateRegister(sseCat, static_cast(i), value, comment); + updateRegister(sseCat, i, value, comment); // To avoid showing stale data in case this is called when AVX state is supported if (avxCat->childCount()) { invalidate(avxCat, i); @@ -636,9 +636,9 @@ void RegisterViewModel::updateAVXReg(int i, edb::value256 value, const QString & return; } // update aliases - updateRegister(sseCat, static_cast(i), edb::value128(value), comment); + updateRegister(sseCat, i, edb::value128(value), comment); // update actual registers - updateRegister(avxCat, static_cast(i), value, comment); + updateRegister(avxCat, i, value, comment); } void RegisterViewModel::invalidateAVXReg(int i) { RegisterViewModelBase::Category *sseCat; diff --git a/src/edb.cpp b/src/edb.cpp index 1886bf24e..3e1356aca 100644 --- a/src/edb.cpp +++ b/src/edb.cpp @@ -43,10 +43,7 @@ #include #include -#include #include -#include -#include IDebugger *edb::v1::debugger_core = nullptr; QWidget *edb::v1::debugger_ui = nullptr; @@ -78,7 +75,7 @@ bool function_symbol_base(edb::address_t address, QString *value, int *offset) { if (const std::shared_ptr s = edb::v1::symbol_manager().findNearSymbol(address)) { *value = s->name; - *offset = static_cast(std::min(address - s->address, std::numeric_limits::max())); + *offset = static_cast(address - s->address); return true; } @@ -817,9 +814,8 @@ bool get_instruction_bytes(address_t address, uint8_t *buf, int *size) { Q_ASSERT(*size >= 0); if (IProcess *process = edb::v1::debugger_core->process()) { - const size_t bytes_read = process->readBytes(address, buf, static_cast(*size)); - *size = static_cast(std::min(bytes_read, static_cast(std::numeric_limits::max()))); - if (*size != 0) { + *size = static_cast(process->readBytes(address, buf, static_cast(*size))); + if (*size) { return true; } } @@ -1116,15 +1112,8 @@ QByteArray get_md5(const QVector &bytes) { // Desc: //------------------------------------------------------------------------------ QByteArray get_md5(const void *p, size_t n) { - QCryptographicHash hasher(QCryptographicHash::Md5); - const char *data = reinterpret_cast(p); - while (n != 0) { - const int chunk_size = static_cast(std::min(n, static_cast(std::numeric_limits::max()))); - hasher.addData(data, chunk_size); - data += chunk_size; - n -= static_cast(chunk_size); - } - return hasher.result(); + auto b = QByteArray::fromRawData(reinterpret_cast(p), static_cast(n)); + return QCryptographicHash::hash(b, QCryptographicHash::Md5); } //------------------------------------------------------------------------------ @@ -1392,9 +1381,6 @@ QVector read_pages(address_t address, size_t page_count) { if (IProcess *process = edb::v1::debugger_core->process()) { try { const size_t page_size = debugger_core->pageSize(); - if (page_size != 0 && page_count > static_cast(std::numeric_limits::max()) / page_size) { - throw std::bad_alloc(); - } QVector pages(static_cast(page_count * page_size)); if (process->readPages(address, pages.data(), page_count)) { From 174a33c4cf4e25172d6fadd35b0c4e66b1f723c4 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 00:43:01 -0400 Subject: [PATCH 04/14] squashing almost all of them now! --- plugins/BinaryInfo/symbols.cpp | 2 +- plugins/CheckVersion/CheckVersion.cpp | 4 ++- .../DialogEditSimdRegister.cpp | 10 +++--- src/BinaryString.cpp | 2 +- src/Debugger.cpp | 4 +-- src/FloatX.cpp | 8 ++--- src/Register.cpp | 2 +- src/RegisterViewModelBase.cpp | 32 +++++++++---------- 8 files changed, 33 insertions(+), 31 deletions(-) diff --git a/plugins/BinaryInfo/symbols.cpp b/plugins/BinaryInfo/symbols.cpp index ea8320c80..3ef51e6fb 100644 --- a/plugins/BinaryInfo/symbols.cpp +++ b/plugins/BinaryInfo/symbols.cpp @@ -241,7 +241,7 @@ void collect_symbols(const void *p, Size size, std::vector & auto symbol_tab = reinterpret_cast(base + linked->sh_offset); auto string_tab = reinterpret_cast(base + sections_begin[linked->sh_link].sh_offset); - const elf_addr symbol_address = static_cast(base_address + (n * M::plt_entry_size)); + const auto symbol_address = static_cast(base_address + (n * M::plt_entry_size)); const char *sym_name = §ion_strings[section->sh_name]; if (strlen(sym_name) > (sizeof(".rela.") - 1) && memcmp(sym_name, ".rela.", (sizeof(".rela.") - 1)) == 0) { diff --git a/plugins/CheckVersion/CheckVersion.cpp b/plugins/CheckVersion/CheckVersion.cpp index eeb6216be..4d870da1a 100644 --- a/plugins/CheckVersion/CheckVersion.cpp +++ b/plugins/CheckVersion/CheckVersion.cpp @@ -100,8 +100,10 @@ void CheckVersion::setProxy(const QUrl &url) { if (!proxy_str.isEmpty()) { const QUrl proxy_url = QUrl::fromUserInput(proxy_str); + const int port = proxy_url.port(80); + const auto qport = static_cast(qBound(0, port, 65535)); - proxy = QNetworkProxy(QNetworkProxy::HttpProxy, proxy_url.host(), proxy_url.port(80), proxy_url.userName(), proxy_url.password()); + proxy = QNetworkProxy(QNetworkProxy::HttpProxy, proxy_url.host(), qport, proxy_url.userName(), proxy_url.password()); } #else diff --git a/plugins/ODbgRegisterView/DialogEditSimdRegister.cpp b/plugins/ODbgRegisterView/DialogEditSimdRegister.cpp index 7b421b486..e90548bd1 100644 --- a/plugins/ODbgRegisterView/DialogEditSimdRegister.cpp +++ b/plugins/ODbgRegisterView/DialogEditSimdRegister.cpp @@ -35,10 +35,10 @@ void DialogEditSimdRegister::setupEntries(const QString &label, std::arrayaddWidget(new QLabel(label, this), row, ENTRIES_FIRST_COL - 1); for (std::size_t entryIndex = 0; entryIndex < NumEntries; ++entryIndex) { - auto &entry = entries[entryIndex]; - const int bytesPerEntry = static_cast(NumBytes / NumEntries); - const int entryColumn = ENTRIES_FIRST_COL + bytesPerEntry * static_cast(NumEntries - 1 - entryIndex); - entry = new NumberEdit(entryColumn, bytesPerEntry, this); + auto &entry = entries[entryIndex]; + const auto bytesPerEntry = static_cast(NumBytes / NumEntries); + const int entryColumn = ENTRIES_FIRST_COL + bytesPerEntry * static_cast(NumEntries - 1 - entryIndex); + entry = new NumberEdit(entryColumn, bytesPerEntry, this); entry->setNaturalWidthInChars(naturalWidthInChars); connect(entry, &NumberEdit::textEdited, this, slot); entry->installEventFilter(this); @@ -442,7 +442,7 @@ template void DialogEditSimdRegister::onIntegerEdited(QObject *sender, const std::array &elements) { const auto changedElementEdit = qobject_cast(sender); std::size_t elementIndex = std::find(elements.begin(), elements.end(), changedElementEdit) - elements.begin(); - Integer value = static_cast(readInteger(elements[elementIndex])); + auto value = static_cast(readInteger(elements[elementIndex])); std::memcpy(&value_[elementIndex * sizeof(value)], &value, sizeof(value)); updateAllEntriesExcept(elements[elementIndex]); } diff --git a/src/BinaryString.cpp b/src/BinaryString.cpp index 59ba784a7..9c5d79e8c 100644 --- a/src/BinaryString.cpp +++ b/src/BinaryString.cpp @@ -172,7 +172,7 @@ void BinaryString::on_txtHex_textEdited(const QString &text) { for (const QString &s : list1) { - const uint8_t ch = s.toUInt(nullptr, 16); + const auto ch = static_cast(s.toUInt(nullptr, 16)); #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN utf16Char = (utf16Char >> 8) | (ch << 8); diff --git a/src/Debugger.cpp b/src/Debugger.cpp index 456e7f51b..e236018b8 100644 --- a/src/Debugger.cpp +++ b/src/Debugger.cpp @@ -1203,7 +1203,7 @@ void Debugger::showEvent(QShowEvent *) { stackView_->setShowComments(settings.value("window.stack.show_comments.enabled", true).toBool()); int row_width = 1; - int word_width = edb::v1::pointer_size(); + auto word_width = static_cast(edb::v1::pointer_size()); stackView_->setRowWidth(row_width); stackView_->setWordWidth(word_width); @@ -3132,7 +3132,7 @@ void Debugger::setupDataViews() { } // Update stack word width - stackView_->setWordWidth(edb::v1::pointer_size()); + stackView_->setWordWidth(static_cast(edb::v1::pointer_size())); } //------------------------------------------------------------------------------ diff --git a/src/FloatX.cpp b/src/FloatX.cpp index 50d4506de..814685341 100644 --- a/src/FloatX.cpp +++ b/src/FloatX.cpp @@ -203,7 +203,7 @@ const char *fixup_g_Yfmt(char *buffer, int digits10) { // If point wasn't found, assume it's at the end of the number if (pointPos < 0) { - pointPos = len; + pointPos = static_cast(len); } const int signChars = buffer[0] == '-'; @@ -219,7 +219,7 @@ const char *fixup_g_Yfmt(char *buffer, int digits10) { // The original string may contain a point, may not contain any. In the // former case we must move everything including the null terminator. In // the latter case only the chunk up to the original point needs moving. - const int lenWithNull = len + 1; + const auto lenWithNull = static_cast(len + 1); char next = buf[1]; for (int i = 0; i < lenWithNull - signChars; ++i) { @@ -244,8 +244,8 @@ const char *fixup_g_Yfmt(char *buffer, int digits10) { // Append the exponent buf[len] = 'e'; buf[len + 1] = '+'; - buf[len + 2] = exp / 10 + '0'; - buf[len + 3] = exp % 10 + '0'; + buf[len + 2] = static_cast(exp / 10 + '0'); + buf[len + 3] = static_cast(exp % 10 + '0'); buf[len + 4] = 0; } diff --git a/src/Register.cpp b/src/Register.cpp index b5f32e816..c5c81e506 100644 --- a/src/Register.cpp +++ b/src/Register.cpp @@ -40,7 +40,7 @@ QString Register::toHexString() const { return tr("(Error: bad register length %1 bits)").arg(bitSize_); } - return value_.toHexString().right(bitSize_ / 4); // TODO: trimming should be moved to valueXX::toHexString() + return value_.toHexString().right(static_cast(bitSize_ / 4)); // TODO: trimming should be moved to valueXX::toHexString() } /** diff --git a/src/RegisterViewModelBase.cpp b/src/RegisterViewModelBase.cpp index 398632457..2a1dc9369 100644 --- a/src/RegisterViewModelBase.cpp +++ b/src/RegisterViewModelBase.cpp @@ -255,7 +255,7 @@ QVariant Model::data(const QModelIndex &index, int role) const { case FixedLengthRole: if (index.column() == NAME_COLUMN) { - return item->name().size(); + return static_cast(item->name().size()); } else if (index.column() == VALUE_COLUMN) { return item->valueMaxLength(); } else { @@ -556,7 +556,7 @@ Category::Category(Category &&other) noexcept } int Category::childCount() const { - return registers.size(); + return static_cast(registers.size()); } RegisterViewItem *Category::child(int row) { @@ -596,7 +596,7 @@ bool Category::visible() const { void Category::addRegister(std::unique_ptr reg) { registers.emplace_back(std::move(reg)); - registers.back()->init(this, registers.size() - 1); + registers.back()->init(this, static_cast(registers.size() - 1)); } AbstractRegisterItem *Category::getRegister(std::size_t i) const { @@ -785,7 +785,7 @@ UnderlyingType BitFieldItem::prevValue() const { template int BitFieldItem::valueMaxLength() const { - return std::ceil(length_ / 4.); // number of nibbles + return static_cast((length_ + 3u) / 4u); // number of nibbles } template @@ -801,7 +801,7 @@ QVariant BitFieldItem::data(int column) const { return name(); case Model::VALUE_COLUMN: Q_ASSERT(str.size() > 0); - return str.right(std::ceil(length_ / 4.)); + return str.right(static_cast((length_ + 3u) / 4u)); case Model::COMMENT_COLUMN: if (explanations.empty()) { return {}; @@ -835,13 +835,13 @@ FlagsRegister::FlagsRegister(const QString &name, const std::vector< for (auto &field : bitFields) { fields.emplace_back(field); - fields.back().init(this, fields.size() - 1); + fields.back().init(this, static_cast(fields.size() - 1)); } } template int FlagsRegister::childCount() const { - return fields.size(); + return static_cast(fields.size()); } template @@ -982,13 +982,13 @@ SIMDSizedElement::SIMDSizedElement(const QString &name, for (const auto format : validFormats) { if (format != NumberDisplayMode::Float || sizeof(SizingType) >= sizeof(float)) { // The order must be as expected by other functions - Q_ASSERT(format != NumberDisplayMode::Float || formats.size() == Model::SIMD_FLOAT_ROW); - Q_ASSERT(format != NumberDisplayMode::Hex || formats.size() == Model::SIMD_HEX_ROW); - Q_ASSERT(format != NumberDisplayMode::Signed || formats.size() == Model::SIMD_SIGNED_ROW); - Q_ASSERT(format != NumberDisplayMode::Unsigned || formats.size() == Model::SIMD_UNSIGNED_ROW); + Q_ASSERT(format != NumberDisplayMode::Float || formats.size() == static_cast(Model::SIMD_FLOAT_ROW)); + Q_ASSERT(format != NumberDisplayMode::Hex || formats.size() == static_cast(Model::SIMD_HEX_ROW)); + Q_ASSERT(format != NumberDisplayMode::Signed || formats.size() == static_cast(Model::SIMD_SIGNED_ROW)); + Q_ASSERT(format != NumberDisplayMode::Unsigned || formats.size() == static_cast(Model::SIMD_UNSIGNED_ROW)); formats.emplace_back(format); - formats.back().init(this, formats.size() - 1); + formats.back().init(this, static_cast(formats.size() - 1)); } } } @@ -1000,7 +1000,7 @@ RegisterViewItem *SIMDSizedElement::child(int row) { template int SIMDSizedElement::childCount() const { - return formats.size(); + return static_cast(formats.size()); } template @@ -1113,7 +1113,7 @@ RegisterViewItem *SIMDSizedElementsContainer::child(int row) { template int SIMDSizedElementsContainer::childCount() const { - return elements.size(); + return static_cast(elements.size()); } template @@ -1179,7 +1179,7 @@ SIMDRegister::SIMDRegister(const QString &name, const std::vector int SIMDRegister::childCount() const { - return sizedElementContainers.size(); + return static_cast(sizedElementContainers.size()); } template @@ -1242,7 +1242,7 @@ void FPURegister::saveValue() { template int FPURegister::childCount() const { - return formats.size(); + return static_cast(formats.size()); } template From cef66e27fae5d00c119fd64769725582fb28e847 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 00:43:21 -0400 Subject: [PATCH 05/14] the last of them... i think --- src/widgets/QDisassemblyView.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/widgets/QDisassemblyView.cpp b/src/widgets/QDisassemblyView.cpp index 189bf7ed5..6d08f9d11 100644 --- a/src/widgets/QDisassemblyView.cpp +++ b/src/widgets/QDisassemblyView.cpp @@ -467,7 +467,7 @@ void QDisassemblyView::setShowAddressSeparator(bool value) { //------------------------------------------------------------------------------ QString QDisassemblyView::formatAddress(edb::address_t address) const { if (edb::v1::debuggeeIs32Bit()) { - return format_address(address.toUint(), showAddressSeparator_); + return format_address(static_cast(address.toUint()), showAddressSeparator_); } return format_address(address, showAddressSeparator_); } @@ -698,7 +698,7 @@ std::optional QDisassemblyView::getLineOfAddress(edb::address_t ad if (!showAddresses_.isEmpty()) { if (addr >= showAddresses_[0] && addr <= showAddresses_[showAddresses_.size() - 1]) { - int pos = std::find(showAddresses_.begin(), showAddresses_.end(), addr) - showAddresses_.begin(); + auto pos = static_cast(std::find(showAddresses_.begin(), showAddresses_.end(), addr) - showAddresses_.begin()); if (pos < showAddresses_.size()) { // address was found return pos; } @@ -717,7 +717,7 @@ int QDisassemblyView::updateDisassembly(int lines_to_render) { instructions_.clear(); showAddresses_.clear(); - int bufsize = static_cast(instructionBuffer_.size()); + auto bufsize = static_cast(instructionBuffer_.size()); uint8_t *inst_buf = instructionBuffer_.data(); const edb::address_t start_address = addressOffset_ + verticalScrollBar()->value(); @@ -744,7 +744,7 @@ int QDisassemblyView::updateDisassembly(int lines_to_render) { showAddresses_.push_back(address); if (instructions_[line].valid()) { - offset += instructions_[line].byteSize(); + offset += static_cast(instructions_[line].byteSize()); } else { ++offset; } @@ -1765,7 +1765,7 @@ int QDisassemblyView::line4() const { // Desc: //------------------------------------------------------------------------------ int QDisassemblyView::addressLength() const { - const int address_len = static_cast(edb::v1::pointer_size() * CHAR_BIT / 4); + const auto address_len = static_cast(edb::v1::pointer_size() * CHAR_BIT / 4); return address_len + (showAddressSeparator_ ? 1 : 0); } From f4af2fbab1d228482d15a328b0818c764019ad9a Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 00:50:31 -0400 Subject: [PATCH 06/14] some minor tweaks --- plugins/Backtrace/DialogBacktrace.cpp | 8 ++--- .../unix/linux/PlatformProcess.cpp | 13 +++------ plugins/HeapAnalyzer/DialogHeap.cpp | 7 ++--- plugins/ODbgRegisterView/Plugin.cpp | 3 +- .../DialogProcessProperties.cpp | 29 +++++-------------- 5 files changed, 18 insertions(+), 42 deletions(-) diff --git a/plugins/Backtrace/DialogBacktrace.cpp b/plugins/Backtrace/DialogBacktrace.cpp index ae0d8cd2b..b92d2c70a 100644 --- a/plugins/Backtrace/DialogBacktrace.cpp +++ b/plugins/Backtrace/DialogBacktrace.cpp @@ -14,7 +14,6 @@ #include #include -#include namespace BacktracePlugin { namespace { @@ -155,11 +154,10 @@ void DialogBacktrace::populateTable() { // Get the call stack and populate the table with entries. CallStack call_stack; const size_t size = call_stack.size(); - for (size_t i = 0; i < size && i <= static_cast(std::numeric_limits::max()); i++) { - const int row = static_cast(i); + for (size_t i = 0; i < size; i++) { // Create the row to insert info - table_->insertRow(row); + table_->insertRow(static_cast(i)); // Get the stack frame so that we can insert its info CallStack::StackFrame *frame = call_stack[i]; @@ -194,7 +192,7 @@ void DialogBacktrace::populateTable() { flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable; item->setFlags(flags); - table_->setItem(row, j, item); + table_->setItem(static_cast(i), j, item); } } diff --git a/plugins/DebuggerCore/unix/linux/PlatformProcess.cpp b/plugins/DebuggerCore/unix/linux/PlatformProcess.cpp index 13aee6ecd..6e9cf21e7 100644 --- a/plugins/DebuggerCore/unix/linux/PlatformProcess.cpp +++ b/plugins/DebuggerCore/unix/linux/PlatformProcess.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -233,7 +232,7 @@ bool get_program_headers(const IProcess *process, edb::address_t *phdr_memaddr, *phdr_memaddr = entry.a_un.a_val; break; case AT_PHNUM: - *num_phdr = static_cast(std::min(entry.a_un.a_val, static_cast(std::numeric_limits::max()))); + *num_phdr = entry.a_un.a_val; break; } } @@ -245,7 +244,7 @@ bool get_program_headers(const IProcess *process, edb::address_t *phdr_memaddr, *phdr_memaddr = entry.a_un.a_val; break; case AT_PHNUM: - *num_phdr = static_cast(std::min(entry.a_un.a_val, static_cast(std::numeric_limits::max()))); + *num_phdr = entry.a_un.a_val; break; } } @@ -390,12 +389,8 @@ std::size_t PlatformProcess::patchBytes(edb::address_t address, const void *buf, Patch patch; patch.address = address; - if (len > static_cast(std::numeric_limits::max())) { - return 0; - } - const int len_int = static_cast(len); - patch.origBytes.resize(len_int); - patch.newBytes = QByteArray(static_cast(buf), len_int); + patch.origBytes.resize(len); + patch.newBytes = QByteArray(static_cast(buf), len); size_t read_ret = readBytes(address, patch.origBytes.data(), len); if (read_ret != len) { diff --git a/plugins/HeapAnalyzer/DialogHeap.cpp b/plugins/HeapAnalyzer/DialogHeap.cpp index 07547d35d..a9d96efd5 100644 --- a/plugins/HeapAnalyzer/DialogHeap.cpp +++ b/plugins/HeapAnalyzer/DialogHeap.cpp @@ -34,7 +34,6 @@ #include #include #include -#include namespace HeapAnalyzerPlugin { namespace { @@ -385,13 +384,11 @@ void DialogHeap::collectBlocks(edb::address_t start_address, edb::address_t end_ QString utf16Data; int asciisz; int utf16sz; - const auto max_string_length = - static_cast(std::min(currentChunk.chunkSize(), std::numeric_limits::max())); if (edb::v1::get_ascii_string_at_address( block_start(currentChunkAddress), asciiData, min_string_length, - max_string_length, + currentChunk.chunkSize(), asciisz)) { data = asciiData; @@ -400,7 +397,7 @@ void DialogHeap::collectBlocks(edb::address_t start_address, edb::address_t end_ block_start(currentChunkAddress), utf16Data, min_string_length, - max_string_length, + currentChunk.chunkSize(), utf16sz)) { data = utf16Data; data_type = ResultViewModel::Result::Utf16; diff --git a/plugins/ODbgRegisterView/Plugin.cpp b/plugins/ODbgRegisterView/Plugin.cpp index 71f0d4667..21c5591b3 100644 --- a/plugins/ODbgRegisterView/Plugin.cpp +++ b/plugins/ODbgRegisterView/Plugin.cpp @@ -16,7 +16,6 @@ #include #include #include -#include namespace ODbgRegisterView { // Q_DECLARE_NAMESPACE_TR(ODbgRegisterView) @@ -55,7 +54,7 @@ void Plugin::setupDocks() { void Plugin::saveSettings() const { QSettings settings; - const int size = static_cast(std::min(registerViews_.size(), static_cast(std::numeric_limits::max()))); + const auto size = static_cast(registerViews_.size()); const auto arrayKey = pluginName + "/" + views; settings.remove(arrayKey); settings.beginWriteArray(arrayKey, size); diff --git a/plugins/ProcessProperties/DialogProcessProperties.cpp b/plugins/ProcessProperties/DialogProcessProperties.cpp index e423f95e0..a1cc5a5f5 100644 --- a/plugins/ProcessProperties/DialogProcessProperties.cpp +++ b/plugins/ProcessProperties/DialogProcessProperties.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) #include @@ -118,22 +117,16 @@ bool tcp_socket_processor(QString *symlink, int sock, const QStringList &lst) { bool ok; const uint32_t local_address = ntohl(lst[1].toUInt(&ok, 16)); if (ok) { - const uint local_port_value = lst[2].toUInt(&ok, 16); - ok = ok && local_port_value <= std::numeric_limits::max(); - const uint16_t local_port = static_cast(local_port_value); + const auto local_port = static_cast(lst[2].toUInt(&ok, 16)); if (ok) { const uint32_t remote_address = ntohl(lst[3].toUInt(&ok, 16)); if (ok) { - const uint remote_port_value = lst[4].toUInt(&ok, 16); - ok = ok && remote_port_value <= std::numeric_limits::max(); - const uint16_t remote_port = static_cast(remote_port_value); + const auto remote_port = static_cast(lst[4].toUInt(&ok, 16)); if (ok) { - const uint state_value = lst[5].toUInt(&ok, 16); - ok = ok && state_value <= std::numeric_limits::max(); - const uint8_t state = static_cast(state_value); + const auto state = static_cast(lst[5].toUInt(&ok, 16)); Q_UNUSED(state) if (ok) { - const int inode = lst[13].toUInt(&ok, 10); + const auto inode = static_cast(lst[13].toUInt(&ok, 10)); if (ok) { if (inode == sock) { *symlink = QStringLiteral("TCP: %1:%2 -> %3:%4") @@ -169,22 +162,16 @@ bool udp_socket_processor(QString *symlink, int sock, const QStringList &lst) { bool ok; const uint32_t local_address = ntohl(lst[1].toUInt(&ok, 16)); if (ok) { - const uint local_port_value = lst[2].toUInt(&ok, 16); - ok = ok && local_port_value <= std::numeric_limits::max(); - const uint16_t local_port = static_cast(local_port_value); + const auto local_port = static_cast(lst[2].toUInt(&ok, 16)); if (ok) { const uint32_t remote_address = ntohl(lst[3].toUInt(&ok, 16)); if (ok) { - const uint remote_port_value = lst[4].toUInt(&ok, 16); - ok = ok && remote_port_value <= std::numeric_limits::max(); - const uint16_t remote_port = static_cast(remote_port_value); + const auto remote_port = static_cast(lst[4].toUInt(&ok, 16)); if (ok) { - const uint state_value = lst[5].toUInt(&ok, 16); - ok = ok && state_value <= std::numeric_limits::max(); - const uint8_t state = static_cast(state_value); + const auto state = static_cast(lst[5].toUInt(&ok, 16)); Q_UNUSED(state) if (ok) { - const int inode = lst[13].toUInt(&ok, 10); + const auto inode = static_cast(lst[13].toUInt(&ok, 10)); if (ok) { if (inode == sock) { *symlink = QStringLiteral("UDP: %1:%2 -> %3:%4") From 32c7831e252e2b21322cbc524f097e3a11290bb7 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 00:52:27 -0400 Subject: [PATCH 07/14] a little bit more... --- plugins/DebuggerCore/unix/linux/PlatformProcess.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/DebuggerCore/unix/linux/PlatformProcess.cpp b/plugins/DebuggerCore/unix/linux/PlatformProcess.cpp index 6e9cf21e7..2ffb3e02d 100644 --- a/plugins/DebuggerCore/unix/linux/PlatformProcess.cpp +++ b/plugins/DebuggerCore/unix/linux/PlatformProcess.cpp @@ -232,7 +232,7 @@ bool get_program_headers(const IProcess *process, edb::address_t *phdr_memaddr, *phdr_memaddr = entry.a_un.a_val; break; case AT_PHNUM: - *num_phdr = entry.a_un.a_val; + *num_phdr = static_cast(entry.a_un.a_val); break; } } @@ -389,8 +389,8 @@ std::size_t PlatformProcess::patchBytes(edb::address_t address, const void *buf, Patch patch; patch.address = address; - patch.origBytes.resize(len); - patch.newBytes = QByteArray(static_cast(buf), len); + patch.origBytes.resize(static_cast(len)); + patch.newBytes = QByteArray(static_cast(buf), static_cast(len)); size_t read_ret = readBytes(address, patch.origBytes.data(), len); if (read_ret != len) { From c80f287bc0907677d89bcf544c300b3fbfa20a8d Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 00:54:05 -0400 Subject: [PATCH 08/14] the last of it? --- plugins/HeapAnalyzer/DialogHeap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/HeapAnalyzer/DialogHeap.cpp b/plugins/HeapAnalyzer/DialogHeap.cpp index a9d96efd5..ada069b79 100644 --- a/plugins/HeapAnalyzer/DialogHeap.cpp +++ b/plugins/HeapAnalyzer/DialogHeap.cpp @@ -388,7 +388,7 @@ void DialogHeap::collectBlocks(edb::address_t start_address, edb::address_t end_ block_start(currentChunkAddress), asciiData, min_string_length, - currentChunk.chunkSize(), + static_cast(currentChunk.chunkSize()), asciisz)) { data = asciiData; @@ -397,7 +397,7 @@ void DialogHeap::collectBlocks(edb::address_t start_address, edb::address_t end_ block_start(currentChunkAddress), utf16Data, min_string_length, - currentChunk.chunkSize(), + static_cast(currentChunk.chunkSize()), utf16sz)) { data = utf16Data; data_type = ResultViewModel::Result::Utf16; From d87d077a7b0695ab8e0dbc570ac1ec699db8f0d5 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 00:56:57 -0400 Subject: [PATCH 09/14] forgot to account for debug builds! --- src/ByteShiftArray.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ByteShiftArray.cpp b/src/ByteShiftArray.cpp index a13245f1c..48cbb19cf 100644 --- a/src/ByteShiftArray.cpp +++ b/src/ByteShiftArray.cpp @@ -67,7 +67,7 @@ int ByteShiftArray::size() const { // Desc: returns and l-value version of an element in the byte array //------------------------------------------------------------------------------ uint8_t &ByteShiftArray::operator[](std::size_t i) { - Q_ASSERT(i < data_.size()); + Q_ASSERT(i < static_cast(data_.size())); return data_[static_cast(i)]; } @@ -76,7 +76,7 @@ uint8_t &ByteShiftArray::operator[](std::size_t i) { // Desc: returns and r-value version of an element in the byte array //------------------------------------------------------------------------------ uint8_t ByteShiftArray::operator[](std::size_t i) const { - Q_ASSERT(i < data_.size()); + Q_ASSERT(i < static_cast(data_.size())); return data_[static_cast(i)]; } From 27d9c5c625f920cc29e4a56ccc6bcef077eef554 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 01:07:04 -0400 Subject: [PATCH 10/14] this one only occurs when graphing is enabled --- src/graph/GraphNode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph/GraphNode.cpp b/src/graph/GraphNode.cpp index dd981f226..6186bb395 100644 --- a/src/graph/GraphNode.cpp +++ b/src/graph/GraphNode.cpp @@ -210,7 +210,7 @@ void GraphNode::drawLabel(const QString &text) { line.setNumColumns(l.length()); line.setPosition(QPoint(0, y)); - y += fm.lineSpacing(); + y += static_cast(fm.lineSpacing()); } textLayout.endLayout(); From e0c9552fa606232ed81cd05e8ce78cd99769317c Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 01:24:32 -0400 Subject: [PATCH 11/14] some more small improvements --- edb.appdata.xml | 24 ++++++++++++------------ include/BasicBlock.h | 2 +- include/BinaryString.h | 2 +- include/ByteShiftArray.h | 2 +- include/Configuration.h | 2 +- include/Function.h | 2 +- include/State.h | 2 +- include/Value.h | 3 +-- src/BasicBlock.cpp | 2 +- src/ByteShiftArray.cpp | 2 +- src/Function.cpp | 2 +- src/State.cpp | 2 +- src/capstone-edb/Instruction.cpp | 2 +- src/capstone-edb/include/Instruction.h | 2 +- 14 files changed, 25 insertions(+), 26 deletions(-) diff --git a/edb.appdata.xml b/edb.appdata.xml index 04583cf0d..7942f8de9 100644 --- a/edb.appdata.xml +++ b/edb.appdata.xml @@ -6,25 +6,25 @@ GPL-2.0 edb Reverse engineer's debugger - + --> edb-debugger -

edb is a cross platform x86/x86-64 debugger. It was inspired by OllyDbg, - but aims to function on x86 and x86-64 as well as multiple OS's. -

-

Linux is the only officially supported platform at the moment, but FreeBSD, - OpenBSD, OSX and Windows ports are underway with varying degrees of functionality. -

+

edb is a cross platform x86/x86-64 debugger. It was inspired by OllyDbg, + but aims to function on x86 and x86-64 as well as multiple OS's. +

+

Linux is the only officially supported platform at the moment, but FreeBSD, + OpenBSD, OSX and Windows ports are underway with varying degrees of functionality. +

- http://codef00.com/img/debugger.png - Main Window, with disassembly, data, stack and registers - + http://codef00.com/img/debugger.png + Main Window, with disassembly, data, stack and registers + evan.teran_at_gmail.com https://github.com/eteran/edb-debugger @@ -36,7 +36,7 @@ mild - + diff --git a/include/BasicBlock.h b/include/BasicBlock.h index 7bb0bf13b..fab9bdcd9 100644 --- a/include/BasicBlock.h +++ b/include/BasicBlock.h @@ -59,7 +59,7 @@ class EDB_EXPORT BasicBlock { [[nodiscard]] bool empty() const; public: - void swap(BasicBlock &other); + void swap(BasicBlock &other) noexcept; public: [[nodiscard]] QString toString() const; diff --git a/include/BinaryString.h b/include/BinaryString.h index e19d15f93..8a1801647 100644 --- a/include/BinaryString.h +++ b/include/BinaryString.h @@ -27,7 +27,7 @@ class EDB_EXPORT BinaryString : public QWidget { }; public: - BinaryString(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); + explicit BinaryString(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); ~BinaryString() override; private Q_SLOTS: diff --git a/include/ByteShiftArray.h b/include/ByteShiftArray.h index d83a0c1b5..181228ee9 100644 --- a/include/ByteShiftArray.h +++ b/include/ByteShiftArray.h @@ -22,7 +22,7 @@ class EDB_EXPORT ByteShiftArray { ByteShiftArray &shl(); ByteShiftArray &shr(); void clear(); - void swap(ByteShiftArray &other); + void swap(ByteShiftArray &other) noexcept; public: ByteShiftArray &operator<<(uint8_t x); diff --git a/include/Configuration.h b/include/Configuration.h index 4fe74c295..864e59abd 100644 --- a/include/Configuration.h +++ b/include/Configuration.h @@ -16,7 +16,7 @@ class EDB_EXPORT Configuration : public QObject { Q_OBJECT public: - Configuration(QObject *parent = nullptr); + explicit Configuration(QObject *parent = nullptr); ~Configuration() override; public: diff --git a/include/Function.h b/include/Function.h index 834f618fd..0e87da7a4 100644 --- a/include/Function.h +++ b/include/Function.h @@ -70,7 +70,7 @@ class EDB_EXPORT Function { [[nodiscard]] int referenceCount() const; public: - void swap(Function &other); + void swap(Function &other) noexcept; private: int referenceCount_ = 0; diff --git a/include/State.h b/include/State.h index 911131652..7332aa725 100644 --- a/include/State.h +++ b/include/State.h @@ -38,7 +38,7 @@ class EDB_EXPORT State { ~State(); public: - void swap(State &other); + void swap(State &other) noexcept; public: [[nodiscard]] bool empty() const; diff --git a/include/Value.h b/include/Value.h index 042e7514c..f84b29e9c 100644 --- a/include/Value.h +++ b/include/Value.h @@ -35,7 +35,6 @@ EDB_EXPORT bool debuggeeIs32Bit(); #pragma GCC diagnostic ignored "-Wconversion" #pragma GCC diagnostic ignored "-Wsign-conversion" - namespace detail { template @@ -233,7 +232,7 @@ class value_type { } public: - void swap(value_type &other) { + void swap(value_type &other) noexcept { using std::swap; swap(value_, other.value_); } diff --git a/src/BasicBlock.cpp b/src/BasicBlock.cpp index b685a69fa..1994636d1 100644 --- a/src/BasicBlock.cpp +++ b/src/BasicBlock.cpp @@ -14,7 +14,7 @@ * @brief BasicBlock::swap * @param other */ -void BasicBlock::swap(BasicBlock &other) { +void BasicBlock::swap(BasicBlock &other) noexcept { using std::swap; swap(instructions_, other.instructions_); swap(references_, other.references_); diff --git a/src/ByteShiftArray.cpp b/src/ByteShiftArray.cpp index 48cbb19cf..52f3c8137 100644 --- a/src/ByteShiftArray.cpp +++ b/src/ByteShiftArray.cpp @@ -19,7 +19,7 @@ ByteShiftArray::ByteShiftArray(int size) // Name: swap // Desc: //------------------------------------------------------------------------------ -void ByteShiftArray::swap(ByteShiftArray &other) { +void ByteShiftArray::swap(ByteShiftArray &other) noexcept { using std::swap; swap(data_, other.data_); swap(maxSize_, other.maxSize_); diff --git a/src/Function.cpp b/src/Function.cpp index 88b6f0152..3563d7f3a 100644 --- a/src/Function.cpp +++ b/src/Function.cpp @@ -10,7 +10,7 @@ * @brief Function::swap * @param other */ -void Function::swap(Function &other) { +void Function::swap(Function &other) noexcept { using std::swap; swap(referenceCount_, other.referenceCount_); swap(type_, other.type_); diff --git a/src/State.cpp b/src/State.cpp index 97819112f..85d7766e5 100644 --- a/src/State.cpp +++ b/src/State.cpp @@ -45,7 +45,7 @@ State::State(State &&other) noexcept * @brief State::swap * @param other */ -void State::swap(State &other) { +void State::swap(State &other) noexcept { using std::swap; swap(impl_, other.impl_); } diff --git a/src/capstone-edb/Instruction.cpp b/src/capstone-edb/Instruction.cpp index 9e495b695..776956a59 100644 --- a/src/capstone-edb/Instruction.cpp +++ b/src/capstone-edb/Instruction.cpp @@ -396,7 +396,7 @@ Instruction::ConditionCode Instruction::conditionCode() const { #endif } -void Instruction::swap(Instruction &other) { +void Instruction::swap(Instruction &other) noexcept { using std::swap; swap(insn_, other.insn_); swap(byte0_, other.byte0_); diff --git a/src/capstone-edb/include/Instruction.h b/src/capstone-edb/include/Instruction.h index 589aa229e..0048c9deb 100644 --- a/src/capstone-edb/include/Instruction.h +++ b/src/capstone-edb/include/Instruction.h @@ -89,7 +89,7 @@ class EDB_EXPORT Instruction { const cs_insn *operator->() const { return insn_; } public: - void swap(Instruction &other); + void swap(Instruction &other) noexcept; public: enum ConditionCode : uint8_t { From 276c92ff3b11b9660755c27e50c8216e13a9bcb6 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 01:25:41 -0400 Subject: [PATCH 12/14] formatting --- src/Debugger.cpp | 2 +- src/arch/x86-generic/ArchProcessor.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Debugger.cpp b/src/Debugger.cpp index e236018b8..46d7d6ebd 100644 --- a/src/Debugger.cpp +++ b/src/Debugger.cpp @@ -1202,7 +1202,7 @@ void Debugger::showEvent(QShowEvent *) { stackView_->setShowAsciiDump(settings.value("window.stack.show_ascii.enabled", true).toBool()); stackView_->setShowComments(settings.value("window.stack.show_comments.enabled", true).toBool()); - int row_width = 1; + int row_width = 1; auto word_width = static_cast(edb::v1::pointer_size()); stackView_->setRowWidth(row_width); diff --git a/src/arch/x86-generic/ArchProcessor.cpp b/src/arch/x86-generic/ArchProcessor.cpp index 022ab1373..4274c5fa4 100644 --- a/src/arch/x86-generic/ArchProcessor.cpp +++ b/src/arch/x86-generic/ArchProcessor.cpp @@ -1651,7 +1651,7 @@ bool ArchProcessor::isFilling(const edb::Instruction &inst) const { if (edb::v1::config().zeros_are_filling) { auto lhs = QByteArray::fromRawData(reinterpret_cast(inst.bytes()), static_cast(inst.byteSize())); auto rhs = QByteArray::fromRawData("\x00\x00", 2); - ret = (lhs == rhs); + ret = (lhs == rhs); } } } else { From 41b78fdf2ce86a02ba5e5276f8ef1613e7c158de Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 01:33:47 -0400 Subject: [PATCH 13/14] removing some pointless code --- src/widgets/QDisassemblyView.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/widgets/QDisassemblyView.cpp b/src/widgets/QDisassemblyView.cpp index 6d08f9d11..12d2e453f 100644 --- a/src/widgets/QDisassemblyView.cpp +++ b/src/widgets/QDisassemblyView.cpp @@ -443,11 +443,6 @@ void QDisassemblyView::scrollbarActionTriggered(int action) { address = followingInstructions(address, verticalScrollBar()->pageStep()); verticalScrollBar()->setSliderPosition(address); } break; - - case QAbstractSlider::SliderToMinimum: - case QAbstractSlider::SliderToMaximum: - case QAbstractSlider::SliderMove: - case QAbstractSlider::SliderNoAction: default: break; } From d3b37dc781dc0b4e8a9223b69b75d69ca7e32a98 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 19 Mar 2026 01:36:45 -0400 Subject: [PATCH 14/14] formatting better auto usage --- plugins/BinaryInfo/symbols.cpp | 2 +- plugins/InstructionInspector/Plugin.cpp | 28 ++++++++++++------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/plugins/BinaryInfo/symbols.cpp b/plugins/BinaryInfo/symbols.cpp index 3ef51e6fb..3923b20eb 100644 --- a/plugins/BinaryInfo/symbols.cpp +++ b/plugins/BinaryInfo/symbols.cpp @@ -280,7 +280,7 @@ void collect_symbols(const void *p, Size size, std::vector & auto symbol_tab = reinterpret_cast(base + linked->sh_offset); auto string_tab = reinterpret_cast(base + sections_begin[linked->sh_link].sh_offset); - const elf_addr symbol_address = static_cast(base_address + (n * M::plt_entry_size)); + const auto symbol_address = static_cast(base_address + (n * M::plt_entry_size)); const char *sym_name = §ion_strings[section->sh_name]; if (strlen(sym_name) > (sizeof(".rel.") - 1) && memcmp(sym_name, ".rel.", (sizeof(".rel.") - 1)) == 0) { diff --git a/plugins/InstructionInspector/Plugin.cpp b/plugins/InstructionInspector/Plugin.cpp index 795d0f1db..967ce5189 100644 --- a/plugins/InstructionInspector/Plugin.cpp +++ b/plugins/InstructionInspector/Plugin.cpp @@ -769,7 +769,7 @@ std::string runOBJDUMP(const std::vector &bytes, edb::address_t ad return "; Failed to create binary file"; } - const qint64 size = static_cast(bytes.size()); + const auto size = static_cast(bytes.size()); if (binary.write(reinterpret_cast(bytes.data()), size) != size) { return "; Failed to write to binary file"; @@ -777,24 +777,22 @@ std::string runOBJDUMP(const std::vector &bytes, edb::address_t ad binary.close(); QProcess process; - process.start(processName.c_str(), { - "-D", - "--target=binary", + process.start(processName.c_str(), {"-D", + "--target=binary", #if defined(EDB_X86) || defined(EDB_X86_64) - "--insn-width=15", - "--architecture=i386" + QString(bits == 64 ? ":x86-64" : ""), - "-M", - "intel,intel-mnemonic", + "--insn-width=15", + "--architecture=i386" + QString(bits == 64 ? ":x86-64" : ""), + "-M", + "intel,intel-mnemonic", #elif defined(EDB_ARM32) - "--insn-width=4", - "-m", - "arm", - edb::v1::debugger_core->cpuMode() == IDebugger::CpuMode::Thumb ? "-Mforce-thumb" : "-Mno-force-thumb", + "--insn-width=4", + "-m", + "arm", + edb::v1::debugger_core->cpuMode() == IDebugger::CpuMode::Thumb ? "-Mforce-thumb" : "-Mno-force-thumb", #else #error "Not implemented" #endif - "--adjust-vma=" + address.toPointerString(), binary.fileName() - }); + "--adjust-vma=" + address.toPointerString(), binary.fileName()}); if (process.waitForFinished()) { if (process.exitCode() != 0) { @@ -890,7 +888,7 @@ std::string runNDISASM(const std::vector &bytes, edb::address_t ad return "; Failed to create binary file"; } - const qint64 size = static_cast(bytes.size()); + const auto size = static_cast(bytes.size()); if (binary.write(reinterpret_cast(bytes.data()), size) != size) { return "; Failed to write to binary file";