1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-22 20:06:40 +00:00

strat: remove sizeof() / sizeof([0])

This commit is contained in:
Michael Scire 2019-07-02 14:36:57 -07:00 committed by SciresM
parent a5da286351
commit c916a7db88
10 changed files with 19 additions and 18 deletions

View file

@ -44,7 +44,7 @@ bool SetMitmService::IsValidLanguageCode(u64 lang_code) {
LanguageCode_SimplifiedChinese,
LanguageCode_TraditionalChinese,
};
size_t num_language_codes = sizeof(s_valid_language_codes) / sizeof(s_valid_language_codes[0]);
size_t num_language_codes = sts::util::size(s_valid_language_codes);
if (GetRuntimeFirmwareVersion() < FirmwareVersion_400) {
/* 4.0.0 added simplified and traditional chinese. */
num_language_codes -= 2;

View file

@ -84,7 +84,7 @@ void Utils::InitializeThreadFunc(void *args) {
DoWithSmSession([&]() {
Handle tmp_hnd = 0;
static const char * const required_active_services[] = {"pcv", "gpio", "pinmux", "psc:c"};
for (unsigned int i = 0; i < sizeof(required_active_services) / sizeof(required_active_services[0]); i++) {
for (unsigned int i = 0; i < sts::util::size(required_active_services); i++) {
R_ASSERT(smGetServiceOriginal(&tmp_hnd, smEncodeName(required_active_services[i])));
svcCloseHandle(tmp_hnd);
}

View file

@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere/reg.hpp>
#include <stratosphere/spl.hpp>
@ -112,9 +113,9 @@ namespace sts::boot {
}
}
#define DO_REGISTER_WRITES(base_address, writes) DoRegisterWrites(base_address, writes, sizeof(writes) / sizeof(writes[0]))
#define DO_SOC_DEPENDENT_REGISTER_WRITES(base_address, writes) DoSocDependentRegisterWrites(base_address, writes##Erista, sizeof(writes##Erista) / sizeof(writes##Erista[0]), writes##Mariko, sizeof(writes##Mariko) / sizeof(writes##Mariko[0]))
#define DO_DSI_SLEEP_OR_REGISTER_WRITES(writes) DoDsiSleepOrRegisterWrites(writes, sizeof(writes) / sizeof(writes[0]))
#define DO_REGISTER_WRITES(base_address, writes) DoRegisterWrites(base_address, writes, util::size(writes))
#define DO_SOC_DEPENDENT_REGISTER_WRITES(base_address, writes) DoSocDependentRegisterWrites(base_address, writes##Erista, util::size(writes##Erista), writes##Mariko, util::size(writes##Mariko))
#define DO_DSI_SLEEP_OR_REGISTER_WRITES(writes) DoDsiSleepOrRegisterWrites(writes, util::size(writes))
void InitializeFrameBuffer() {
if (g_frame_buffer != nullptr) {
@ -296,7 +297,7 @@ namespace sts::boot {
/* Parse LCD vendor. */
{
u32 host_response[3];
for (size_t i = 0; i < sizeof(host_response) / sizeof(host_response[0]); i++) {
for (size_t i = 0; i < util::size(host_response); i++) {
host_response[i] = reg::Read(g_dsi_regs + sizeof(u32) * DSI_RD_DATA);
}

View file

@ -245,7 +245,7 @@ namespace sts::i2c::driver::impl {
static constexpr u64 s_interrupts[] = {
0x46, 0x74, 0x7C, 0x98, 0x55, 0x5F
};
if (ConvertToIndex(bus) >= sizeof(s_interrupts) / sizeof(s_interrupts[0])) {
if (ConvertToIndex(bus) >= util::size(s_interrupts)) {
std::abort();
}

View file

@ -67,7 +67,7 @@ namespace sts::i2c::driver::impl {
{I2cDevice_Ina226VddDdr0V6, Bus::I2C2, 0x4e, AddressingMode::SevenBit, SpeedMode::Fast, 3, 5'000'000},
};
constexpr size_t NumDeviceConfigs = sizeof(g_device_configs) / sizeof(g_device_configs[0]);
constexpr size_t NumDeviceConfigs = util::size(g_device_configs);
constexpr size_t DeviceInvalidIndex = static_cast<size_t>(-1);

View file

@ -79,7 +79,7 @@ namespace sts::pinmux {
static constexpr u32 ExtraIowaPadNames[] = {
0xAA, 0xAC, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9
};
for (size_t i = 0; i < sizeof(ExtraIowaPadNames) / sizeof(ExtraIowaPadNames[0]); i++) {
for (size_t i = 0; i < util::size(ExtraIowaPadNames); i++) {
UpdatePad(ExtraIowaPadNames[i], 0x2000, 0x2000);
}
}

View file

@ -356,7 +356,7 @@ bool DmntCheatManager::ParseCheats(const char *s, size_t len) {
}
/* Bounds check the opcode count. */
if (cur_entry->definition.num_opcodes >= sizeof(cur_entry->definition.opcodes)/sizeof(cur_entry->definition.opcodes[0])) {
if (cur_entry->definition.num_opcodes >= sts::util::size(cur_entry->definition.opcodes)) {
return false;
}
@ -662,7 +662,7 @@ Result DmntCheatManager::AddCheat(u32 *out_id, CheatDefinition *def, bool enable
return ResultDmntCheatNotAttached;
}
if (def->num_opcodes == 0 || def->num_opcodes > sizeof(def->opcodes)/sizeof(def->opcodes[0])) {
if (def->num_opcodes == 0 || def->num_opcodes > sts::util::size(def->opcodes)) {
return ResultDmntCheatInvalidCheat;
}
@ -860,7 +860,7 @@ Result DmntCheatManager::ForceOpenCheatProcess() {
{
LoaderModuleInfo proc_modules[2];
u32 num_modules;
R_TRY(ldrDmntGetModuleInfos(g_cheat_process_metadata.process_id, proc_modules, sizeof(proc_modules)/sizeof(proc_modules[0]), &num_modules));
R_TRY(ldrDmntGetModuleInfos(g_cheat_process_metadata.process_id, proc_modules, sts::util::size(proc_modules), &num_modules));
/* All applications must have two modules. */
/* However, this is a force-open, so we will accept one module. */
@ -949,7 +949,7 @@ void DmntCheatManager::OnNewApplicationLaunch() {
{
LoaderModuleInfo proc_modules[2];
u32 num_modules;
R_ASSERT(ldrDmntGetModuleInfos(g_cheat_process_metadata.process_id, proc_modules, sizeof(proc_modules)/sizeof(proc_modules[0]), &num_modules));
R_ASSERT(ldrDmntGetModuleInfos(g_cheat_process_metadata.process_id, proc_modules, sts::util::size(proc_modules), &num_modules));
/* All applications must have two modules. */
/* If we only have one, we must be e.g. mitming HBL. */

@ -1 +1 @@
Subproject commit d6eacecce97d93b8261a9def8f69385f6a231dc9
Subproject commit c9dc24cce1e832650e6a2fc67bce465062504279

View file

@ -36,7 +36,7 @@ namespace sts::boot2 {
ncm::TitleId{TitleId_Settings}, /* settings */
ncm::TitleId{TitleId_Pcv}, /* pcv */
};
constexpr size_t NumPreSdCardLaunchPrograms = sizeof(PreSdCardLaunchPrograms) / sizeof(PreSdCardLaunchPrograms[0]);
constexpr size_t NumPreSdCardLaunchPrograms = util::size(PreSdCardLaunchPrograms);
constexpr ncm::TitleId AdditionalLaunchPrograms[] = {
ncm::TitleId{TitleId_Usb}, /* usb */
@ -81,7 +81,7 @@ namespace sts::boot2 {
ncm::TitleId{TitleId_Grc}, /* grc */
ncm::TitleId{TitleId_Olsc}, /* olsc */
};
constexpr size_t NumAdditionalLaunchPrograms = sizeof(AdditionalLaunchPrograms) / sizeof(AdditionalLaunchPrograms[0]);
constexpr size_t NumAdditionalLaunchPrograms = util::size(AdditionalLaunchPrograms);
constexpr ncm::TitleId AdditionalMaintenanceLaunchPrograms[] = {
ncm::TitleId{TitleId_Usb}, /* usb */
@ -122,7 +122,7 @@ namespace sts::boot2 {
ncm::TitleId{TitleId_Grc}, /* grc */
ncm::TitleId{TitleId_Olsc}, /* olsc */
};
constexpr size_t NumAdditionalMaintenanceLaunchPrograms = sizeof(AdditionalMaintenanceLaunchPrograms) / sizeof(AdditionalMaintenanceLaunchPrograms[0]);
constexpr size_t NumAdditionalMaintenanceLaunchPrograms = util::size(AdditionalMaintenanceLaunchPrograms);
/* Helpers. */
inline bool IsHexadecimal(const char *str) {

View file

@ -29,7 +29,7 @@ namespace sts::pm::resource {
LimitableResource_TransferMemories,
LimitableResource_Sessions,
};
constexpr size_t LimitableResource_Count = sizeof(LimitableResources) / sizeof(LimitableResources[0]);
constexpr size_t LimitableResource_Count = util::size(LimitableResources);
constexpr size_t Megabyte = 0x100000;