Use std::array<> in more places.

This lets us get rid of a few NULL terminators, too.
This commit is contained in:
David Korth 2025-05-30 18:47:47 -04:00
parent cb09464faa
commit 76746231ca
5 changed files with 37 additions and 34 deletions

View File

@ -19,19 +19,23 @@
#include "libwiicrypto/gcn_structs.h" #include "libwiicrypto/gcn_structs.h"
#include "libwiicrypto/wii_structs.h" #include "libwiicrypto/wii_structs.h"
// C includes. // C includes
#include <stdlib.h> #include <stdlib.h>
// C includes. (C++ namespace) // C includes (C++ namespace)
#include <cassert> #include <cassert>
#include <cerrno> #include <cerrno>
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
// C++ STL classes
#include <array>
using std::array;
// NDDEMO header. // NDDEMO header.
// Used in early GameCube tech demos. // Used in early GameCube tech demos.
// Note the lack of a GameCube magic number. // Note the lack of a GameCube magic number.
static const uint8_t nddemo_header[64] = { static const array<uint8_t, 64> nddemo_header = {{
0x30, 0x30, 0x00, 0x45, 0x30, 0x31, 0x00, 0x00, 0x30, 0x30, 0x00, 0x45, 0x30, 0x31, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 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. // Volume group and partition table.
// NOTE: Only reading the first 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. // Check for GameCube NDDEMO.
if (!memcmp(discHeader, nddemo_header, sizeof(nddemo_header))) { if (!memcmp(discHeader, nddemo_header.data(), nddemo_header.size())) {
// NDDEMO header found. // NDDEMO header found.
return RVTH_BankType_GCN; return RVTH_BankType_GCN;
} }

View File

@ -101,7 +101,6 @@ CisoReader::CisoReader(const RefFilePtr &file, uint32_t lba_start, uint32_t lba_
int ret; int ret;
int err = 0; int err = 0;
size_t size; size_t size;
unsigned int i;
uint16_t physBlockIdx = 0; uint16_t physBlockIdx = 0;
uint16_t maxLogicalBlockUsed = 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)); m_block_size_lba = BYTES_TO_LBA(le32_to_cpu(cisoHeader->block_size));
// Clear the CISO block map initially. // Clear the CISO block map initially.
memset(m_blockMap, 0xFF, sizeof(m_blockMap)); m_blockMap.fill(0xFF);
// Parse the CISO block map. // Parse the CISO block map.
for (i = 0; i < ARRAY_SIZE(m_blockMap); i++) { for (unsigned int i = 0; i < static_cast<unsigned int>(m_blockMap.size()); i++) {
switch (cisoHeader->map[i]) { switch (cisoHeader->map[i]) {
case 0: case 0:
// Empty block. // Empty block.

View File

@ -10,6 +10,9 @@
#include "Reader.hpp" #include "Reader.hpp"
// C++ STL classes
#include <array>
class CisoReader : public Reader class CisoReader : public Reader
{ {
public: public:
@ -70,5 +73,5 @@ private:
// Block map. // Block map.
// 0x0000 == first block after CISO header. // 0x0000 == first block after CISO header.
// 0xFFFF == empty block. // 0xFFFF == empty block.
uint16_t m_blockMap[CISO_MAP_SIZE]; std::array<uint16_t, CISO_MAP_SIZE> m_blockMap;
}; };

View File

@ -74,7 +74,7 @@ private:
// Icons for COL_TYPE. // Icons for COL_TYPE.
// TODO: QMutexLocker? // TODO: QMutexLocker?
static QIcon ms_icons[RvtHModel::ICON_MAX]; static array<QIcon, RvtHModel::ICON_MAX> ms_icons;
public: public:
/** /**
@ -94,7 +94,7 @@ public:
/** RvtHModelPrivate **/ /** RvtHModelPrivate **/
QIcon RvtHModelPrivate::ms_icons[RvtHModel::ICON_MAX]; array<QIcon, RvtHModel::ICON_MAX> RvtHModelPrivate::ms_icons;
RvtHModelPrivate::RvtHModelPrivate(RvtHModel *q) RvtHModelPrivate::RvtHModelPrivate(RvtHModel *q)
: q_ptr(q) : q_ptr(q)

View File

@ -15,6 +15,10 @@
// C includes // C includes
#include <string.h> #include <string.h>
// C++ STl classes
#include <array>
using std::array;
// Qt includes // Qt includes
#include <QtCore/QString> #include <QtCore/QString>
#include <QtCore/QStringList> #include <QtCore/QStringList>
@ -182,24 +186,20 @@ void AboutDialogPrivate::initCreditsTab(void)
}; };
// Credits data. // Credits data.
static const CreditsData_t CreditsData[] = { static const array<CreditsData_t, 2> CreditsData = {{
{CT_TRANSLATORS, "crediar", nullptr, "de"}, {CT_TRANSLATORS, "crediar", nullptr, "de"},
{CT_CONTINUE, "Moddimation", nullptr, "de"}, {CT_CONTINUE, "Moddimation", nullptr, "de"},
}};
{CT_MAX, nullptr, nullptr, nullptr}
};
CreditType_t lastCreditType = CT_CONTINUE; CreditType_t lastCreditType = CT_CONTINUE;
for (const CreditsData_t *creditsData = &CreditsData[0]; for (const CreditsData_t &p : CreditsData) {
creditsData->type < CT_MAX; creditsData++) if (p.type != CT_CONTINUE &&
{ p.type != lastCreditType)
if (creditsData->type != CT_CONTINUE &&
creditsData->type != lastCreditType)
{ {
// New credit type. // New credit type.
QString creditType; QString creditType;
switch (creditsData->type) { switch (p.type) {
case CT_TESTERS: case CT_TESTERS:
creditType = AboutDialog::tr("Testers:"); creditType = AboutDialog::tr("Testers:");
break; break;
@ -215,17 +215,17 @@ void AboutDialogPrivate::initCreditsTab(void)
// Append the contributor's name. // Append the contributor's name.
credits += ql1BR + sIndent + chrBullet + QChar(L' '); credits += ql1BR + sIndent + chrBullet + QChar(L' ');
if (creditsData->url) { if (p.url) {
credits += QStringLiteral("<a href='%1'>") credits += QStringLiteral("<a href='%1'>")
.arg(QLatin1String(creditsData->url)); .arg(QLatin1String(p.url));
} }
credits += QString::fromUtf8(creditsData->name); credits += QString::fromUtf8(p.name);
if (creditsData->url) { if (p.url) {
credits += QStringLiteral("</a>"); credits += QStringLiteral("</a>");
} }
if (creditsData->sub) { if (p.sub) {
credits += QStringLiteral(" (%1)") credits += QStringLiteral(" (%1)")
.arg(QLatin1String(creditsData->sub)); .arg(QLatin1String(p.sub));
} }
} }
@ -346,16 +346,13 @@ void AboutDialogPrivate::initSupportTab(void)
// Support sites. // Support sites.
// TODO: Other sites? // TODO: Other sites?
static const supportSite_t supportSites[] = { static const array<supportSite_t, 1> supportSites = {{
{"GitHub", "https://github.com/GerbilSoft/rvthtool"}, {"GitHub", "https://github.com/GerbilSoft/rvthtool"},
{nullptr, nullptr} }};
};
for (const supportSite_t *supportSite = &supportSites[0]; for (const supportSite_t &p : supportSites) {
supportSite->name != nullptr; supportSite++)
{
QString siteUrlHtml = QStringLiteral("<a href=\"%1\">%2</a>") QString siteUrlHtml = QStringLiteral("<a href=\"%1\">%2</a>")
.arg(QLatin1String(supportSite->url), QLatin1String(supportSite->name)); .arg(QLatin1String(p.url), QLatin1String(p.name));
sSupport += chrBullet + QChar(L' ') + siteUrlHtml + ql1BR; sSupport += chrBullet + QChar(L' ') + siteUrlHtml + ql1BR;
} }