From 76746231cace4133f970e78b1315ee7d56adcd62 Mon Sep 17 00:00:00 2001 From: David Korth Date: Fri, 30 May 2025 18:47:47 -0400 Subject: [PATCH] Use std::array<> in more places. This lets us get rid of a few NULL terminators, too. --- src/librvth/disc_header.cpp | 14 +++++---- src/librvth/reader/CisoReader.cpp | 5 ++-- src/librvth/reader/CisoReader.hpp | 5 +++- src/qrvthtool/RvtHModel.cpp | 4 +-- src/qrvthtool/windows/AboutDialog.cpp | 43 +++++++++++++-------------- 5 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/librvth/disc_header.cpp b/src/librvth/disc_header.cpp index ebc501b..a1a7f14 100644 --- a/src/librvth/disc_header.cpp +++ b/src/librvth/disc_header.cpp @@ -19,19 +19,23 @@ #include "libwiicrypto/gcn_structs.h" #include "libwiicrypto/wii_structs.h" -// C includes. +// C includes #include -// C includes. (C++ namespace) +// C includes (C++ namespace) #include #include #include #include +// C++ STL classes +#include +using std::array; + // NDDEMO header. // Used in early GameCube tech demos. // Note the lack of a GameCube magic number. -static const uint8_t nddemo_header[64] = { +static const array nddemo_header = {{ 0x30, 0x30, 0x00, 0x45, 0x30, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -40,7 +44,7 @@ static const uint8_t nddemo_header[64] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; +}}; // Volume group and partition table. // NOTE: Only reading the first partition table, @@ -84,7 +88,7 @@ int rvth_disc_header_identify(const GCN_DiscHeader *discHeader) } // Check for GameCube NDDEMO. - if (!memcmp(discHeader, nddemo_header, sizeof(nddemo_header))) { + if (!memcmp(discHeader, nddemo_header.data(), nddemo_header.size())) { // NDDEMO header found. return RVTH_BankType_GCN; } diff --git a/src/librvth/reader/CisoReader.cpp b/src/librvth/reader/CisoReader.cpp index adc33db..fa9ec69 100644 --- a/src/librvth/reader/CisoReader.cpp +++ b/src/librvth/reader/CisoReader.cpp @@ -101,7 +101,6 @@ CisoReader::CisoReader(const RefFilePtr &file, uint32_t lba_start, uint32_t lba_ int ret; int err = 0; size_t size; - unsigned int i; uint16_t physBlockIdx = 0; uint16_t maxLogicalBlockUsed = 0; @@ -163,10 +162,10 @@ CisoReader::CisoReader(const RefFilePtr &file, uint32_t lba_start, uint32_t lba_ m_block_size_lba = BYTES_TO_LBA(le32_to_cpu(cisoHeader->block_size)); // Clear the CISO block map initially. - memset(m_blockMap, 0xFF, sizeof(m_blockMap)); + m_blockMap.fill(0xFF); // Parse the CISO block map. - for (i = 0; i < ARRAY_SIZE(m_blockMap); i++) { + for (unsigned int i = 0; i < static_cast(m_blockMap.size()); i++) { switch (cisoHeader->map[i]) { case 0: // Empty block. diff --git a/src/librvth/reader/CisoReader.hpp b/src/librvth/reader/CisoReader.hpp index e44d6aa..6158b66 100644 --- a/src/librvth/reader/CisoReader.hpp +++ b/src/librvth/reader/CisoReader.hpp @@ -10,6 +10,9 @@ #include "Reader.hpp" +// C++ STL classes +#include + class CisoReader : public Reader { public: @@ -70,5 +73,5 @@ private: // Block map. // 0x0000 == first block after CISO header. // 0xFFFF == empty block. - uint16_t m_blockMap[CISO_MAP_SIZE]; + std::array m_blockMap; }; diff --git a/src/qrvthtool/RvtHModel.cpp b/src/qrvthtool/RvtHModel.cpp index 997d48c..46077c0 100644 --- a/src/qrvthtool/RvtHModel.cpp +++ b/src/qrvthtool/RvtHModel.cpp @@ -74,7 +74,7 @@ private: // Icons for COL_TYPE. // TODO: QMutexLocker? - static QIcon ms_icons[RvtHModel::ICON_MAX]; + static array ms_icons; public: /** @@ -94,7 +94,7 @@ public: /** RvtHModelPrivate **/ -QIcon RvtHModelPrivate::ms_icons[RvtHModel::ICON_MAX]; +array RvtHModelPrivate::ms_icons; RvtHModelPrivate::RvtHModelPrivate(RvtHModel *q) : q_ptr(q) diff --git a/src/qrvthtool/windows/AboutDialog.cpp b/src/qrvthtool/windows/AboutDialog.cpp index d3caf6d..d79d878 100644 --- a/src/qrvthtool/windows/AboutDialog.cpp +++ b/src/qrvthtool/windows/AboutDialog.cpp @@ -15,6 +15,10 @@ // C includes #include +// C++ STl classes +#include +using std::array; + // Qt includes #include #include @@ -182,24 +186,20 @@ void AboutDialogPrivate::initCreditsTab(void) }; // Credits data. - static const CreditsData_t CreditsData[] = { + static const array CreditsData = {{ {CT_TRANSLATORS, "crediar", nullptr, "de"}, {CT_CONTINUE, "Moddimation", nullptr, "de"}, - - {CT_MAX, nullptr, nullptr, nullptr} - }; + }}; CreditType_t lastCreditType = CT_CONTINUE; - for (const CreditsData_t *creditsData = &CreditsData[0]; - creditsData->type < CT_MAX; creditsData++) - { - if (creditsData->type != CT_CONTINUE && - creditsData->type != lastCreditType) + for (const CreditsData_t &p : CreditsData) { + if (p.type != CT_CONTINUE && + p.type != lastCreditType) { // New credit type. QString creditType; - switch (creditsData->type) { + switch (p.type) { case CT_TESTERS: creditType = AboutDialog::tr("Testers:"); break; @@ -215,17 +215,17 @@ void AboutDialogPrivate::initCreditsTab(void) // Append the contributor's name. credits += ql1BR + sIndent + chrBullet + QChar(L' '); - if (creditsData->url) { + if (p.url) { credits += QStringLiteral("") - .arg(QLatin1String(creditsData->url)); + .arg(QLatin1String(p.url)); } - credits += QString::fromUtf8(creditsData->name); - if (creditsData->url) { + credits += QString::fromUtf8(p.name); + if (p.url) { credits += QStringLiteral(""); } - if (creditsData->sub) { + if (p.sub) { credits += QStringLiteral(" (%1)") - .arg(QLatin1String(creditsData->sub)); + .arg(QLatin1String(p.sub)); } } @@ -346,16 +346,13 @@ void AboutDialogPrivate::initSupportTab(void) // Support sites. // TODO: Other sites? - static const supportSite_t supportSites[] = { + static const array supportSites = {{ {"GitHub", "https://github.com/GerbilSoft/rvthtool"}, - {nullptr, nullptr} - }; + }}; - for (const supportSite_t *supportSite = &supportSites[0]; - supportSite->name != nullptr; supportSite++) - { + for (const supportSite_t &p : supportSites) { QString siteUrlHtml = QStringLiteral("%2") - .arg(QLatin1String(supportSite->url), QLatin1String(supportSite->name)); + .arg(QLatin1String(p.url), QLatin1String(p.name)); sSupport += chrBullet + QChar(L' ') + siteUrlHtml + ql1BR; }