From 44f33b297c3a708d96e2338c064a2ecd56479794 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 27 Apr 2024 10:28:31 +0100 Subject: [PATCH 01/25] Enable compilation database generation in CMake file. `CMAKE_EXPORT_COMPILE_COMMANDS` is now enabled. Supported generators (e.g. Ninja or Makefile) will now produce a `compile_commands.json` file in the build directory. --- Source/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 23b3a896..39374330 100755 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -4,6 +4,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(GCC_min_version 10) project(dolphin-memory-engine) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + if(WIN32) set(DolphinProcessSrc DolphinProcess/Windows/WindowsDolphinProcess.cpp) set(ExeIconSrc Resources/exeicon.rc) From 40cefd27346a2e44c533a41c410b5f65c40d5d40 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 15:17:58 +0100 Subject: [PATCH 02/25] Add Clang-Tidy configuration file. The check list has been manually crafted for the Dolphin Memory Engine project. Checks that are generally not worth fixing have been disabled, but it is possible there are more checks that could be disabled; devs are encouraged to disable them when the time comes. --- Source/.clang-tidy | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Source/.clang-tidy diff --git a/Source/.clang-tidy b/Source/.clang-tidy new file mode 100644 index 00000000..55e472a8 --- /dev/null +++ b/Source/.clang-tidy @@ -0,0 +1,37 @@ +Checks: > + -*, + bugprone-*, + -bugprone-branch-clone, + -bugprone-easily-swappable-parameters, + -bugprone-misplaced-widening-cast, + google-*, + -google-readability-braces-around-statements, + hicpp-*, + -hicpp-avoid-c-arrays, + -hicpp-braces-around-statements, + -hicpp-uppercase-literal-suffix, + -hicpp-use-auto, + -hicpp-use-equals-default, + misc-*, + -misc-const-correctness, + -misc-include-cleaner, + -misc-no-recursion, + -misc-non-private-member-variables-in-classes, + -misc-unused-parameters, + -misc-use-anonymous-namespace, + modernize-*, + -modernize-avoid-c-arrays, + -modernize-use-auto, + -modernize-use-nodiscard, + -modernize-use-trailing-return-type, + performance-*, + -performance-no-int-to-ptr, + readability-*, + -readability-braces-around-statements, + -readability-function-cognitive-complexity, + -readability-identifier-length, + -readability-implicit-bool-conversion, + -readability-magic-numbers, + -readability-uppercase-literal-suffix + +FormatStyle: file From 98283d283470c34e6c3d6dcf0a8978c3b4e621ef Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 15:59:33 +0100 Subject: [PATCH 03/25] Address `bugprone-integer-division` warnings. Warning was: ``` /w/dolphin-memory-engine/Source/GUI/MemViewer/MemViewer.cpp:918:9: warning: result of integer division used in a floating point context; possible loss of precision [bugprone-integer-division] 918 | (1000 - (m_elapsedTimer.elapsed() - | ^ /w/dolphin-memory-engine/Source/GUI/MemViewer/MemViewer.cpp:920:10: warning: result of integer division used in a floating point context; possible loss of precision [bugprone-integer-division] 920 | (1000 / 100); | ^ ``` --- Source/GUI/MemViewer/MemViewer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/GUI/MemViewer/MemViewer.cpp b/Source/GUI/MemViewer/MemViewer.cpp index 7e845ca8..0efbb643 100644 --- a/Source/GUI/MemViewer/MemViewer.cpp +++ b/Source/GUI/MemViewer/MemViewer.cpp @@ -915,9 +915,10 @@ void MemViewer::determineMemoryTextRenderProperties(const int rowIndex, const in { QColor baseColor = QColor(Qt::red); float alphaPercentage = - (1000 - (m_elapsedTimer.elapsed() - - m_memoryMsElapsedLastChange[rowIndex * m_numColumns + columnIndex])) / - (1000 / 100); + (1000.0f - + static_cast(m_elapsedTimer.elapsed() - + m_memoryMsElapsedLastChange[rowIndex * m_numColumns + columnIndex])) / + (1000.0f / 100.0f); int newAlpha = std::trunc(baseColor.alpha() * (alphaPercentage / 100)); bgColor = QColor(baseColor.red(), baseColor.green(), baseColor.blue(), newAlpha); } From 126a833449e8b7416eea16ed43776f6116009f64 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 16:21:19 +0100 Subject: [PATCH 04/25] Address `bugprone-multi-level-implicit-pointer-conversion` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchModel.cpp:432:34: warning: multilevel pointer conversion from 'MemWatchTreeNode **' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] 432 | std::memcpy(&leastDeepPointer, &leastDeepNode, sizeof(MemWatchTreeNode*)); | ^ /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchModel.cpp:438:27: warning: multilevel pointer conversion from 'MemWatchTreeNode **' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] 438 | std::memcpy(&pointer, &node, sizeof(node)); | ^ /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchModel.cpp:462:15: warning: multilevel pointer conversion from 'MemWatchTreeNode **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] 462 | std::memcpy(&leastDeepNode, &leastDeepNodePtr, sizeof(leastDeepNodePtr)); | ^ /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchModel.cpp:489:17: warning: multilevel pointer conversion from 'MemWatchTreeNode **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] 489 | std::memcpy(&srcNode, &nodePtr, sizeof(nodePtr)); | ^ ``` The bitwise casts are now applied via `std::bit_cast`. --- Source/Common/CommonUtils.h | 13 +++++++++++++ Source/GUI/MemWatcher/MemWatchModel.cpp | 19 +++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Source/Common/CommonUtils.h b/Source/Common/CommonUtils.h index 36802cfc..cbe28efb 100644 --- a/Source/Common/CommonUtils.h +++ b/Source/Common/CommonUtils.h @@ -21,6 +21,19 @@ namespace Common { +template +To bit_cast(From from) // To be replaced with std::bit_cast when available +{ + static_assert(sizeof(From) == sizeof(To), "Type sizes do not match"); + union + { + From f; + To t; + } u; + u.f = from; + return u.t; +} + #ifdef _WIN32 inline u16 bSwap16(u16 data) { diff --git a/Source/GUI/MemWatcher/MemWatchModel.cpp b/Source/GUI/MemWatcher/MemWatchModel.cpp index 7902338a..2af2e170 100644 --- a/Source/GUI/MemWatcher/MemWatchModel.cpp +++ b/Source/GUI/MemWatcher/MemWatchModel.cpp @@ -2,11 +2,13 @@ #include #include + #include #include #include #include "../../CheatEngineParser/CheatEngineParser.h" +#include "../../Common/CommonUtils.h" #include "../GUICommon.h" MemWatchModel::MemWatchModel(QObject* parent) : QAbstractItemModel(parent) @@ -427,15 +429,14 @@ QMimeData* MemWatchModel::mimeData(const QModelIndexList& indexes) const if (!nodes.contains(node)) nodes << node; } - qulonglong leastDeepPointer = 0; MemWatchTreeNode* leastDeepNode = getLeastDeepNodeFromList(nodes); - std::memcpy(&leastDeepPointer, &leastDeepNode, sizeof(MemWatchTreeNode*)); + const qulonglong leastDeepPointer{ + Common::bit_cast(leastDeepNode)}; stream << leastDeepPointer; stream << static_cast(nodes.count()); foreach (MemWatchTreeNode* node, nodes) { - qulonglong pointer = 0; - std::memcpy(&pointer, &node, sizeof(node)); + const auto pointer{Common::bit_cast(node)}; stream << pointer; } mimeData->setData("application/x-memwatchtreenode", data); @@ -456,10 +457,9 @@ bool MemWatchModel::dropMimeData(const QMimeData* data, Qt::DropAction action, i else destParentNode = static_cast(parent.internalPointer()); - qlonglong leastDeepNodePtr; + qulonglong leastDeepNodePtr{}; stream >> leastDeepNodePtr; - MemWatchTreeNode* leastDeepNode = nullptr; - std::memcpy(&leastDeepNode, &leastDeepNodePtr, sizeof(leastDeepNodePtr)); + auto* const leastDeepNode{Common::bit_cast(leastDeepNodePtr)}; if (row == -1) { @@ -483,10 +483,9 @@ bool MemWatchModel::dropMimeData(const QMimeData* data, Qt::DropAction action, i for (int i = 0; i < count; ++i) { - qlonglong nodePtr; + qulonglong nodePtr{}; stream >> nodePtr; - MemWatchTreeNode* srcNode = nullptr; - std::memcpy(&srcNode, &nodePtr, sizeof(nodePtr)); + auto* const srcNode{Common::bit_cast(nodePtr)}; // Since beginMoveRows uses the same row format then the one received, we want to keep that, but // still use the correct row number for inserting. From fd9362b2be8e5f483338fa58729ea0fdf650802a Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 16:26:11 +0100 Subject: [PATCH 05/25] Address `bugprone-signed-char-misuse` warnings. The one warning was: ``` /w/dolphin-memory-engine/Source/GUI/MemViewer/MemViewer.cpp:954:24: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse] 954 | int asciiByte = (int)asciiStr[0]; | ^ ``` --- Source/GUI/MemViewer/MemViewer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/GUI/MemViewer/MemViewer.cpp b/Source/GUI/MemViewer/MemViewer.cpp index 0efbb643..af8df09d 100644 --- a/Source/GUI/MemViewer/MemViewer.cpp +++ b/Source/GUI/MemViewer/MemViewer.cpp @@ -952,7 +952,7 @@ void MemViewer::renderASCIIText(QPainter& painter, const int rowIndex, const int std::string asciiStr = Common::formatMemoryToString( m_updatedRawMemoryData + ((rowIndex * m_numColumns) + columnIndex), Common::MemType::type_string, 1, Common::MemBase::base_none, true); - int asciiByte = (int)asciiStr[0]; + const int asciiByte{static_cast(static_cast(asciiStr[0]))}; if (asciiByte > 0x7E || asciiByte < 0x20) asciiStr = "."; QRect* currentCharRect = new QRect( From 8a18f3422236d45287e3c1f06dea31415ef05b43 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 16:32:28 +0100 Subject: [PATCH 06/25] Address `bugprone-unused-local-non-trivial-variable` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/CheatEngineParser/CheatEngineParser.cpp:42:17: warning: unused local variable 'test' of type 'std::string' (aka 'basic_string') [bugprone-unused-local-non-trivial-variable] 42 | std::string test = m_xmlReader->name().toString().toStdString(); | ^ /w/dolphin-memory-engine/Source/CheatEngineParser/CheatEngineParser.cpp:74:19: warning: unused local variable 'test' of type 'std::string' (aka 'basic_string') [bugprone-unused-local-non-trivial-variable] 74 | std::string test = m_xmlReader->name().toString().toStdString(); | ^ /w/dolphin-memory-engine/Source/CheatEngineParser/CheatEngineParser.cpp:98:19: warning: unused local variable 'test' of type 'std::string' (aka 'basic_string') [bugprone-unused-local-non-trivial-variable] 98 | std::string test = m_xmlReader->name().toString().toStdString(); | ^ /w/dolphin-memory-engine/Source/Common/MemoryCommon.cpp:421:25: warning: unused local variable 'byteStream' of type 'std::stringstream' (aka 'basic_stringstream') [bugprone-unused-local-non-trivial-variable] 421 | std::stringstream byteStream(i); | ^ ``` --- Source/CheatEngineParser/CheatEngineParser.cpp | 3 --- Source/Common/MemoryCommon.cpp | 1 - 2 files changed, 4 deletions(-) diff --git a/Source/CheatEngineParser/CheatEngineParser.cpp b/Source/CheatEngineParser/CheatEngineParser.cpp index b8eadda4..7b576d15 100644 --- a/Source/CheatEngineParser/CheatEngineParser.cpp +++ b/Source/CheatEngineParser/CheatEngineParser.cpp @@ -39,7 +39,6 @@ MemWatchTreeNode* CheatEngineParser::parseCTFile(QIODevice* CTFileIODevice, if (m_xmlReader->readNextStartElement()) { - std::string test = m_xmlReader->name().toString().toStdString(); if (m_xmlReader->name() == QString("CheatTable")) { MemWatchTreeNode* rootNode = new MemWatchTreeNode(nullptr); @@ -71,7 +70,6 @@ MemWatchTreeNode* CheatEngineParser::parseCheatTable(MemWatchTreeNode* rootNode, { if (m_xmlReader->readNextStartElement()) { - std::string test = m_xmlReader->name().toString().toStdString(); if (m_xmlReader->name() == QString("CheatEntries")) parseCheatEntries(rootNode, useDolphinPointer); } @@ -95,7 +93,6 @@ MemWatchTreeNode* CheatEngineParser::parseCheatEntries(MemWatchTreeNode* node, { if (m_xmlReader->readNextStartElement()) { - std::string test = m_xmlReader->name().toString().toStdString(); if (m_xmlReader->name() == QString("CheatEntry")) parseCheatEntry(node, useDolphinPointer); } diff --git a/Source/Common/MemoryCommon.cpp b/Source/Common/MemoryCommon.cpp index 321ef3ca..ec8a70a9 100644 --- a/Source/Common/MemoryCommon.cpp +++ b/Source/Common/MemoryCommon.cpp @@ -419,7 +419,6 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen int index = 0; for (const auto& i : bytes) { - std::stringstream byteStream(i); ss >> std::hex; u8 theByte = 0; int theByteInt = 0; From df1d84cf729dd4f99bd8559faf3c6db62e753911 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 21:02:09 +0100 Subject: [PATCH 07/25] Address `google-readability-casting` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp:166:21: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [google-readability-casting] 166 | remote.iov_base = (void*)RAMAddress; | ^ /w/dolphin-memory-engine/Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp:235:21: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [google-readability-casting] 235 | remote.iov_base = (void*)RAMAddress; | ^ /w/dolphin-memory-engine/Source/GUI/MemCopy/DlgCopy.cpp:159:23: warning: C-style casts are discouraged; use static_cast [google-readability-casting] 159 | (DlgCopy::ByteStringFormats)m_cmbViewerBytesSeparator->currentIndex()))); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ | static_cast( ) /w/dolphin-memory-engine/Source/GUI/MemCopy/DlgCopy.cpp:221:12: warning: C-style casts are discouraged; use static_cast [google-readability-casting] 221 | output = (u32)u; | ^~~~~ | static_cast( ) /w/dolphin-memory-engine/Source/GUI/MemViewer/MemViewer.cpp:733:75: warning: C-style casts are discouraged; use static_cast [google-readability-casting] 733 | u32 offsetToWrite = Common::dolphinAddrToOffset(m_currentFirstAddress + (u32)memoryOffset, | ^~~~~ | static_cast() ``` --- Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp | 4 ++-- Source/DolphinProcess/Windows/WindowsDolphinProcess.cpp | 6 ++++-- Source/GUI/MemCopy/DlgCopy.cpp | 8 ++++---- Source/GUI/MemViewer/MemViewer.cpp | 5 +++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp b/Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp index bae5a6d4..7ed406cc 100644 --- a/Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp +++ b/Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp @@ -163,7 +163,7 @@ bool LinuxDolphinProcess::readFromRAM(const u32 offset, char* buffer, const size local.iov_base = buffer; local.iov_len = size; - remote.iov_base = (void*)RAMAddress; + remote.iov_base = reinterpret_cast(RAMAddress); remote.iov_len = size; nread = process_vm_readv(m_PID, &local, 1, &remote, 1, 0); @@ -232,7 +232,7 @@ bool LinuxDolphinProcess::writeToRAM(const u32 offset, const char* buffer, const local.iov_base = bufferCopy; local.iov_len = size; - remote.iov_base = (void*)RAMAddress; + remote.iov_base = reinterpret_cast(RAMAddress); remote.iov_len = size; if (withBSwap) diff --git a/Source/DolphinProcess/Windows/WindowsDolphinProcess.cpp b/Source/DolphinProcess/Windows/WindowsDolphinProcess.cpp index 1e640d98..8564eb5c 100644 --- a/Source/DolphinProcess/Windows/WindowsDolphinProcess.cpp +++ b/Source/DolphinProcess/Windows/WindowsDolphinProcess.cpp @@ -173,7 +173,8 @@ bool WindowsDolphinProcess::readFromRAM(const u32 offset, char* buffer, const si } SIZE_T nread = 0; - bool bResult = ReadProcessMemory(m_hDolphin, (void*)RAMAddress, buffer, size, &nread); + const bool bResult{static_cast( + ReadProcessMemory(m_hDolphin, reinterpret_cast(RAMAddress), buffer, size, &nread))}; if (bResult && nread == size) { if (withBSwap) @@ -265,7 +266,8 @@ bool WindowsDolphinProcess::writeToRAM(const u32 offset, const char* buffer, con } } - bool bResult = WriteProcessMemory(m_hDolphin, (void*)RAMAddress, bufferCopy, size, &nread); + const bool bResult{static_cast(WriteProcessMemory( + m_hDolphin, reinterpret_cast(RAMAddress), bufferCopy, size, &nread))}; delete[] bufferCopy; return (bResult && nread == size); } diff --git a/Source/GUI/MemCopy/DlgCopy.cpp b/Source/GUI/MemCopy/DlgCopy.cpp index 2b65a4f9..c4b35e2e 100644 --- a/Source/GUI/MemCopy/DlgCopy.cpp +++ b/Source/GUI/MemCopy/DlgCopy.cpp @@ -154,9 +154,9 @@ bool DlgCopy::copyMemory() void DlgCopy::updateMemoryText() { - m_spnWatcherCopyOutput->setText(QString::fromStdString( - charToHexString(m_Data.data(), m_Data.size(), - (DlgCopy::ByteStringFormats)m_cmbViewerBytesSeparator->currentIndex()))); + m_spnWatcherCopyOutput->setText(QString::fromStdString(charToHexString( + m_Data.data(), m_Data.size(), + static_cast(m_cmbViewerBytesSeparator->currentIndex())))); } bool DlgCopy::isHexString(std::string str) @@ -217,7 +217,7 @@ bool DlgCopy::uintStringToU32(std::string str, u32& output) if (u > ULONG_MAX) return false; - output = (u32)u; + output = static_cast(u); return true; } diff --git a/Source/GUI/MemViewer/MemViewer.cpp b/Source/GUI/MemViewer/MemViewer.cpp index af8df09d..cf5fe23b 100644 --- a/Source/GUI/MemViewer/MemViewer.cpp +++ b/Source/GUI/MemViewer/MemViewer.cpp @@ -730,8 +730,9 @@ bool MemViewer::writeCharacterToSelectedMemory(char byteToWrite) byteToWrite = selectedMemoryValue & 0x0F | (byteToWrite << 4); } - u32 offsetToWrite = Common::dolphinAddrToOffset(m_currentFirstAddress + (u32)memoryOffset, - DolphinComm::DolphinAccessor::isARAMAccessible()); + const u32 offsetToWrite{ + Common::dolphinAddrToOffset(m_currentFirstAddress + static_cast(memoryOffset), + DolphinComm::DolphinAccessor::isARAMAccessible())}; return DolphinComm::DolphinAccessor::writeToRAM(offsetToWrite, &byteToWrite, 1, false); } From 3bb5aa26c4bd4a5929c5aa86598de74c17aa5575 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 16:41:21 +0100 Subject: [PATCH 08/25] Address `google-runtime-int` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/Common/MemoryCommon.cpp:160:7: warning: consider replacing 'unsigned long long' with 'uint64' [google-runtime-int] 160 | unsigned long long input = 0; | ^ /w/dolphin-memory-engine/Source/Common/MemoryCommon.cpp:198:7: warning: consider replacing 'unsigned long long' with 'uint64' [google-runtime-int] 198 | unsigned long long input = 0; | ^ /w/dolphin-memory-engine/Source/Common/MemoryCommon.cpp:234:7: warning: consider replacing 'unsigned long long' with 'uint64' [google-runtime-int] 234 | unsigned long long input = 0; | ^ /w/dolphin-memory-engine/Source/Common/MemoryCommon.cpp:272:9: warning: consider replacing 'unsigned long long' with 'uint64' [google-runtime-int] 272 | unsigned long long input = 0; | ^ /w/dolphin-memory-engine/Source/Common/MemoryCommon.cpp:325:9: warning: consider replacing 'unsigned long long' with 'uint64' [google-runtime-int] 325 | unsigned long long input = 0; | ^ ``` --- Source/Common/MemoryCommon.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Source/Common/MemoryCommon.cpp b/Source/Common/MemoryCommon.cpp index ec8a70a9..5c12ef0a 100644 --- a/Source/Common/MemoryCommon.cpp +++ b/Source/Common/MemoryCommon.cpp @@ -158,10 +158,10 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen u8 theByte = 0; if (base == MemBase::base_binary) { - unsigned long long input = 0; + u8 input{}; try { - input = std::bitset(inputString).to_ullong(); + input = static_cast(std::bitset(inputString).to_ullong()); } catch (std::invalid_argument) { @@ -170,7 +170,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen returnCode = MemOperationReturnCode::invalidInput; return buffer; } - theByte = static_cast(input); + theByte = input; } else { @@ -196,10 +196,10 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen u16 theHalfword = 0; if (base == MemBase::base_binary) { - unsigned long long input = 0; + u16 input{}; try { - input = std::bitset(inputString).to_ullong(); + input = static_cast(std::bitset(inputString).to_ullong()); } catch (std::invalid_argument) { @@ -208,7 +208,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen returnCode = MemOperationReturnCode::invalidInput; return buffer; } - theHalfword = static_cast(input); + theHalfword = input; } else { @@ -232,10 +232,10 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen u32 theWord = 0; if (base == MemBase::base_binary) { - unsigned long long input = 0; + u32 input{}; try { - input = std::bitset(inputString).to_ullong(); + input = static_cast(std::bitset(inputString).to_ullong()); } catch (std::invalid_argument) { @@ -244,7 +244,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen returnCode = MemOperationReturnCode::invalidInput; return buffer; } - theWord = static_cast(input); + theWord = input; } else { @@ -270,10 +270,10 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen u32 theWord = 0; if (base == MemBase::base_binary) { - unsigned long long input = 0; + u32 input{}; try { - input = std::bitset(inputString).to_ullong(); + input = static_cast(std::bitset(inputString).to_ullong()); } catch (const std::invalid_argument&) { @@ -282,7 +282,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen returnCode = MemOperationReturnCode::invalidInput; return buffer; } - theWord = static_cast(input); + theWord = input; } else { @@ -323,10 +323,10 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen u64 theDoubleWord = 0; if (base == MemBase::base_binary) { - unsigned long long input = 0; + u64 input{}; try { - input = std::bitset(inputString).to_ullong(); + input = static_cast(std::bitset(inputString).to_ullong()); } catch (const std::invalid_argument&) { @@ -335,7 +335,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen returnCode = MemOperationReturnCode::invalidInput; return buffer; } - theDoubleWord = static_cast(input); + theDoubleWord = input; } else { From 243c639bbf6cbe824c35fd26b518087c40c146e0 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 16:54:14 +0100 Subject: [PATCH 09/25] Address `hicpp-use-equals-default` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/DolphinProcess/IDolphinProcess.h:13:11: warning: use '= default' to define a trivial destructor [hicpp-use-equals-default] 13 | virtual ~IDolphinProcess() {} | ^ ~~ | = default; /w/dolphin-memory-engine/Source/DolphinProcess/Linux/LinuxDolphinProcess.h:16:3: warning: use '= default' to define a trivial default constructor [hicpp-use-equals-default] 16 | LinuxDolphinProcess() {} | ^ ~~ | = default; /w/dolphin-memory-engine/Source/GUI/MemScanner/ResultsListModel.cpp:8:19: warning: use '= default' to define a trivial destructor [hicpp-use-equals-default] 8 | ResultsListModel::~ResultsListModel() | ^ 9 | { | ~ | = default; 10 | } | ~ ``` --- Source/DolphinProcess/IDolphinProcess.h | 2 +- Source/DolphinProcess/Linux/LinuxDolphinProcess.h | 2 +- Source/DolphinProcess/Mac/MacDolphinProcess.h | 2 +- Source/DolphinProcess/Windows/WindowsDolphinProcess.h | 2 +- Source/GUI/MemScanner/ResultsListModel.cpp | 4 +--- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Source/DolphinProcess/IDolphinProcess.h b/Source/DolphinProcess/IDolphinProcess.h index 2609c02b..f2f819f3 100644 --- a/Source/DolphinProcess/IDolphinProcess.h +++ b/Source/DolphinProcess/IDolphinProcess.h @@ -10,7 +10,7 @@ namespace DolphinComm class IDolphinProcess { public: - virtual ~IDolphinProcess() {} + virtual ~IDolphinProcess() = default; virtual bool findPID() = 0; virtual bool obtainEmuRAMInformations() = 0; virtual bool readFromRAM(const u32 offset, char* buffer, const size_t size, diff --git a/Source/DolphinProcess/Linux/LinuxDolphinProcess.h b/Source/DolphinProcess/Linux/LinuxDolphinProcess.h index 58026f65..0e2ed0a9 100644 --- a/Source/DolphinProcess/Linux/LinuxDolphinProcess.h +++ b/Source/DolphinProcess/Linux/LinuxDolphinProcess.h @@ -13,7 +13,7 @@ namespace DolphinComm class LinuxDolphinProcess : public IDolphinProcess { public: - LinuxDolphinProcess() {} + LinuxDolphinProcess() = default; bool findPID() override; bool obtainEmuRAMInformations() override; bool readFromRAM(const u32 offset, char* buffer, size_t size, const bool withBSwap) override; diff --git a/Source/DolphinProcess/Mac/MacDolphinProcess.h b/Source/DolphinProcess/Mac/MacDolphinProcess.h index 4b235254..a0f4e8c1 100644 --- a/Source/DolphinProcess/Mac/MacDolphinProcess.h +++ b/Source/DolphinProcess/Mac/MacDolphinProcess.h @@ -10,7 +10,7 @@ namespace DolphinComm class MacDolphinProcess : public IDolphinProcess { public: - MacDolphinProcess() {} + MacDolphinProcess() = default; bool findPID() override; bool obtainEmuRAMInformations() override; bool readFromRAM(const u32 offset, char* buffer, size_t size, const bool withBSwap) override; diff --git a/Source/DolphinProcess/Windows/WindowsDolphinProcess.h b/Source/DolphinProcess/Windows/WindowsDolphinProcess.h index b12705ab..4c013a33 100644 --- a/Source/DolphinProcess/Windows/WindowsDolphinProcess.h +++ b/Source/DolphinProcess/Windows/WindowsDolphinProcess.h @@ -11,7 +11,7 @@ namespace DolphinComm class WindowsDolphinProcess : public IDolphinProcess { public: - WindowsDolphinProcess() {} + WindowsDolphinProcess() = default; bool findPID() override; bool obtainEmuRAMInformations() override; bool readFromRAM(const u32 offset, char* buffer, const size_t size, diff --git a/Source/GUI/MemScanner/ResultsListModel.cpp b/Source/GUI/MemScanner/ResultsListModel.cpp index 2d4b747f..4664652d 100644 --- a/Source/GUI/MemScanner/ResultsListModel.cpp +++ b/Source/GUI/MemScanner/ResultsListModel.cpp @@ -5,9 +5,7 @@ ResultsListModel::ResultsListModel(QObject* parent, MemScanner* scanner) { } -ResultsListModel::~ResultsListModel() -{ -} +ResultsListModel::~ResultsListModel() = default; int ResultsListModel::columnCount(const QModelIndex& parent) const { From be734e8582577f3207d53c3155de084933571e59 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 17:02:15 +0100 Subject: [PATCH 10/25] Address `hicpp-use-nullptr` warnings. The one warning was: ``` /w/dolphin-memory-engine/Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.cpp:188:22: warning: use nullptr [hicpp-use-nullptr] 188 | txbOffset->setText(0); | ^ | nullptr ``` `0`, which was equivalent to `nullptr`, was being used to implicitly construct an empty `QString` that was then passed to `setText()`, which would do nothing. --- Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.cpp b/Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.cpp index 666362e7..d9cdb75c 100644 --- a/Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.cpp +++ b/Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.cpp @@ -185,7 +185,6 @@ void DlgAddWatchEntry::addPointerOffset() int level = static_cast(m_entry->getPointerLevel()); QLabel* lblLevel = new QLabel(QString::fromStdString("Level " + std::to_string(level + 1) + ":")); QLineEdit* txbOffset = new QLineEdit(); - txbOffset->setText(0); m_offsets.append(txbOffset); QLabel* lblAddressOfPath = new QLabel(" -> "); m_addressPath.append(lblAddressOfPath); From 5a671d8971d7b78624cf9ab6d9f6d1978ed78a9d Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 17:10:51 +0100 Subject: [PATCH 11/25] Address `misc-redundant-expression` warnings. The one warning was: ``` /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.h:116:19: warning: both sides of operator are equivalent [misc-redundant-expression] 116 | if (firstByte != firstByte) | ^ ``` --- Source/MemoryScanner/MemoryScanner.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/MemoryScanner/MemoryScanner.h b/Source/MemoryScanner/MemoryScanner.h index dbc50807..59333946 100644 --- a/Source/MemoryScanner/MemoryScanner.h +++ b/Source/MemoryScanner/MemoryScanner.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -113,8 +114,9 @@ class MemScanner } } - if (firstByte != firstByte) - return CompareResult::nan; + if constexpr (std::is_floating_point::value) + if (std::isnan(firstByte)) + return CompareResult::nan; if (firstByte < (secondByte + convertMemoryToType(offset, offsetInvert))) return CompareResult::smaller; From 1e56dedaf3c6f4588d9596eb3588fd0260f6ebd0 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 17:13:10 +0100 Subject: [PATCH 12/25] Address `misc-throw-by-value-catch-by-reference` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/Common/MemoryCommon.cpp:165:14: warning: catch handler catches by value; should catch by reference instead [misc-throw-by-value-catch-by-reference] 165 | catch (std::invalid_argument) | ^ /w/dolphin-memory-engine/Source/Common/MemoryCommon.cpp:203:14: warning: catch handler catches by value; should catch by reference instead [misc-throw-by-value-catch-by-reference] 203 | catch (std::invalid_argument) | ^ /w/dolphin-memory-engine/Source/Common/MemoryCommon.cpp:239:14: warning: catch handler catches by value; should catch by reference instead [misc-throw-by-value-catch-by-reference] 239 | catch (std::invalid_argument) | ^ ``` --- Source/Common/MemoryCommon.cpp | 6 +++--- Source/MemoryScanner/MemoryScanner.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Common/MemoryCommon.cpp b/Source/Common/MemoryCommon.cpp index 5c12ef0a..90295bac 100644 --- a/Source/Common/MemoryCommon.cpp +++ b/Source/Common/MemoryCommon.cpp @@ -163,7 +163,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen { input = static_cast(std::bitset(inputString).to_ullong()); } - catch (std::invalid_argument) + catch (const std::invalid_argument&) { delete[] buffer; buffer = nullptr; @@ -201,7 +201,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen { input = static_cast(std::bitset(inputString).to_ullong()); } - catch (std::invalid_argument) + catch (const std::invalid_argument&) { delete[] buffer; buffer = nullptr; @@ -237,7 +237,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen { input = static_cast(std::bitset(inputString).to_ullong()); } - catch (std::invalid_argument) + catch (const std::invalid_argument&) { delete[] buffer; buffer = nullptr; diff --git a/Source/MemoryScanner/MemoryScanner.h b/Source/MemoryScanner/MemoryScanner.h index 59333946..4de0032b 100644 --- a/Source/MemoryScanner/MemoryScanner.h +++ b/Source/MemoryScanner/MemoryScanner.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "../Common/CommonTypes.h" From a8af60fa66d293722130f90c8a15bc465b4cb89c Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 17:16:55 +0100 Subject: [PATCH 13/25] Address `modernize-pass-by-value` warnings. The one warning was: ``` /w/dolphin-memory-engine/Source/MemoryWatch/MemWatchTreeNode.cpp:10:56: warning: pass by value and use std::move [modernize-pass-by-value] 6 | 7 | #include "../GUI/GUICommon.h" 8 | 9 | MemWatchTreeNode::MemWatchTreeNode(MemWatchEntry* entry, MemWatchTreeNode* parent, 10 | const bool isGroup, const QString& groupName) | ^~~~~~~~~~~~~~ | QString 11 | : m_entry(entry), m_parent(parent), m_isGroup(isGroup), m_groupName(groupName) | | std::move( ) ``` --- Source/MemoryWatch/MemWatchTreeNode.cpp | 7 ++++--- Source/MemoryWatch/MemWatchTreeNode.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/MemoryWatch/MemWatchTreeNode.cpp b/Source/MemoryWatch/MemWatchTreeNode.cpp index 926ed94d..45ba1103 100644 --- a/Source/MemoryWatch/MemWatchTreeNode.cpp +++ b/Source/MemoryWatch/MemWatchTreeNode.cpp @@ -3,12 +3,13 @@ #include #include +#include #include "../GUI/GUICommon.h" -MemWatchTreeNode::MemWatchTreeNode(MemWatchEntry* entry, MemWatchTreeNode* parent, - const bool isGroup, const QString& groupName) - : m_entry(entry), m_parent(parent), m_isGroup(isGroup), m_groupName(groupName) +MemWatchTreeNode::MemWatchTreeNode(MemWatchEntry* const entry, MemWatchTreeNode* const parent, + const bool isGroup, QString groupName) + : m_entry(entry), m_parent(parent), m_isGroup(isGroup), m_groupName(std::move(groupName)) { } diff --git a/Source/MemoryWatch/MemWatchTreeNode.h b/Source/MemoryWatch/MemWatchTreeNode.h index ef9f4bf0..9e30ffa5 100644 --- a/Source/MemoryWatch/MemWatchTreeNode.h +++ b/Source/MemoryWatch/MemWatchTreeNode.h @@ -9,8 +9,8 @@ class MemWatchTreeNode { public: - MemWatchTreeNode(MemWatchEntry* entry, MemWatchTreeNode* parent = nullptr, - const bool isGroup = false, const QString& groupName = ""); + explicit MemWatchTreeNode(MemWatchEntry* entry, MemWatchTreeNode* parent = nullptr, + bool isGroup = false, QString groupName = {}); MemWatchTreeNode(const MemWatchTreeNode& node); ~MemWatchTreeNode(); From 42254e98feb04205f207d9af87dbf20b5dcc7cf5 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 17:18:36 +0100 Subject: [PATCH 14/25] Address `modernize-use-using` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/Common/CommonTypes.h:5:1: warning: use 'using' instead of 'typedef' [modernize-use-using] 5 | typedef uint64_t u64; | ^~~~~~~~~~~~~~~~~~~~ | using u64 = uint64_t /w/dolphin-memory-engine/Source/Common/CommonTypes.h:6:1: warning: use 'using' instead of 'typedef' [modernize-use-using] 6 | typedef uint32_t u32; | ^~~~~~~~~~~~~~~~~~~~ | using u32 = uint32_t /w/dolphin-memory-engine/Source/Common/CommonTypes.h:7:1: warning: use 'using' instead of 'typedef' [modernize-use-using] 7 | typedef uint16_t u16; | ^~~~~~~~~~~~~~~~~~~~ | using u16 = uint16_t /w/dolphin-memory-engine/Source/Common/CommonTypes.h:8:1: warning: use 'using' instead of 'typedef' [modernize-use-using] 8 | typedef uint8_t u8; | ^~~~~~~~~~~~~~~~~~ | using u8 = uint8_t /w/dolphin-memory-engine/Source/Common/CommonTypes.h:10:1: warning: use 'using' instead of 'typedef' [modernize-use-using] 10 | typedef int64_t s64; | ^~~~~~~~~~~~~~~~~~~ | using s64 = int64_t /w/dolphin-memory-engine/Source/Common/CommonTypes.h:11:1: warning: use 'using' instead of 'typedef' [modernize-use-using] 11 | typedef int32_t s32; | ^~~~~~~~~~~~~~~~~~~ | using s32 = int32_t /w/dolphin-memory-engine/Source/Common/CommonTypes.h:12:1: warning: use 'using' instead of 'typedef' [modernize-use-using] 12 | typedef int16_t s16; | ^~~~~~~~~~~~~~~~~~~ | using s16 = int16_t /w/dolphin-memory-engine/Source/Common/CommonTypes.h:13:1: warning: use 'using' instead of 'typedef' [modernize-use-using] 13 | typedef int8_t s8; | ^~~~~~~~~~~~~~~~~ | using s8 = int8_t ``` --- Source/Common/CommonTypes.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Common/CommonTypes.h b/Source/Common/CommonTypes.h index 29495cbc..c9ea09dd 100755 --- a/Source/Common/CommonTypes.h +++ b/Source/Common/CommonTypes.h @@ -2,12 +2,12 @@ #include -typedef uint64_t u64; -typedef uint32_t u32; -typedef uint16_t u16; -typedef uint8_t u8; +using u64 = uint64_t; +using u32 = uint32_t; +using u16 = uint16_t; +using u8 = uint8_t; -typedef int64_t s64; -typedef int32_t s32; -typedef int16_t s16; -typedef int8_t s8; +using s64 = int64_t; +using s32 = int32_t; +using s16 = int16_t; +using s8 = int8_t; From 825ee35b0041330dd29a45a78d6c16a98dc6594a Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 17:20:52 +0100 Subject: [PATCH 15/25] Address `performance-for-range-copy` warnings. The one warning was: ``` /w/dolphin-memory-engine/Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp:39:15: warning: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy] 39 | for (auto str : lineData) | ^ | const & ``` --- Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp b/Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp index 7ed406cc..56afb504 100644 --- a/Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp +++ b/Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp @@ -36,7 +36,7 @@ bool LinuxDolphinProcess::obtainEmuRAMInformations() continue; bool foundDevShmDolphin = false; - for (auto str : lineData) + for (const std::string& str : lineData) { if (str.substr(0, 19) == "/dev/shm/dolphinmem" || str.substr(0, 20) == "/dev/shm/dolphin-emu") { From c5d61d3a366bd2e4b6c35ccbc92246c2a8252d1e Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 18:31:39 +0100 Subject: [PATCH 16/25] Address `performance-unnecessary-value-param` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/Common/MemoryCommon.cpp:127:46: warning: the const qualified parameter 'inputString' is copied for each invocation; consider making it a reference [performance-unnecessary-value-param] 127 | const std::string inputString, const MemBase base, const MemType type, | ^ | & /w/dolphin-memory-engine/Source/GUI/MemCopy/DlgCopy.cpp:180:42: warning: the parameter 'str' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] 180 | bool DlgCopy::hexStringToU32(std::string str, u32& output) | ^ | const & /w/dolphin-memory-engine/Source/GUI/MemCopy/DlgCopy.cpp:197:51: warning: the parameter 'str' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] 197 | bool DlgCopy::isUnsignedIntegerString(std::string str) | ^ | const & /w/dolphin-memory-engine/Source/GUI/MemCopy/DlgCopy.cpp:210:43: warning: the parameter 'str' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] 210 | bool DlgCopy::uintStringToU32(std::string str, u32& output) | ^ | const & /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchModel.cpp:400:72: warning: the const qualified parameter 'nodes' is copied for each invocation; consider making it a reference [performance-unnecessary-value-param] 400 | MemWatchModel::getLeastDeepNodeFromList(const QList nodes) const | ^ | & /w/dolphin-memory-engine/Source/MemoryWatch/MemWatchEntry.cpp:13:44: warning: the const qualified parameter 'label' is copied for each invocation; consider making it a reference [performance-unnecessary-value-param] 13 | MemWatchEntry::MemWatchEntry(const QString label, const u32 consoleAddress, | ^ | & /w/dolphin-memory-engine/Source/MemoryWatch/MemWatchTreeNode.cpp:86:16: warning: parameter 'children' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param] 6 | m_children = children; | ^ | std::move( ) ``` --- Source/Common/MemoryCommon.cpp | 24 +++++++++++++++--------- Source/Common/MemoryCommon.h | 4 ++-- Source/GUI/MemCopy/DlgCopy.cpp | 13 +++++++------ Source/GUI/MemCopy/DlgCopy.h | 10 ++++++---- Source/GUI/MemWatcher/MemWatchModel.cpp | 2 +- Source/GUI/MemWatcher/MemWatchModel.h | 2 +- Source/MemoryWatch/MemWatchEntry.cpp | 10 +++++----- Source/MemoryWatch/MemWatchEntry.h | 7 +++---- Source/MemoryWatch/MemWatchTreeNode.cpp | 2 +- 9 files changed, 41 insertions(+), 33 deletions(-) diff --git a/Source/Common/MemoryCommon.cpp b/Source/Common/MemoryCommon.cpp index 90295bac..239aeb88 100644 --- a/Source/Common/MemoryCommon.cpp +++ b/Source/Common/MemoryCommon.cpp @@ -125,8 +125,8 @@ int getNbrBytesAlignmentForType(const MemType type) } char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLength, - const std::string inputString, const MemBase base, const MemType type, - const size_t length) + const std::string_view inputString, const MemBase base, + const MemType type, const size_t length) { if (inputString.length() == 0) { @@ -134,7 +134,8 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen return nullptr; } - std::stringstream ss(inputString); + std::stringstream ss; + ss << inputString; switch (base) { case MemBase::base_octal: @@ -161,7 +162,8 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen u8 input{}; try { - input = static_cast(std::bitset(inputString).to_ullong()); + input = static_cast( + std::bitset(inputString.data(), inputString.size()).to_ullong()); } catch (const std::invalid_argument&) { @@ -199,7 +201,8 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen u16 input{}; try { - input = static_cast(std::bitset(inputString).to_ullong()); + input = static_cast( + std::bitset(inputString.data(), inputString.size()).to_ullong()); } catch (const std::invalid_argument&) { @@ -235,7 +238,8 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen u32 input{}; try { - input = static_cast(std::bitset(inputString).to_ullong()); + input = static_cast( + std::bitset(inputString.data(), inputString.size()).to_ullong()); } catch (const std::invalid_argument&) { @@ -273,7 +277,8 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen u32 input{}; try { - input = static_cast(std::bitset(inputString).to_ullong()); + input = static_cast( + std::bitset(inputString.data(), inputString.size()).to_ullong()); } catch (const std::invalid_argument&) { @@ -326,7 +331,8 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen u64 input{}; try { - input = static_cast(std::bitset(inputString).to_ullong()); + input = static_cast( + std::bitset(inputString.data(), inputString.size()).to_ullong()); } catch (const std::invalid_argument&) { @@ -378,7 +384,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen returnCode = MemOperationReturnCode::inputTooLong; return buffer; } - std::memcpy(buffer, inputString.c_str(), length); + std::memcpy(buffer, inputString.data(), length); actualLength = length; break; } diff --git a/Source/Common/MemoryCommon.h b/Source/Common/MemoryCommon.h index 0d0bd38b..3c2fa68b 100644 --- a/Source/Common/MemoryCommon.h +++ b/Source/Common/MemoryCommon.h @@ -2,6 +2,7 @@ #include #include +#include #include "CommonTypes.h" @@ -58,8 +59,7 @@ size_t getSizeForType(const MemType type, const size_t length); bool shouldBeBSwappedForType(const MemType type); int getNbrBytesAlignmentForType(const MemType type); char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLength, - const std::string inputString, const MemBase base, const MemType type, - const size_t length); + std::string_view inputString, MemBase base, MemType type, size_t length); std::string formatMemoryToString(const char* memory, const MemType type, const size_t length, const MemBase base, const bool isUnsigned, const bool withBSwap = false); diff --git a/Source/GUI/MemCopy/DlgCopy.cpp b/Source/GUI/MemCopy/DlgCopy.cpp index c4b35e2e..df6f8abf 100644 --- a/Source/GUI/MemCopy/DlgCopy.cpp +++ b/Source/GUI/MemCopy/DlgCopy.cpp @@ -159,7 +159,7 @@ void DlgCopy::updateMemoryText() static_cast(m_cmbViewerBytesSeparator->currentIndex())))); } -bool DlgCopy::isHexString(std::string str) +bool DlgCopy::isHexString(std::string_view str) { if (str.length() > 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) { @@ -177,7 +177,7 @@ bool DlgCopy::isHexString(std::string str) return true; } -bool DlgCopy::hexStringToU32(std::string str, u32& output) +bool DlgCopy::hexStringToU32(const std::string_view str, u32& output) { // if (str.empty() || str.length() % 2 == 1) if (str.empty()) @@ -186,7 +186,8 @@ bool DlgCopy::hexStringToU32(std::string str, u32& output) if (!isHexString(str)) return false; - std::stringstream ss(str); + std::stringstream ss; + ss << str; ss >> std::hex; ss >> output; @@ -194,7 +195,7 @@ bool DlgCopy::hexStringToU32(std::string str, u32& output) return true; } -bool DlgCopy::isUnsignedIntegerString(std::string str) +bool DlgCopy::isUnsignedIntegerString(const std::string_view str) { for (char c : str) { @@ -207,12 +208,12 @@ bool DlgCopy::isUnsignedIntegerString(std::string str) return true; } -bool DlgCopy::uintStringToU32(std::string str, u32& output) +bool DlgCopy::uintStringToU32(const std::string_view str, u32& output) { if (!isUnsignedIntegerString(str) || str.empty() || str.length() > 10) return false; - u64 u = std::stoll(str); + const auto u{static_cast(std::stoll(std::string{str}))}; if (u > ULONG_MAX) return false; diff --git a/Source/GUI/MemCopy/DlgCopy.h b/Source/GUI/MemCopy/DlgCopy.h index 45499811..b005280a 100644 --- a/Source/GUI/MemCopy/DlgCopy.h +++ b/Source/GUI/MemCopy/DlgCopy.h @@ -1,5 +1,7 @@ #pragma once +#include + #include #include #include @@ -30,10 +32,10 @@ class DlgCopy : public QDialog bool copyMemory(); void updateMemoryText(); - static bool hexStringToU32(std::string str, u32& output); - static bool isHexString(std::string str); - static bool isUnsignedIntegerString(std::string str); - static bool uintStringToU32(std::string str, u32& output); + static bool hexStringToU32(std::string_view str, u32& output); + static bool isHexString(std::string_view str); + static bool isUnsignedIntegerString(std::string_view str); + static bool uintStringToU32(std::string_view str, u32& output); static std::string charToHexString(char* input, size_t count, ByteStringFormats format); QLineEdit* m_spnWatcherCopyAddress; diff --git a/Source/GUI/MemWatcher/MemWatchModel.cpp b/Source/GUI/MemWatcher/MemWatchModel.cpp index 2af2e170..8f030f58 100644 --- a/Source/GUI/MemWatcher/MemWatchModel.cpp +++ b/Source/GUI/MemWatcher/MemWatchModel.cpp @@ -399,7 +399,7 @@ int MemWatchModel::getNodeDeepness(const MemWatchTreeNode* node) const } MemWatchTreeNode* -MemWatchModel::getLeastDeepNodeFromList(const QList nodes) const +MemWatchModel::getLeastDeepNodeFromList(const QList& nodes) const { int leastLevelFound = std::numeric_limits::max(); MemWatchTreeNode* returnNode = new MemWatchTreeNode(nullptr); diff --git a/Source/GUI/MemWatcher/MemWatchModel.h b/Source/GUI/MemWatcher/MemWatchModel.h index 1e89fead..803314c5 100644 --- a/Source/GUI/MemWatcher/MemWatchModel.h +++ b/Source/GUI/MemWatcher/MemWatchModel.h @@ -80,7 +80,7 @@ class MemWatchModel : public QAbstractItemModel bool freezeNodeValueRecursive(MemWatchTreeNode* node, const QModelIndex& parent = QModelIndex(), const bool writeSucess = true); QString getAddressString(const MemWatchEntry* entry) const; - MemWatchTreeNode* getLeastDeepNodeFromList(const QList nodes) const; + MemWatchTreeNode* getLeastDeepNodeFromList(const QList& nodes) const; int getNodeDeepness(const MemWatchTreeNode* node) const; MemWatchTreeNode* m_rootNode; diff --git a/Source/MemoryWatch/MemWatchEntry.cpp b/Source/MemoryWatch/MemWatchEntry.cpp index e6bacd31..86a414a4 100644 --- a/Source/MemoryWatch/MemWatchEntry.cpp +++ b/Source/MemoryWatch/MemWatchEntry.cpp @@ -6,16 +6,16 @@ #include #include #include +#include #include "../Common/CommonUtils.h" #include "../DolphinProcess/DolphinAccessor.h" -MemWatchEntry::MemWatchEntry(const QString label, const u32 consoleAddress, - const Common::MemType type, const Common::MemBase base, - const bool isUnsigned, const size_t length, +MemWatchEntry::MemWatchEntry(QString label, const u32 consoleAddress, const Common::MemType type, + const Common::MemBase base, const bool isUnsigned, const size_t length, const bool isBoundToPointer) - : m_label(label), m_consoleAddress(consoleAddress), m_type(type), m_isUnsigned(isUnsigned), - m_base(base), m_boundToPointer(isBoundToPointer), m_length(length) + : m_label(std::move(label)), m_consoleAddress(consoleAddress), m_type(type), + m_isUnsigned(isUnsigned), m_base(base), m_boundToPointer(isBoundToPointer), m_length(length) { m_memory = new char[getSizeForType(m_type, m_length)]; } diff --git a/Source/MemoryWatch/MemWatchEntry.h b/Source/MemoryWatch/MemWatchEntry.h index 781bbd6d..83af72ea 100644 --- a/Source/MemoryWatch/MemWatchEntry.h +++ b/Source/MemoryWatch/MemWatchEntry.h @@ -12,10 +12,9 @@ class MemWatchEntry { public: MemWatchEntry(); - MemWatchEntry(const QString label, const u32 consoleAddress, const Common::MemType type, - const Common::MemBase = Common::MemBase::base_decimal, - const bool m_isUnsigned = false, const size_t length = 1, - const bool isBoundToPointer = false); + MemWatchEntry(QString label, u32 consoleAddress, Common::MemType type, + Common::MemBase = Common::MemBase::base_decimal, bool m_isUnsigned = false, + size_t length = 1, bool isBoundToPointer = false); MemWatchEntry(MemWatchEntry* entry); ~MemWatchEntry(); diff --git a/Source/MemoryWatch/MemWatchTreeNode.cpp b/Source/MemoryWatch/MemWatchTreeNode.cpp index 45ba1103..388028d1 100644 --- a/Source/MemoryWatch/MemWatchTreeNode.cpp +++ b/Source/MemoryWatch/MemWatchTreeNode.cpp @@ -84,7 +84,7 @@ QVector MemWatchTreeNode::getChildren() const void MemWatchTreeNode::setChildren(QVector children) { - m_children = children; + m_children = std::move(children); } MemWatchTreeNode* MemWatchTreeNode::getParent() const From c32f48fcbfe056e3fd7fc2243e69a78824b0ff76 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 18:35:51 +0100 Subject: [PATCH 17/25] Address `readability-container-size-empty` warnings. The one warning was: ``` /w/dolphin-memory-engine/Source/Common/MemoryCommon.cpp:130:7: warning: the 'empty' method should be used to check for emptiness instead of 'length' [readability-container-size-empty] 130 | if (inputString.length() == 0) | ^~~~~~~~~~~~~~~~~~~~~~~~~ | inputString.empty() /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/basic_string.h:1191:7: note: method 'basic_string'::empty() defined here 1191 | empty() const _GLIBCXX_NOEXCEPT | ^ ``` --- Source/Common/MemoryCommon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Common/MemoryCommon.cpp b/Source/Common/MemoryCommon.cpp index 239aeb88..aa2ba8ab 100644 --- a/Source/Common/MemoryCommon.cpp +++ b/Source/Common/MemoryCommon.cpp @@ -128,7 +128,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen const std::string_view inputString, const MemBase base, const MemType type, const size_t length) { - if (inputString.length() == 0) + if (inputString.empty()) { returnCode = MemOperationReturnCode::invalidInput; return nullptr; From 2ed89f691ebb823e5dcc4b78027f4d9f97ac44a8 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 18:48:05 +0100 Subject: [PATCH 18/25] Address `readability-convert-member-functions-to-static` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/CheatEngineParser/CheatEngineParser.cpp:365:28: warning: method 'formatImportedEntryBasicInfo' can be made static [readability-convert-member-functions-to-static] 365 | QString CheatEngineParser::formatImportedEntryBasicInfo(const MemWatchEntry* entry) const | ^ ~~~~~ /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchModel.cpp:95:31: warning: method 'getEntryFromIndex' can be made static [readability-convert-member-functions-to-static] 95 | MemWatchEntry* MemWatchModel::getEntryFromIndex(const QModelIndex& index) const | ^ ~~~~~ /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchModel.cpp:625:24: warning: method 'getAddressString' can be made static [readability-convert-member-functions-to-static] 625 | QString MemWatchModel::getAddressString(const MemWatchEntry* entry) const | ^ ~~~~~ /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchModel.cpp:688:34: warning: method 'getTreeNodeFromIndex' can be made static [readability-convert-member-functions-to-static] 688 | MemWatchTreeNode* MemWatchModel::getTreeNodeFromIndex(const QModelIndex& index) const | ^ ~~~~~ /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.cpp:476:17: warning: method 'getTermsNumForFilter' can be made static [readability-convert-member-functions-to-static] 476 | int MemScanner::getTermsNumForFilter(const MemScanner::ScanFiter filter) const | ^ ~~~~~ /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.cpp:488:18: warning: method 'typeSupportsAdditionalOptions' can be made static [readability-convert-member-functions-to-static] 488 | bool MemScanner::typeSupportsAdditionalOptions(const Common::MemType type) const | ^ ~~~~~ /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.cpp:526:25: warning: method 'addSpacesToBytesArrays' can be made static [readability-convert-member-functions-to-static] 526 | std::string MemScanner::addSpacesToBytesArrays(const std::string& bytesArray) const | ^ ~~~~~ ``` --- .../CheatEngineParser/CheatEngineParser.cpp | 2 +- Source/CheatEngineParser/CheatEngineParser.h | 2 +- Source/GUI/MemWatcher/MemWatchModel.cpp | 37 ++++++++------- Source/GUI/MemWatcher/MemWatchModel.h | 5 +- Source/MemoryScanner/MemoryScanner.cpp | 47 ++++++++++--------- Source/MemoryScanner/MemoryScanner.h | 5 +- 6 files changed, 52 insertions(+), 46 deletions(-) diff --git a/Source/CheatEngineParser/CheatEngineParser.cpp b/Source/CheatEngineParser/CheatEngineParser.cpp index 7b576d15..b4f3088a 100644 --- a/Source/CheatEngineParser/CheatEngineParser.cpp +++ b/Source/CheatEngineParser/CheatEngineParser.cpp @@ -359,7 +359,7 @@ void CheatEngineParser::verifyCheatEntryParsingErrors(cheatEntryParsingState sta } } -QString CheatEngineParser::formatImportedEntryBasicInfo(const MemWatchEntry* entry) const +QString CheatEngineParser::formatImportedEntryBasicInfo(const MemWatchEntry* const entry) { QString formatedEntry = ""; formatedEntry += "Label: " + entry->getLabel() + "\n"; diff --git a/Source/CheatEngineParser/CheatEngineParser.h b/Source/CheatEngineParser/CheatEngineParser.h index d92b955d..a607e75b 100644 --- a/Source/CheatEngineParser/CheatEngineParser.h +++ b/Source/CheatEngineParser/CheatEngineParser.h @@ -38,7 +38,7 @@ class CheatEngineParser void parseCheatEntry(MemWatchTreeNode* node, const bool useDolphinPointer); void verifyCheatEntryParsingErrors(cheatEntryParsingState state, MemWatchEntry* entry, bool isGroup, const bool useDolphinPointer); - QString formatImportedEntryBasicInfo(const MemWatchEntry* entry) const; + static QString formatImportedEntryBasicInfo(const MemWatchEntry* entry); u64 m_tableStartAddress = 0; QString m_errorMessages = ""; diff --git a/Source/GUI/MemWatcher/MemWatchModel.cpp b/Source/GUI/MemWatcher/MemWatchModel.cpp index 8f030f58..949e4658 100644 --- a/Source/GUI/MemWatcher/MemWatchModel.cpp +++ b/Source/GUI/MemWatcher/MemWatchModel.cpp @@ -11,6 +11,24 @@ #include "../../Common/CommonUtils.h" #include "../GUICommon.h" +namespace +{ +QString getAddressString(const MemWatchEntry* const entry) +{ + std::stringstream ss; + if (entry->isBoundToPointer()) + { + int level = static_cast(entry->getPointerLevel()); + std::string strAddress = entry->getAddressStringForPointerLevel(level); + ss << "(" << level << "*)" << std::hex << std::uppercase << strAddress; + return QString::fromStdString(ss.str()); + } + u32 address = entry->getConsoleAddress(); + ss << std::hex << std::uppercase << address; + return QString::fromStdString(ss.str()); +} +} // namespace + MemWatchModel::MemWatchModel(QObject* parent) : QAbstractItemModel(parent) { m_rootNode = new MemWatchTreeNode(nullptr); @@ -94,7 +112,7 @@ void MemWatchModel::changeType(const QModelIndex& index, Common::MemType type, s emit dataChanged(index, index); } -MemWatchEntry* MemWatchModel::getEntryFromIndex(const QModelIndex& index) const +MemWatchEntry* MemWatchModel::getEntryFromIndex(const QModelIndex& index) { MemWatchTreeNode* node = static_cast(index.internalPointer()); return node->getEntry(); @@ -621,21 +639,6 @@ void MemWatchModel::sortRecursive(int column, Qt::SortOrder order, MemWatchTreeN } } -QString MemWatchModel::getAddressString(const MemWatchEntry* entry) const -{ - std::stringstream ss; - if (entry->isBoundToPointer()) - { - int level = static_cast(entry->getPointerLevel()); - std::string strAddress = entry->getAddressStringForPointerLevel(level); - ss << "(" << level << "*)" << std::hex << std::uppercase << strAddress; - return QString::fromStdString(ss.str()); - } - u32 address = entry->getConsoleAddress(); - ss << std::hex << std::uppercase << address; - return QString::fromStdString(ss.str()); -} - void MemWatchModel::loadRootFromJsonRecursive(const QJsonObject& json) { m_rootNode->readFromJson(json); @@ -684,7 +687,7 @@ MemWatchTreeNode* MemWatchModel::getRootNode() const return m_rootNode; } -MemWatchTreeNode* MemWatchModel::getTreeNodeFromIndex(const QModelIndex& index) const +MemWatchTreeNode* MemWatchModel::getTreeNodeFromIndex(const QModelIndex& index) { return static_cast(index.internalPointer()); } diff --git a/Source/GUI/MemWatcher/MemWatchModel.h b/Source/GUI/MemWatcher/MemWatchModel.h index 803314c5..20425b2d 100644 --- a/Source/GUI/MemWatcher/MemWatchModel.h +++ b/Source/GUI/MemWatcher/MemWatchModel.h @@ -49,7 +49,7 @@ class MemWatchModel : public QAbstractItemModel const QModelIndex& parent) override; void changeType(const QModelIndex& index, const Common::MemType type, const size_t length); - MemWatchEntry* getEntryFromIndex(const QModelIndex& index) const; + static MemWatchEntry* getEntryFromIndex(const QModelIndex& index); void addGroup(const QString& name); void addEntry(MemWatchEntry* entry); void editEntry(MemWatchEntry* entry, const QModelIndex& index); @@ -65,7 +65,7 @@ class MemWatchModel : public QAbstractItemModel QString writeRootToCSVStringRecursive() const; bool hasAnyNodes() const; MemWatchTreeNode* getRootNode() const; - MemWatchTreeNode* getTreeNodeFromIndex(const QModelIndex& index) const; + static MemWatchTreeNode* getTreeNodeFromIndex(const QModelIndex& index); bool editData(const QModelIndex& index, const QVariant& value, int role, bool emitEdit = false); signals: @@ -79,7 +79,6 @@ class MemWatchModel : public QAbstractItemModel const bool readSucess = true); bool freezeNodeValueRecursive(MemWatchTreeNode* node, const QModelIndex& parent = QModelIndex(), const bool writeSucess = true); - QString getAddressString(const MemWatchEntry* entry) const; MemWatchTreeNode* getLeastDeepNodeFromList(const QList& nodes) const; int getNodeDeepness(const MemWatchTreeNode* node) const; diff --git a/Source/MemoryScanner/MemoryScanner.cpp b/Source/MemoryScanner/MemoryScanner.cpp index c3f7f45c..54474541 100644 --- a/Source/MemoryScanner/MemoryScanner.cpp +++ b/Source/MemoryScanner/MemoryScanner.cpp @@ -1,8 +1,32 @@ #include "MemoryScanner.h" +#include + #include "../Common/CommonUtils.h" #include "../DolphinProcess/DolphinAccessor.h" +namespace +{ +std::string addSpacesToBytesArrays(const std::string_view bytesArray) +{ + std::string result(bytesArray); + int spacesAdded = 0; + for (int i = 2; i < bytesArray.length(); i += 2) + { + if (bytesArray[i] != ' ') + { + result.insert(i + spacesAdded, 1, ' '); + spacesAdded++; + } + else + { + i++; + } + } + return result; +} +} // namespace + MemScanner::MemScanner() : m_resultsConsoleAddr(std::vector()) { } @@ -473,7 +497,7 @@ bool MemScanner::setSearchRangeEnd(u32 endRange) return true; } -int MemScanner::getTermsNumForFilter(const MemScanner::ScanFiter filter) const +int MemScanner::getTermsNumForFilter(const MemScanner::ScanFiter filter) { if (filter == MemScanner::ScanFiter::between) return 2; @@ -485,7 +509,7 @@ int MemScanner::getTermsNumForFilter(const MemScanner::ScanFiter filter) const return 0; } -bool MemScanner::typeSupportsAdditionalOptions(const Common::MemType type) const +bool MemScanner::typeSupportsAdditionalOptions(const Common::MemType type) { return (type == Common::MemType::type_byte || type == Common::MemType::type_halfword || type == Common::MemType::type_word); @@ -524,25 +548,6 @@ void MemScanner::removeResultAt(int index) m_resultCount--; } -std::string MemScanner::addSpacesToBytesArrays(const std::string& bytesArray) const -{ - std::string result(bytesArray); - int spacesAdded = 0; - for (int i = 2; i < bytesArray.length(); i += 2) - { - if (bytesArray[i] != ' ') - { - result.insert(i + spacesAdded, 1, ' '); - spacesAdded++; - } - else - { - i++; - } - } - return result; -} - bool MemScanner::undoScan() { if (m_undoCount > 0) diff --git a/Source/MemoryScanner/MemoryScanner.h b/Source/MemoryScanner/MemoryScanner.h index 4de0032b..45aa29dd 100644 --- a/Source/MemoryScanner/MemoryScanner.h +++ b/Source/MemoryScanner/MemoryScanner.h @@ -140,7 +140,7 @@ class MemScanner size_t getResultCount() const; bool hasUndo() const; size_t getUndoCount() const; - int getTermsNumForFilter(const ScanFiter filter) const; + static int getTermsNumForFilter(ScanFiter filter); Common::MemType getType() const; Common::MemBase getBase() const; size_t getLength() const; @@ -148,7 +148,7 @@ class MemScanner std::string getFormattedScannedValueAt(const int index) const; std::string getFormattedCurrentValueAt(int index) const; void removeResultAt(int index); - bool typeSupportsAdditionalOptions(const Common::MemType type) const; + static bool typeSupportsAdditionalOptions(Common::MemType type); bool hasScanStarted() const; private: @@ -156,7 +156,6 @@ class MemScanner const char* memoryToCompare2, const char* noOffset, const char* newerRAMCache, const size_t realSize, const u32 consoleOffset) const; - std::string addSpacesToBytesArrays(const std::string& bytesArray) const; bool m_searchInRangeBegin = false; bool m_searchInRangeEnd = false; From b826aa3439cce657608c68462f8cf813d915d627 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 20:53:18 +0100 Subject: [PATCH 19/25] Address `readability-inconsistent-declaration-parameter-name` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.h:132:8: warning: function 'MemScanner::setSearchRangeBegin' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name] 132 | bool setSearchRangeBegin(u32 beginIndex); | ^ /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.cpp:446:18: note: the definition seen here 446 | bool MemScanner::setSearchRangeBegin(u32 beginRange) | ^ /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.h:132:8: note: differing parameters are named here: ('beginIndex'), in definition: ('beginRange') 132 | bool setSearchRangeBegin(u32 beginIndex); | ^ ~~~~~~~~~~ | beginRange /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.h:133:8: warning: function 'MemScanner::setSearchRangeEnd' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name] 133 | bool setSearchRangeEnd(u32 endIndex); | ^ /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.cpp:461:18: note: the definition seen here 461 | bool MemScanner::setSearchRangeEnd(u32 endRange) | ^ /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.h:133:8: note: differing parameters are named here: ('endIndex'), in definition: ('endRange') 133 | bool setSearchRangeEnd(u32 endIndex); | ^ ~~~~~~~~ | endRange /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.h:134:8: warning: function 'MemScanner::setSearchRange' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name] 134 | bool setSearchRange(u32 beginIndex, u32 endIndex); | ^ /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.cpp:428:18: note: the definition seen here 428 | bool MemScanner::setSearchRange(u32 beginRange, u32 endRange) | ^ /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.h:134:8: note: differing parameters are named here: ('beginIndex', 'endIndex'), in definition: ('beginRange', 'endRange') 134 | bool setSearchRange(u32 beginIndex, u32 endIndex); | ^ ~~~~~~~~~~ ~~~~~~~~ | beginRange endRange ``` --- Source/MemoryScanner/MemoryScanner.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/MemoryScanner/MemoryScanner.h b/Source/MemoryScanner/MemoryScanner.h index 45aa29dd..f52b1621 100644 --- a/Source/MemoryScanner/MemoryScanner.h +++ b/Source/MemoryScanner/MemoryScanner.h @@ -132,9 +132,9 @@ class MemScanner void setEnforceMemAlignment(const bool enforceAlignment); void setIsSigned(const bool isSigned); void resetSearchRange(); - bool setSearchRangeBegin(u32 beginIndex); - bool setSearchRangeEnd(u32 endIndex); - bool setSearchRange(u32 beginIndex, u32 endIndex); + bool setSearchRangeBegin(u32 beginRange); + bool setSearchRangeEnd(u32 endRange); + bool setSearchRange(u32 beginRange, u32 endRange); std::vector getResultsConsoleAddr() const; size_t getResultCount() const; From 043012d2763d96ab8fb6162023a4c222da53be9c Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 20:59:18 +0100 Subject: [PATCH 20/25] Address `readability-non-const-parameter` warnings. The one warning was: ``` /w/dolphin-memory-engine/Source/GUI/MemCopy/DlgCopy.cpp:225:44: warning: pointer parameter 'input' can be pointer to const [readability-non-const-parameter] 225 | std::string DlgCopy::charToHexString(char* input, size_t count, DlgCopy::ByteStringFormats format) | ^ | const ``` --- Source/GUI/MemCopy/DlgCopy.cpp | 3 ++- Source/GUI/MemCopy/DlgCopy.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/GUI/MemCopy/DlgCopy.cpp b/Source/GUI/MemCopy/DlgCopy.cpp index df6f8abf..c0283c03 100644 --- a/Source/GUI/MemCopy/DlgCopy.cpp +++ b/Source/GUI/MemCopy/DlgCopy.cpp @@ -222,7 +222,8 @@ bool DlgCopy::uintStringToU32(const std::string_view str, u32& output) return true; } -std::string DlgCopy::charToHexString(char* input, size_t count, DlgCopy::ByteStringFormats format) +std::string DlgCopy::charToHexString(const char* const input, const size_t count, + const DlgCopy::ByteStringFormats format) { std::stringstream ss; const char convert[16] = {'0', '1', '2', '3', '4', '5', '6', '7', diff --git a/Source/GUI/MemCopy/DlgCopy.h b/Source/GUI/MemCopy/DlgCopy.h index b005280a..63bb4649 100644 --- a/Source/GUI/MemCopy/DlgCopy.h +++ b/Source/GUI/MemCopy/DlgCopy.h @@ -36,7 +36,7 @@ class DlgCopy : public QDialog static bool isHexString(std::string_view str); static bool isUnsignedIntegerString(std::string_view str); static bool uintStringToU32(std::string_view str, u32& output); - static std::string charToHexString(char* input, size_t count, ByteStringFormats format); + static std::string charToHexString(const char* input, size_t count, ByteStringFormats format); QLineEdit* m_spnWatcherCopyAddress; QLineEdit* m_spnWatcherCopySize; From 6bd459ba593f2c4f5d5404d2b4e75dcf0ee1faba Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 21:58:46 +0100 Subject: [PATCH 21/25] Address `readability-qualified-auto` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchModel.cpp:60:10: warning: 'auto i' can be declared as 'auto *i' [readability-qualified-auto] 60 | for (auto i : children) | ^~~~ | auto * /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchModel.cpp:84:10: warning: 'auto i' can be declared as 'auto *i' [readability-qualified-auto] 84 | for (auto i : children) | ^~~~ | auto * /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchModel.cpp:424:8: warning: 'auto i' can be declared as 'auto *i' [readability-qualified-auto] 424 | for (auto i : nodes) | ^~~~ | auto * /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchModel.cpp:634:8: warning: 'auto i' can be declared as 'auto *i' [readability-qualified-auto] 634 | for (auto i : parent->getChildren()) | ^~~~ | auto * /w/dolphin-memory-engine/Source/GUI/MemWatcher/MemWatchWidget.cpp:348:10: warning: 'auto i' can be declared as 'auto *i' [readability-qualified-auto] 348 | for (auto i : copiedRootNode->getChildren()) | ^~~~ | auto * /w/dolphin-memory-engine/Source/MemoryWatch/MemWatchTreeNode.cpp:193:10: warning: 'auto i' can be declared as 'auto *i' [readability-qualified-auto] 193 | for (auto i : m_children) | ^~~~ | auto * /w/dolphin-memory-engine/Source/MemoryWatch/MemWatchTreeNode.cpp:206:12: warning: 'auto i' can be declared as 'auto *i' [readability-qualified-auto] 206 | for (auto i : m_children) | ^~~~ | auto * /w/dolphin-memory-engine/Source/MemoryWatch/MemWatchTreeNode.cpp:247:10: warning: 'auto i' can be declared as 'auto *i' [readability-qualified-auto] 247 | for (auto i : m_children) | ^~~~ | auto * ``` --- Source/GUI/MemWatcher/MemWatchModel.cpp | 28 +++++++++++++----------- Source/GUI/MemWatcher/MemWatchWidget.cpp | 6 ++--- Source/MemoryWatch/MemWatchTreeNode.cpp | 12 +++++----- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Source/GUI/MemWatcher/MemWatchModel.cpp b/Source/GUI/MemWatcher/MemWatchModel.cpp index 949e4658..aa4d4ad4 100644 --- a/Source/GUI/MemWatcher/MemWatchModel.cpp +++ b/Source/GUI/MemWatcher/MemWatchModel.cpp @@ -57,13 +57,13 @@ bool MemWatchModel::updateNodeValueRecursive(MemWatchTreeNode* node, const QMode QVector children = node->getChildren(); if (children.count() > 0) { - for (auto i : children) + for (MemWatchTreeNode* const child : children) { - QModelIndex theIndex = index(i->getRow(), WATCH_COL_VALUE, parent); - readSucess = updateNodeValueRecursive(i, theIndex, readSucess); + QModelIndex theIndex = index(child->getRow(), WATCH_COL_VALUE, parent); + readSucess = updateNodeValueRecursive(child, theIndex, readSucess); if (!readSucess) return false; - if (!GUICommon::g_valueEditing && !i->isGroup()) + if (!GUICommon::g_valueEditing && !child->isGroup()) emit dataChanged(theIndex, theIndex); } } @@ -81,10 +81,10 @@ bool MemWatchModel::freezeNodeValueRecursive(MemWatchTreeNode* node, const QMode QVector children = node->getChildren(); if (children.count() > 0) { - for (auto i : children) + for (MemWatchTreeNode* const child : children) { - QModelIndex theIndex = index(i->getRow(), WATCH_COL_VALUE, parent); - writeSucess = freezeNodeValueRecursive(i, theIndex, writeSucess); + QModelIndex theIndex = index(child->getRow(), WATCH_COL_VALUE, parent); + writeSucess = freezeNodeValueRecursive(child, theIndex, writeSucess); if (!writeSucess) return false; } @@ -421,12 +421,12 @@ MemWatchModel::getLeastDeepNodeFromList(const QList& nodes) c { int leastLevelFound = std::numeric_limits::max(); MemWatchTreeNode* returnNode = new MemWatchTreeNode(nullptr); - for (auto i : nodes) + for (MemWatchTreeNode* const node : nodes) { - int deepness = getNodeDeepness(i); + int deepness = getNodeDeepness(node); if (deepness < leastLevelFound) { - returnNode = i; + returnNode = node; leastLevelFound = deepness; } } @@ -632,10 +632,12 @@ void MemWatchModel::sortRecursive(int column, Qt::SortOrder order, MemWatchTreeN parent->setChildren(children); - for (auto i : parent->getChildren()) + for (MemWatchTreeNode* const child : parent->getChildren()) { - if (i->isGroup()) - sortRecursive(column, order, i); + if (child->isGroup()) + { + sortRecursive(column, order, child); + } } } diff --git a/Source/GUI/MemWatcher/MemWatchWidget.cpp b/Source/GUI/MemWatcher/MemWatchWidget.cpp index 0d0761d8..51ece341 100644 --- a/Source/GUI/MemWatcher/MemWatchWidget.cpp +++ b/Source/GUI/MemWatcher/MemWatchWidget.cpp @@ -345,17 +345,17 @@ void MemWatchWidget::pasteWatchFromClipBoard(MemWatchTreeNode* node, int row) if (copiedRootNode->hasChildren()) { int numberIterated = 0; - for (auto i : copiedRootNode->getChildren()) + for (MemWatchTreeNode* const child : copiedRootNode->getChildren()) { if (node == nullptr) node = m_watchModel->getRootNode(); if (node->isGroup() || (node->getParent() == nullptr)) { - node->appendChild(i); + node->appendChild(child); } else { - node->getParent()->insertChild(row + numberIterated, i); + node->getParent()->insertChild(row + numberIterated, child); } numberIterated++; } diff --git a/Source/MemoryWatch/MemWatchTreeNode.cpp b/Source/MemoryWatch/MemWatchTreeNode.cpp index 388028d1..6c88f888 100644 --- a/Source/MemoryWatch/MemWatchTreeNode.cpp +++ b/Source/MemoryWatch/MemWatchTreeNode.cpp @@ -190,10 +190,10 @@ void MemWatchTreeNode::writeToJson(QJsonObject& json) const { json["groupName"] = m_groupName; QJsonArray entries; - for (auto i : m_children) + for (MemWatchTreeNode* const child : m_children) { QJsonObject theNode; - i->writeToJson(theNode); + child->writeToJson(theNode); entries.append(theNode); } json["groupEntries"] = entries; @@ -203,10 +203,10 @@ void MemWatchTreeNode::writeToJson(QJsonObject& json) const if (m_parent == nullptr) { QJsonArray watchList; - for (auto i : m_children) + for (MemWatchTreeNode* const child : m_children) { QJsonObject theNode; - i->writeToJson(theNode); + child->writeToJson(theNode); watchList.append(theNode); } json["watchList"] = watchList; @@ -244,9 +244,9 @@ QString MemWatchTreeNode::writeAsCSV() const if (isGroup() || m_parent == nullptr) { QString rootCsv; - for (auto i : m_children) + for (MemWatchTreeNode* const child : m_children) { - QString theCsvLine = i->writeAsCSV(); + QString theCsvLine = child->writeAsCSV(); rootCsv.append(theCsvLine); } return rootCsv; From ce3a310ff1f65a973be2a094822bf992ab606368 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 21:52:36 +0100 Subject: [PATCH 22/25] Address `readability-redundant-inline-specifier` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.h:53:3: warning: function 'convertMemoryToType' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier] 53 | inline T convertMemoryToType(const char* memory, bool invert) const | ^~~~~~ /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.h:63:3: warning: function 'compareMemoryAsNumbersWithType' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier] 63 | inline CompareResult compareMemoryAsNumbersWithType(const char* first, const char* second, | ^~~~~~ ``` --- Source/MemoryScanner/MemoryScanner.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/MemoryScanner/MemoryScanner.h b/Source/MemoryScanner/MemoryScanner.h index f52b1621..073399e7 100644 --- a/Source/MemoryScanner/MemoryScanner.h +++ b/Source/MemoryScanner/MemoryScanner.h @@ -50,7 +50,7 @@ class MemScanner bool bswapSecond, size_t length) const; template - inline T convertMemoryToType(const char* memory, bool invert) const + T convertMemoryToType(const char* memory, bool invert) const { T theType; std::memcpy(&theType, memory, sizeof(T)); @@ -60,9 +60,9 @@ class MemScanner } template - inline CompareResult compareMemoryAsNumbersWithType(const char* first, const char* second, - const char* offset, bool offsetInvert, - bool bswapSecond) const + CompareResult compareMemoryAsNumbersWithType(const char* first, const char* second, + const char* offset, bool offsetInvert, + bool bswapSecond) const { T firstByte; T secondByte; From 3a7fc4dad3e9d5b4f502080e77726c0183928b30 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 21:51:22 +0100 Subject: [PATCH 23/25] Address `readability-redundant-member-init` warnings. The one warning was: ``` /w/dolphin-memory-engine/Source/MemoryScanner/MemoryScanner.cpp:30:28: warning: initializer for member 'm_resultsConsoleAddr' is redundant [readability-redundant-member-init] 30 | MemScanner::MemScanner() : m_resultsConsoleAddr(std::vector()) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` --- Source/MemoryScanner/MemoryScanner.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/MemoryScanner/MemoryScanner.cpp b/Source/MemoryScanner/MemoryScanner.cpp index 54474541..c3d60710 100644 --- a/Source/MemoryScanner/MemoryScanner.cpp +++ b/Source/MemoryScanner/MemoryScanner.cpp @@ -27,9 +27,7 @@ std::string addSpacesToBytesArrays(const std::string_view bytesArray) } } // namespace -MemScanner::MemScanner() : m_resultsConsoleAddr(std::vector()) -{ -} +MemScanner::MemScanner() = default; MemScanner::~MemScanner() { From b80ca3c652c7f9a14b928451e0ca125b4caf8008 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 21:49:32 +0100 Subject: [PATCH 24/25] Address `readability-redundant-string-init` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/GUI/MemCopy/DlgCopy.cpp:230:15: warning: redundant string initialization [readability-redundant-string-init] 230 | std::string beforeAll = ""; | ^~~~~~~~~~~~~~ | beforeAll /w/dolphin-memory-engine/Source/GUI/MemCopy/DlgCopy.cpp:231:15: warning: redundant string initialization [readability-redundant-string-init] 231 | std::string beforeByte = ""; | ^~~~~~~~~~~~~~~ | beforeByte /w/dolphin-memory-engine/Source/GUI/MemCopy/DlgCopy.cpp:232:15: warning: redundant string initialization [readability-redundant-string-init] 232 | std::string betweenBytes = ""; | ^~~~~~~~~~~~~~~~~ | betweenBytes /w/dolphin-memory-engine/Source/GUI/MemCopy/DlgCopy.cpp:233:15: warning: redundant string initialization [readability-redundant-string-init] 233 | std::string afterAll = ""; | ^~~~~~~~~~~~~ | afterAll ``` --- Source/GUI/MemCopy/DlgCopy.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/GUI/MemCopy/DlgCopy.cpp b/Source/GUI/MemCopy/DlgCopy.cpp index c0283c03..5b196b98 100644 --- a/Source/GUI/MemCopy/DlgCopy.cpp +++ b/Source/GUI/MemCopy/DlgCopy.cpp @@ -228,10 +228,10 @@ std::string DlgCopy::charToHexString(const char* const input, const size_t count std::stringstream ss; const char convert[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; - std::string beforeAll = ""; - std::string beforeByte = ""; - std::string betweenBytes = ""; - std::string afterAll = ""; + std::string beforeAll; + std::string beforeByte; + std::string betweenBytes; + std::string afterAll; switch (format) { From 22721464a3961fce43822c2f079a16f532ca8f36 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sat, 4 May 2024 22:55:09 +0100 Subject: [PATCH 25/25] Address `readability-use-anyofallof` warnings. The warnings were: ``` /w/dolphin-memory-engine/Source/GUI/MemCopy/DlgCopy.cpp:169:3: warning: replace loop by 'std::ranges::all_of()' [readability-use-anyofallof] 169 | for (char c : str) | ^ /w/dolphin-memory-engine/Source/GUI/MemCopy/DlgCopy.cpp:200:3: warning: replace loop by 'std::ranges::all_of()' [readability-use-anyofallof] 200 | for (char c : str) | ^ ``` --- Source/GUI/MemCopy/DlgCopy.cpp | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/Source/GUI/MemCopy/DlgCopy.cpp b/Source/GUI/MemCopy/DlgCopy.cpp index 5b196b98..34cd215f 100644 --- a/Source/GUI/MemCopy/DlgCopy.cpp +++ b/Source/GUI/MemCopy/DlgCopy.cpp @@ -6,6 +6,8 @@ #include #include #include + +#include #include #include #include "../../Common/CommonUtils.h" @@ -166,15 +168,9 @@ bool DlgCopy::isHexString(std::string_view str) str = str.substr(2); } - for (char c : str) - { - if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) - { - continue; - } - return false; - } - return true; + return std::ranges::all_of(str.cbegin(), str.cend(), [](const char c) { + return ('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'); + }); } bool DlgCopy::hexStringToU32(const std::string_view str, u32& output) @@ -197,15 +193,8 @@ bool DlgCopy::hexStringToU32(const std::string_view str, u32& output) bool DlgCopy::isUnsignedIntegerString(const std::string_view str) { - for (char c : str) - { - if (c >= '0' && c <= '9') - { - continue; - } - return false; - } - return true; + return std::ranges::all_of(str.cbegin(), str.cend(), + [](const char c) { return '0' <= c && c <= '9'; }); } bool DlgCopy::uintStringToU32(const std::string_view str, u32& output)