Skip to content

Commit

Permalink
Merge pull request #137 from cristian64/further_clang_tidy_fixes
Browse files Browse the repository at this point in the history
Further fixes for Clang-Tidy warnings (2).
  • Loading branch information
dreamsyntax authored May 14, 2024
2 parents c416d6b + 71fe1f8 commit 4c94370
Show file tree
Hide file tree
Showing 31 changed files with 232 additions and 141 deletions.
2 changes: 2 additions & 0 deletions Source/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Checks: >
hicpp-*,
-hicpp-avoid-c-arrays,
-hicpp-braces-around-statements,
-hicpp-signed-bitwise,
-hicpp-uppercase-literal-suffix,
-hicpp-use-auto,
-hicpp-use-equals-default,
Expand All @@ -25,6 +26,7 @@ Checks: >
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
performance-*,
-performance-enum-size,
-performance-no-int-to-ptr,
readability-*,
-readability-braces-around-statements,
Expand Down
15 changes: 10 additions & 5 deletions Source/CheatEngineParser/CheatEngineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ class CheatEngineParser
CheatEngineParser();
~CheatEngineParser();

CheatEngineParser(const CheatEngineParser&) = delete;
CheatEngineParser(CheatEngineParser&&) = delete;
CheatEngineParser& operator=(const CheatEngineParser&) = delete;
CheatEngineParser& operator=(CheatEngineParser&&) = delete;

QString getErrorMessages() const;
bool hasACriticalErrorOccured() const;
void setTableStartAddress(u32 tableStartAddress);
MemWatchTreeNode* parseCTFile(QIODevice* CTFileIODevice, const bool useDolphinPointer);
MemWatchTreeNode* parseCTFile(QIODevice* CTFileIODevice, bool useDolphinPointer);

private:
struct cheatEntryParsingState
Expand All @@ -33,11 +38,11 @@ class CheatEngineParser
bool validLengthForStr = true;
};

MemWatchTreeNode* parseCheatTable(MemWatchTreeNode* rootNode, const bool useDolphinPointer);
MemWatchTreeNode* parseCheatEntries(MemWatchTreeNode* node, const bool useDolphinPointer);
void parseCheatEntry(MemWatchTreeNode* node, const bool useDolphinPointer);
MemWatchTreeNode* parseCheatTable(MemWatchTreeNode* rootNode, bool useDolphinPointer);
MemWatchTreeNode* parseCheatEntries(MemWatchTreeNode* node, bool useDolphinPointer);
void parseCheatEntry(MemWatchTreeNode* node, bool useDolphinPointer);
void verifyCheatEntryParsingErrors(cheatEntryParsingState state, MemWatchEntry* entry,
bool isGroup, const bool useDolphinPointer);
bool isGroup, bool useDolphinPointer);
static QString formatImportedEntryBasicInfo(const MemWatchEntry* entry);

u32 m_tableStartAddress = 0;
Expand Down
11 changes: 5 additions & 6 deletions Source/Common/MemoryCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ enum class MemOperationReturnCode
OK
};

size_t getSizeForType(const MemType type, const size_t length);
bool shouldBeBSwappedForType(const MemType type);
int getNbrBytesAlignmentForType(const MemType type);
size_t getSizeForType(MemType type, size_t length);
bool shouldBeBSwappedForType(MemType type);
int getNbrBytesAlignmentForType(MemType type);
char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLength,
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);
std::string formatMemoryToString(const char* memory, MemType type, size_t length, MemBase base,
bool isUnsigned, bool withBSwap = false);
} // namespace Common
9 changes: 4 additions & 5 deletions Source/DolphinProcess/DolphinAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ class DolphinAccessor
static void free();
static void hook();
static void unHook();
static bool readFromRAM(const u32 offset, char* buffer, const size_t size, const bool withBSwap);
static bool writeToRAM(const u32 offset, const char* buffer, const size_t size,
const bool withBSwap);
static bool readFromRAM(u32 offset, char* buffer, size_t size, bool withBSwap);
static bool writeToRAM(u32 offset, const char* buffer, size_t size, bool withBSwap);
static int getPID();
static u64 getEmuRAMAddressStart();
static DolphinStatus getStatus();
Expand All @@ -33,10 +32,10 @@ class DolphinAccessor
static bool isMEM2Present();
static size_t getRAMTotalSize();
static Common::MemOperationReturnCode readEntireRAM(char* buffer);
static std::string getFormattedValueFromMemory(const u32 ramIndex, Common::MemType memType,
static std::string getFormattedValueFromMemory(u32 ramIndex, Common::MemType memType,
size_t memSize, Common::MemBase memBase,
bool memIsUnsigned);
static bool isValidConsoleAddress(const u32 address);
static bool isValidConsoleAddress(u32 address);

private:
static IDolphinProcess* m_instance;
Expand Down
13 changes: 9 additions & 4 deletions Source/DolphinProcess/IDolphinProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ namespace DolphinComm
class IDolphinProcess
{
public:
IDolphinProcess() = default;
virtual ~IDolphinProcess() = default;

IDolphinProcess(const IDolphinProcess&) = delete;
IDolphinProcess(IDolphinProcess&&) = delete;
IDolphinProcess& operator=(const IDolphinProcess&) = delete;
IDolphinProcess& operator=(IDolphinProcess&&) = delete;

virtual bool findPID() = 0;
virtual bool obtainEmuRAMInformations() = 0;
virtual bool readFromRAM(const u32 offset, char* buffer, const size_t size,
const bool withBSwap) = 0;
virtual bool writeToRAM(const u32 offset, const char* buffer, const size_t size,
const bool withBSwap) = 0;
virtual bool readFromRAM(u32 offset, char* buffer, size_t size, bool withBSwap) = 0;
virtual bool writeToRAM(u32 offset, const char* buffer, size_t size, bool withBSwap) = 0;

int getPID() const { return m_PID; };
u64 getEmuRAMAddressStart() const { return m_emuRAMAddressStart; };
Expand Down
5 changes: 3 additions & 2 deletions Source/DolphinProcess/Linux/LinuxDolphinProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ bool LinuxDolphinProcess::findPID()
struct dirent* directoryEntry = nullptr;
while (m_PID == -1 && (directoryEntry = readdir(directoryPointer)))
{
std::istringstream conversionStream(directoryEntry->d_name);
const char* const name{static_cast<const char*>(directoryEntry->d_name)};
std::istringstream conversionStream(name);
int aPID = 0;
if (!(conversionStream >> aPID))
continue;
std::ifstream aCmdLineFile;
std::string line;
aCmdLineFile.open("/proc/" + std::string(directoryEntry->d_name) + "/comm");
aCmdLineFile.open("/proc/" + std::string(name) + "/comm");
getline(aCmdLineFile, line);

const bool match{s_dolphinProcessName ? line == s_dolphinProcessName :
Expand Down
5 changes: 2 additions & 3 deletions Source/DolphinProcess/Linux/LinuxDolphinProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ class LinuxDolphinProcess : public IDolphinProcess
LinuxDolphinProcess() = default;
bool findPID() override;
bool obtainEmuRAMInformations() override;
bool readFromRAM(const u32 offset, char* buffer, size_t size, const bool withBSwap) override;
bool writeToRAM(const u32 offset, const char* buffer, const size_t size,
const bool withBSwap) override;
bool readFromRAM(u32 offset, char* buffer, size_t size, bool withBSwap) override;
bool writeToRAM(u32 offset, const char* buffer, size_t size, bool withBSwap) override;
};
} // namespace DolphinComm
#endif
5 changes: 2 additions & 3 deletions Source/DolphinProcess/Mac/MacDolphinProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ class MacDolphinProcess : public IDolphinProcess
MacDolphinProcess() = default;
bool findPID() override;
bool obtainEmuRAMInformations() override;
bool readFromRAM(const u32 offset, char* buffer, size_t size, const bool withBSwap) override;
bool writeToRAM(const u32 offset, const char* buffer, const size_t size,
const bool withBSwap) override;
bool readFromRAM(u32 offset, char* buffer, size_t size, bool withBSwap) override;
bool writeToRAM(u32 offset, const char* buffer, size_t size, bool withBSwap) override;

private:
task_t m_task;
Expand Down
6 changes: 2 additions & 4 deletions Source/DolphinProcess/Windows/WindowsDolphinProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ class WindowsDolphinProcess : public IDolphinProcess
WindowsDolphinProcess() = default;
bool findPID() override;
bool obtainEmuRAMInformations() override;
bool readFromRAM(const u32 offset, char* buffer, const size_t size,
const bool withBSwap) override;
bool writeToRAM(const u32 offset, const char* buffer, const size_t size,
const bool withBSwap) override;
bool readFromRAM(u32 offset, char* buffer, size_t size, bool withBSwap) override;
bool writeToRAM(u32 offset, const char* buffer, size_t size, bool withBSwap) override;

private:
HANDLE m_hDolphin;
Expand Down
4 changes: 2 additions & 2 deletions Source/GUI/GUICommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ extern QStringList g_memTypeNames;
extern QStringList g_memScanFilter;
extern QStringList g_memBaseNames;

QString getStringFromType(const Common::MemType type, const size_t length = 0);
QString getNameFromBase(const Common::MemBase base);
QString getStringFromType(Common::MemType type, size_t length = 0);
QString getNameFromBase(Common::MemBase base);

void changeApplicationStyle(int);

Expand Down
6 changes: 6 additions & 0 deletions Source/GUI/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class MainWindow : public QMainWindow
public:
MainWindow();
~MainWindow() override;

MainWindow(const MainWindow&) = delete;
MainWindow(MainWindow&&) = delete;
MainWindow& operator=(const MainWindow&) = delete;
MainWindow& operator=(MainWindow&&) = delete;

void closeEvent(QCloseEvent* event) override;
void addWatchRequested(u32 address, Common::MemType type, size_t length, bool isUnsigned,
Common::MemBase base);
Expand Down
6 changes: 3 additions & 3 deletions Source/GUI/MemCopy/DlgCopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ bool DlgCopy::copyMemory()
{
QString errorMsg = tr("The address you entered is invalid, make sure it is an "
"hexadecimal number between 0x%08X and 0x%08X")
.arg(Common::MEM1_START, Common::GetMEM1End() - 1);
.arg(Common::MEM1_START, static_cast<int>(Common::GetMEM1End()) - 1);
if (DolphinComm::DolphinAccessor::isMEM2Present())
errorMsg.append(
tr(" or between 0x%08X and 0x%08X").arg(Common::MEM2_START, Common::GetMEM2End() - 1));
errorMsg.append(tr(" or between 0x%08X and 0x%08X")
.arg(Common::MEM2_START, static_cast<int>(Common::GetMEM2End()) - 1));

errorBox = new QMessageBox(QMessageBox::Critical, tr("Invalid address"), errorMsg,
QMessageBox::Ok, nullptr);
Expand Down
5 changes: 5 additions & 0 deletions Source/GUI/MemCopy/DlgCopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class DlgCopy : public QDialog
explicit DlgCopy(QWidget* parent = nullptr);
~DlgCopy() override;

DlgCopy(const DlgCopy&) = delete;
DlgCopy(DlgCopy&&) = delete;
DlgCopy& operator=(const DlgCopy&) = delete;
DlgCopy& operator=(DlgCopy&&) = delete;

private:
enum ByteStringFormats
{
Expand Down
7 changes: 6 additions & 1 deletion Source/GUI/MemScanner/MemScanWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class MemScanWidget : public QWidget
MemScanWidget();
~MemScanWidget() override;

MemScanWidget(const MemScanWidget&) = delete;
MemScanWidget(MemScanWidget&&) = delete;
MemScanWidget& operator=(const MemScanWidget&) = delete;
MemScanWidget& operator=(MemScanWidget&&) = delete;

ResultsListModel* getResultListModel() const;
std::vector<u32> getAllResults() const;
QModelIndexList getSelectedResults() const;
Expand All @@ -30,7 +35,7 @@ class MemScanWidget : public QWidget
void onScanMemTypeChanged();
void onCurrentValuesUpdateTimer();
void onResultListDoubleClicked(const QModelIndex& index);
void handleScannerErrors(const Common::MemOperationReturnCode errorCode);
void handleScannerErrors(Common::MemOperationReturnCode errorCode);
void onFirstScan();
void onNextScan();
void onUndoScan();
Expand Down
7 changes: 6 additions & 1 deletion Source/GUI/MemScanner/ResultsListModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ class ResultsListModel : public QAbstractTableModel
ResultsListModel(QObject* parent, MemScanner* scanner);
~ResultsListModel() override;

ResultsListModel(const ResultsListModel&) = delete;
ResultsListModel(ResultsListModel&&) = delete;
ResultsListModel& operator=(const ResultsListModel&) = delete;
ResultsListModel& operator=(ResultsListModel&&) = delete;

int columnCount(const QModelIndex& parent) const override;
int rowCount(const QModelIndex& parent) const override;
QVariant data(const QModelIndex& index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
bool removeRows(int row, int count, const QModelIndex& parent) override;

u32 getResultAddress(const int row) const;
u32 getResultAddress(int row) const;
void updateScanner();
void updateAfterScannerReset();
void setShowThreshold(size_t showThreshold);
Expand Down
18 changes: 11 additions & 7 deletions Source/GUI/MemViewer/MemViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ void MemViewer::memoryValidityChanged(const bool valid)
m_memViewStart = Common::ARAM_START;
m_memViewEnd = Common::ARAM_END;
}
verticalScrollBar()->setRange(0, ((m_memViewEnd - m_memViewStart) / m_numColumns) - m_numRows);
verticalScrollBar()->setRange(
0, (static_cast<int>(m_memViewEnd - m_memViewStart) / m_numColumns) - m_numRows);
}
viewport()->update();
}
Expand Down Expand Up @@ -143,7 +144,8 @@ void MemViewer::jumpToAddress(const u32 address)
m_carretBetweenHex = false;

m_disableScrollContentEvent = true;
verticalScrollBar()->setValue(((address & 0xFFFFFFF0) - m_memViewStart) / m_numColumns);
verticalScrollBar()->setValue(static_cast<int>((address & 0xFFFFFFF0) - m_memViewStart) /
m_numColumns);
m_disableScrollContentEvent = false;

viewport()->update();
Expand All @@ -167,7 +169,8 @@ void MemViewer::changeMemoryRegion(const MemoryRegion region)
m_memViewEnd = Common::GetMEM2End();
break;
}
verticalScrollBar()->setRange(0, ((m_memViewEnd - m_memViewStart) / m_numColumns) - m_numRows);
verticalScrollBar()->setRange(
0, (static_cast<int>(m_memViewEnd - m_memViewStart) / m_numColumns) - m_numRows);
}

MemViewer::bytePosFromMouse MemViewer::mousePosToBytePos(QPoint pos)
Expand Down Expand Up @@ -720,10 +723,11 @@ bool MemViewer::writeCharacterToSelectedMemory(char byteToWrite)

const char selectedMemoryValue = *(m_updatedRawMemoryData + memoryOffset);
if (m_carretBetweenHex)
byteToWrite = (selectedMemoryValue & static_cast<char>(0xF0)) | byteToWrite;
byteToWrite = static_cast<char>((static_cast<u32>(selectedMemoryValue) & 0xF0) |
static_cast<u32>(byteToWrite));
else
byteToWrite =
(selectedMemoryValue & static_cast<char>(0x0F)) | static_cast<char>(byteToWrite << 4);
byteToWrite = static_cast<char>((static_cast<u32>(selectedMemoryValue) & 0x0F) |
(static_cast<u32>(byteToWrite) << 4));
}

const u32 offsetToWrite{
Expand Down Expand Up @@ -845,7 +849,7 @@ void MemViewer::renderColumnsHeaderText(QPainter& painter) const
for (int i = 0; i < m_numColumns; i++)
{
std::stringstream ss;
int byte = (m_currentFirstAddress + i) & 0xF;
const u32 byte{(m_currentFirstAddress + static_cast<u32>(i)) & 0xF};
ss << std::hex << std::uppercase << byte;
std::string headerText = "." + ss.str();
painter.drawText(posXHeaderText, m_charHeight, QString::fromStdString(headerText));
Expand Down
28 changes: 17 additions & 11 deletions Source/GUI/MemViewer/MemViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class MemViewer : public QAbstractScrollArea
public:
explicit MemViewer(QWidget* parent);
~MemViewer() override;

MemViewer(const MemViewer&) = delete;
MemViewer(MemViewer&&) = delete;
MemViewer& operator=(const MemViewer&) = delete;
MemViewer& operator=(MemViewer&&) = delete;

QSize sizeHint() const override;
void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
Expand All @@ -29,9 +35,9 @@ class MemViewer : public QAbstractScrollArea
void paintEvent(QPaintEvent* event) override;
void scrollContentsBy(int dx, int dy) override;
u32 getCurrentFirstAddress() const;
void jumpToAddress(const u32 address);
void jumpToAddress(u32 address);
void updateViewer();
void memoryValidityChanged(const bool valid);
void memoryValidityChanged(bool valid);

signals:
void memErrorOccured();
Expand Down Expand Up @@ -68,21 +74,21 @@ class MemViewer : public QAbstractScrollArea
void editSelection();
void addSelectionAsArrayOfBytes();
void addByteIndexAsWatch(int index);
bool handleNaviguationKey(const int key, bool shiftIsHeld);
bool handleNaviguationKey(int key, bool shiftIsHeld);
bool writeCharacterToSelectedMemory(char byteToWrite);
void updateMemoryData();
void changeMemoryRegion(const MemoryRegion region);
void changeMemoryRegion(MemoryRegion region);
void renderColumnsHeaderText(QPainter& painter) const;
void renderRowHeaderText(QPainter& painter, int rowIndex) const;
void renderSeparatorLines(QPainter& painter) const;
void renderMemory(QPainter& painter, const int rowIndex, const int columnIndex);
void renderHexByte(QPainter& painter, const int rowIndex, const int columnIndex, QColor& bgColor,
void renderMemory(QPainter& painter, int rowIndex, int columnIndex);
void renderHexByte(QPainter& painter, int rowIndex, int columnIndex, QColor& bgColor,
QColor& fgColor, bool drawCarret);
void renderASCIIText(QPainter& painter, const int rowIndex, const int columnIndex,
QColor& bgColor, QColor& fgColor);
void renderCarret(QPainter& painter, const int rowIndex, const int columnIndex);
void determineMemoryTextRenderProperties(const int rowIndex, const int columnIndex,
bool& drawCarret, QColor& bgColor, QColor& fgColor);
void renderASCIIText(QPainter& painter, int rowIndex, int columnIndex, QColor& bgColor,
QColor& fgColor);
void renderCarret(QPainter& painter, int rowIndex, int columnIndex);
void determineMemoryTextRenderProperties(int rowIndex, int columnIndex, bool& drawCarret,
QColor& bgColor, QColor& fgColor);

const int m_numRows = 16;
const int m_numColumns = 16; // Should be a multiple of 16, or the header doesn't make much sense
Expand Down
5 changes: 5 additions & 0 deletions Source/GUI/MemViewer/MemViewerWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class MemViewerWidget : public QWidget
explicit MemViewerWidget(QWidget* parent);
~MemViewerWidget() override;

MemViewerWidget(const MemViewerWidget&) = delete;
MemViewerWidget(MemViewerWidget&&) = delete;
MemViewerWidget& operator=(const MemViewerWidget&) = delete;
MemViewerWidget& operator=(MemViewerWidget&&) = delete;

void onJumpToAddressTextChanged();
void onGoToMEM1Start();
void onGoToSecondaryRAMStart();
Expand Down
6 changes: 6 additions & 0 deletions Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class DlgAddWatchEntry : public QDialog
public:
DlgAddWatchEntry(bool newEntry, MemWatchEntry* entry, QWidget* parent);
~DlgAddWatchEntry() override;

DlgAddWatchEntry(const DlgAddWatchEntry&) = delete;
DlgAddWatchEntry(DlgAddWatchEntry&&) = delete;
DlgAddWatchEntry& operator=(const DlgAddWatchEntry&) = delete;
DlgAddWatchEntry& operator=(DlgAddWatchEntry&&) = delete;

void onTypeChange(int index);
void accept() override;
void onAddressChanged();
Expand Down
Loading

0 comments on commit 4c94370

Please sign in to comment.