From 5c610a22250e78a26cea0d7a816925d52fad632b Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 28 Sep 2019 15:13:20 -0700 Subject: [PATCH] sts: add STS_UNREACHABLE_DEFAULT_CASE() --- include/stratosphere/defines.hpp | 2 ++ source/firmware_version.cpp | 8 ++------ source/os/os_system_event.cpp | 18 ++++++------------ source/os/os_waitable_holder.cpp | 6 ++---- source/spl/spl_api.cpp | 3 +-- source/updater/updater_api.cpp | 18 ++++++------------ source/updater/updater_bis_management.hpp | 11 +++++++---- source/updater/updater_paths.cpp | 9 +++------ 8 files changed, 29 insertions(+), 46 deletions(-) diff --git a/include/stratosphere/defines.hpp b/include/stratosphere/defines.hpp index aecf6aa7..3cd70b67 100644 --- a/include/stratosphere/defines.hpp +++ b/include/stratosphere/defines.hpp @@ -21,6 +21,8 @@ #define STS_ASSERT(expr) do { if (!(expr)) { std::abort(); } } while (0) +#define STS_UNREACHABLE_DEFAULT_CASE() default: std::abort() + #define NON_COPYABLE(cls) \ cls(const cls&) = delete; \ cls& operator=(const cls&) = delete diff --git a/source/firmware_version.cpp b/source/firmware_version.cpp index c444ad49..cc1344a7 100644 --- a/source/firmware_version.cpp +++ b/source/firmware_version.cpp @@ -77,9 +77,7 @@ static void _CacheValues(void) case AtmosphereTargetFirmware_900: g_firmware_version = FirmwareVersion_900; break; - default: - std::abort(); - break; + STS_UNREACHABLE_DEFAULT_CASE(); } __atomic_store_n(&g_HasCached, true, __ATOMIC_SEQ_CST); @@ -145,9 +143,7 @@ void SetFirmwareVersionForLibnx() { minor = 0; micro = 0; break; - default: - std::abort(); - break; + STS_UNREACHABLE_DEFAULT_CASE(); } hosversionSet(MAKEHOSVERSION(major, minor, micro)); } diff --git a/source/os/os_system_event.cpp b/source/os/os_system_event.cpp index 1e64fa03..2e596a9c 100644 --- a/source/os/os_system_event.cpp +++ b/source/os/os_system_event.cpp @@ -116,8 +116,7 @@ namespace sts::os { case SystemEventState::InterProcessEvent: this->GetInterProcessEvent().~InterProcessEvent(); break; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } this->state = SystemEventState::Uninitialized; } @@ -131,8 +130,7 @@ namespace sts::os { this->GetInterProcessEvent().Signal(); break; case SystemEventState::Uninitialized: - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -145,8 +143,7 @@ namespace sts::os { this->GetInterProcessEvent().Reset(); break; case SystemEventState::Uninitialized: - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } void SystemEvent::Wait() { @@ -158,8 +155,7 @@ namespace sts::os { this->GetInterProcessEvent().Wait(); break; case SystemEventState::Uninitialized: - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -170,8 +166,7 @@ namespace sts::os { case SystemEventState::InterProcessEvent: return this->GetInterProcessEvent().TryWait(); case SystemEventState::Uninitialized: - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -182,8 +177,7 @@ namespace sts::os { case SystemEventState::InterProcessEvent: return this->GetInterProcessEvent().TimedWait(ns); case SystemEventState::Uninitialized: - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } } diff --git a/source/os/os_waitable_holder.cpp b/source/os/os_waitable_holder.cpp index c44b65f5..b908f3d0 100644 --- a/source/os/os_waitable_holder.cpp +++ b/source/os/os_waitable_holder.cpp @@ -48,8 +48,7 @@ namespace sts::os { new (GetPointer(this->impl_storage)) impl::WaitableHolderOfInterProcessEvent(&event->GetInterProcessEvent()); break; case SystemEventState::Uninitialized: - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } /* Set user-data. */ @@ -81,8 +80,7 @@ namespace sts::os { case MessageQueueWaitKind::ForNotEmpty: new (GetPointer(this->impl_storage)) impl::WaitableHolderOfMessageQueueForNotEmpty(message_queue); break; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } /* Set user-data. */ diff --git a/source/spl/spl_api.cpp b/source/spl/spl_api.cpp index 140d44a1..23c3eb2b 100644 --- a/source/spl/spl_api.cpp +++ b/source/spl/spl_api.cpp @@ -70,8 +70,7 @@ namespace sts::spl { case HardwareType::Hoag: case HardwareType::Iowa: return true; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } diff --git a/source/updater/updater_api.cpp b/source/updater/updater_api.cpp index d078b965..7481d533 100644 --- a/source/updater/updater_api.cpp +++ b/source/updater/updater_api.cpp @@ -72,8 +72,7 @@ namespace sts::updater { return true; case BootImageUpdateType::Mariko: return false; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -83,8 +82,7 @@ namespace sts::updater { return true; case BootImageUpdateType::Mariko: return false; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -94,8 +92,7 @@ namespace sts::updater { return NcmContentMetaType_BootImagePackage; case BootModeType::Safe: return NcmContentMetaType_BootImagePackageSafe; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -185,8 +182,7 @@ namespace sts::updater { return VerifyBootImagesNormal(data_id, work_buffer, work_buffer_size, boot_image_update_type); case BootModeType::Safe: return VerifyBootImagesSafe(data_id, work_buffer, work_buffer_size, boot_image_update_type); - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -311,8 +307,7 @@ namespace sts::updater { return UpdateBootImagesNormal(data_id, work_buffer, work_buffer_size, boot_image_update_type); case BootModeType::Safe: return UpdateBootImagesSafe(data_id, work_buffer, work_buffer_size, boot_image_update_type); - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -505,8 +500,7 @@ namespace sts::updater { case spl::HardwareType::Hoag: case spl::HardwareType::Iowa: return BootImageUpdateType::Mariko; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } diff --git a/source/updater/updater_bis_management.hpp b/source/updater/updater_bis_management.hpp index 83078e21..829d465d 100644 --- a/source/updater/updater_bis_management.hpp +++ b/source/updater/updater_bis_management.hpp @@ -130,12 +130,16 @@ namespace sts::updater { PartitionAccessor(FsBisStorageId id) : BisAccessor(id) { } private: constexpr const OffsetSizeType *FindEntry(EnumType which) { + const OffsetSizeType *entry = nullptr; for (size_t i = 0; i < Meta::NumEntries; i++) { if (Meta::Entries[i].which == which) { - return &Meta::Entries[i]; + entry = &Meta::Entries[i]; + break; } } - std::abort(); + + STS_ASSERT(entry != nullptr); + return entry; } public: Result Read(size_t *out_size, void *dst, size_t size, EnumType which) { @@ -194,8 +198,7 @@ namespace sts::updater { return FsBisStorageId_BootConfigAndPackage2RepairMain; case Package2Type::RepairSub: return FsBisStorageId_BootConfigAndPackage2RepairSub; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } diff --git a/source/updater/updater_paths.cpp b/source/updater/updater_paths.cpp index 228d89c4..01c90612 100644 --- a/source/updater/updater_paths.cpp +++ b/source/updater/updater_paths.cpp @@ -72,8 +72,7 @@ namespace sts::updater { constexpr const char *candidates[] = {BctPathA, BctPathNx}; return ChooseCandidatePath(candidates, util::size(candidates)); } - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -89,8 +88,7 @@ namespace sts::updater { constexpr const char *candidates[] = {Package1PathA, Package1PathNx}; return ChooseCandidatePath(candidates, util::size(candidates)); } - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -106,8 +104,7 @@ namespace sts::updater { constexpr const char *candidates[] = {Package2PathA, Package2PathNx}; return ChooseCandidatePath(candidates, util::size(candidates)); } - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE();; } }