From c916a7db8869d920f1de575515603143e0cf9a95 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 2 Jul 2019 14:36:57 -0700 Subject: [PATCH] strat: remove sizeof() / sizeof([0]) --- .../ams_mitm/source/set_mitm/set_mitm_service.cpp | 2 +- stratosphere/ams_mitm/source/utils.cpp | 2 +- stratosphere/boot/source/boot_display.cpp | 9 +++++---- .../boot/source/i2c/driver/impl/i2c_bus_accessor.cpp | 2 +- .../boot/source/i2c/driver/impl/i2c_device_config.cpp | 2 +- .../boot/source/pinmux/pinmux_initial_configuration.cpp | 2 +- stratosphere/dmnt/source/dmnt_cheat_manager.cpp | 8 ++++---- stratosphere/libstratosphere | 2 +- stratosphere/pm/source/boot2/boot2_api.cpp | 6 +++--- stratosphere/pm/source/impl/pm_resource_manager.cpp | 2 +- 10 files changed, 19 insertions(+), 18 deletions(-) diff --git a/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.cpp b/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.cpp index 88274477d..30e8ebea9 100644 --- a/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.cpp @@ -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; diff --git a/stratosphere/ams_mitm/source/utils.cpp b/stratosphere/ams_mitm/source/utils.cpp index 46e9fe236..9a77e7f88 100644 --- a/stratosphere/ams_mitm/source/utils.cpp +++ b/stratosphere/ams_mitm/source/utils.cpp @@ -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); } diff --git a/stratosphere/boot/source/boot_display.cpp b/stratosphere/boot/source/boot_display.cpp index 45bd1284b..0993364cc 100644 --- a/stratosphere/boot/source/boot_display.cpp +++ b/stratosphere/boot/source/boot_display.cpp @@ -14,6 +14,7 @@ * along with this program. If not, see . */ + #include #include @@ -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); } diff --git a/stratosphere/boot/source/i2c/driver/impl/i2c_bus_accessor.cpp b/stratosphere/boot/source/i2c/driver/impl/i2c_bus_accessor.cpp index 3ab1f31b2..9f1ad98ed 100644 --- a/stratosphere/boot/source/i2c/driver/impl/i2c_bus_accessor.cpp +++ b/stratosphere/boot/source/i2c/driver/impl/i2c_bus_accessor.cpp @@ -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(); } diff --git a/stratosphere/boot/source/i2c/driver/impl/i2c_device_config.cpp b/stratosphere/boot/source/i2c/driver/impl/i2c_device_config.cpp index 543e63afd..870131362 100644 --- a/stratosphere/boot/source/i2c/driver/impl/i2c_device_config.cpp +++ b/stratosphere/boot/source/i2c/driver/impl/i2c_device_config.cpp @@ -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(-1); diff --git a/stratosphere/boot/source/pinmux/pinmux_initial_configuration.cpp b/stratosphere/boot/source/pinmux/pinmux_initial_configuration.cpp index 507693272..ea055d2a0 100644 --- a/stratosphere/boot/source/pinmux/pinmux_initial_configuration.cpp +++ b/stratosphere/boot/source/pinmux/pinmux_initial_configuration.cpp @@ -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); } } diff --git a/stratosphere/dmnt/source/dmnt_cheat_manager.cpp b/stratosphere/dmnt/source/dmnt_cheat_manager.cpp index 3441b393b..ce4315a8d 100644 --- a/stratosphere/dmnt/source/dmnt_cheat_manager.cpp +++ b/stratosphere/dmnt/source/dmnt_cheat_manager.cpp @@ -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. */ diff --git a/stratosphere/libstratosphere b/stratosphere/libstratosphere index d6eacecce..c9dc24cce 160000 --- a/stratosphere/libstratosphere +++ b/stratosphere/libstratosphere @@ -1 +1 @@ -Subproject commit d6eacecce97d93b8261a9def8f69385f6a231dc9 +Subproject commit c9dc24cce1e832650e6a2fc67bce465062504279 diff --git a/stratosphere/pm/source/boot2/boot2_api.cpp b/stratosphere/pm/source/boot2/boot2_api.cpp index 6c00d4833..6614d61b2 100644 --- a/stratosphere/pm/source/boot2/boot2_api.cpp +++ b/stratosphere/pm/source/boot2/boot2_api.cpp @@ -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) { diff --git a/stratosphere/pm/source/impl/pm_resource_manager.cpp b/stratosphere/pm/source/impl/pm_resource_manager.cpp index 321aa66d0..e6ed25a5f 100644 --- a/stratosphere/pm/source/impl/pm_resource_manager.cpp +++ b/stratosphere/pm/source/impl/pm_resource_manager.cpp @@ -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;