Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Clang-Tidy configuration file + a some fixes. #125

Merged
merged 25 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
44f33b2
Enable compilation database generation in CMake file.
cristian64 Apr 27, 2024
40cefd2
Add Clang-Tidy configuration file.
cristian64 May 4, 2024
98283d2
Address `bugprone-integer-division` warnings.
cristian64 May 4, 2024
126a833
Address `bugprone-multi-level-implicit-pointer-conversion` warnings.
cristian64 May 4, 2024
fd9362b
Address `bugprone-signed-char-misuse` warnings.
cristian64 May 4, 2024
8a18f34
Address `bugprone-unused-local-non-trivial-variable` warnings.
cristian64 May 4, 2024
df1d84c
Address `google-readability-casting` warnings.
cristian64 May 4, 2024
3bb5aa2
Address `google-runtime-int` warnings.
cristian64 May 4, 2024
243c639
Address `hicpp-use-equals-default` warnings.
cristian64 May 4, 2024
be734e8
Address `hicpp-use-nullptr` warnings.
cristian64 May 4, 2024
5a671d8
Address `misc-redundant-expression` warnings.
cristian64 May 4, 2024
1e56ded
Address `misc-throw-by-value-catch-by-reference` warnings.
cristian64 May 4, 2024
a8af60f
Address `modernize-pass-by-value` warnings.
cristian64 May 4, 2024
42254e9
Address `modernize-use-using` warnings.
cristian64 May 4, 2024
825ee35
Address `performance-for-range-copy` warnings.
cristian64 May 4, 2024
c5d61d3
Address `performance-unnecessary-value-param` warnings.
cristian64 May 4, 2024
c32f48f
Address `readability-container-size-empty` warnings.
cristian64 May 4, 2024
2ed89f6
Address `readability-convert-member-functions-to-static` warnings.
cristian64 May 4, 2024
b826aa3
Address `readability-inconsistent-declaration-parameter-name` warnings.
cristian64 May 4, 2024
043012d
Address `readability-non-const-parameter` warnings.
cristian64 May 4, 2024
6bd459b
Address `readability-qualified-auto` warnings.
cristian64 May 4, 2024
ce3a310
Address `readability-redundant-inline-specifier` warnings.
cristian64 May 4, 2024
3a7fc4d
Address `readability-redundant-member-init` warnings.
cristian64 May 4, 2024
b80ca3c
Address `readability-redundant-string-init` warnings.
cristian64 May 4, 2024
2272146
Address `readability-use-anyofallof` warnings.
cristian64 May 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Source/.clang-tidy
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions Source/CheatEngineParser/CheatEngineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -362,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";
Expand Down
2 changes: 1 addition & 1 deletion Source/CheatEngineParser/CheatEngineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
16 changes: 8 additions & 8 deletions Source/Common/CommonTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <cstdint>

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;
13 changes: 13 additions & 0 deletions Source/Common/CommonUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@

namespace Common
{
template <typename To, typename From>
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)
{
Expand Down
53 changes: 29 additions & 24 deletions Source/Common/MemoryCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,17 @@ 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)
if (inputString.empty())
{
returnCode = MemOperationReturnCode::invalidInput;
return nullptr;
}

std::stringstream ss(inputString);
std::stringstream ss;
ss << inputString;
switch (base)
{
case MemBase::base_octal:
Expand All @@ -158,19 +159,20 @@ 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<sizeof(u8) * 8>(inputString).to_ullong();
input = static_cast<u8>(
std::bitset<sizeof(u8) * 8>(inputString.data(), inputString.size()).to_ullong());
}
catch (std::invalid_argument)
catch (const std::invalid_argument&)
{
delete[] buffer;
buffer = nullptr;
returnCode = MemOperationReturnCode::invalidInput;
return buffer;
}
theByte = static_cast<u8>(input);
theByte = input;
}
else
{
Expand All @@ -196,19 +198,20 @@ 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<sizeof(u16) * 8>(inputString).to_ullong();
input = static_cast<u16>(
std::bitset<sizeof(u16) * 8>(inputString.data(), inputString.size()).to_ullong());
}
catch (std::invalid_argument)
catch (const std::invalid_argument&)
{
delete[] buffer;
buffer = nullptr;
returnCode = MemOperationReturnCode::invalidInput;
return buffer;
}
theHalfword = static_cast<u16>(input);
theHalfword = input;
}
else
{
Expand All @@ -232,19 +235,20 @@ 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<sizeof(u32) * 8>(inputString).to_ullong();
input = static_cast<u32>(
std::bitset<sizeof(u32) * 8>(inputString.data(), inputString.size()).to_ullong());
}
catch (std::invalid_argument)
catch (const std::invalid_argument&)
{
delete[] buffer;
buffer = nullptr;
returnCode = MemOperationReturnCode::invalidInput;
return buffer;
}
theWord = static_cast<u32>(input);
theWord = input;
}
else
{
Expand All @@ -270,10 +274,11 @@ 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<sizeof(u32) * 8>(inputString).to_ullong();
input = static_cast<u32>(
std::bitset<sizeof(u32) * 8>(inputString.data(), inputString.size()).to_ullong());
}
catch (const std::invalid_argument&)
{
Expand All @@ -282,7 +287,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen
returnCode = MemOperationReturnCode::invalidInput;
return buffer;
}
theWord = static_cast<u32>(input);
theWord = input;
}
else
{
Expand Down Expand Up @@ -323,10 +328,11 @@ 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<sizeof(u64) * 8>(inputString).to_ullong();
input = static_cast<u64>(
std::bitset<sizeof(u64) * 8>(inputString.data(), inputString.size()).to_ullong());
}
catch (const std::invalid_argument&)
{
Expand All @@ -335,7 +341,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen
returnCode = MemOperationReturnCode::invalidInput;
return buffer;
}
theDoubleWord = static_cast<u64>(input);
theDoubleWord = input;
}
else
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -419,7 +425,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;
Expand Down
4 changes: 2 additions & 2 deletions Source/Common/MemoryCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstddef>
#include <string>
#include <string_view>

#include "CommonTypes.h"

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/DolphinProcess/IDolphinProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down Expand Up @@ -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<void*>(RAMAddress);
remote.iov_len = size;

nread = process_vm_readv(m_PID, &local, 1, &remote, 1, 0);
Expand Down Expand Up @@ -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<void*>(RAMAddress);
remote.iov_len = size;

if (withBSwap)
Expand Down
2 changes: 1 addition & 1 deletion Source/DolphinProcess/Linux/LinuxDolphinProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/DolphinProcess/Mac/MacDolphinProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions Source/DolphinProcess/Windows/WindowsDolphinProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>(
ReadProcessMemory(m_hDolphin, reinterpret_cast<void*>(RAMAddress), buffer, size, &nread))};
if (bResult && nread == size)
{
if (withBSwap)
Expand Down Expand Up @@ -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<bool>(WriteProcessMemory(
m_hDolphin, reinterpret_cast<void*>(RAMAddress), bufferCopy, size, &nread))};
delete[] bufferCopy;
return (bResult && nread == size);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/DolphinProcess/Windows/WindowsDolphinProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading