From 1da366f7916bcecf9259d00880503b86ed4c7391 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Tue, 25 Feb 2020 00:26:07 +1100 Subject: [PATCH] Adopted AMS_ABORT_UNLESS --- .../ncm/source/ncm_contentstorage.cpp | 9 ++---- stratosphere/ncm/source/ncm_fs.cpp | 31 ++++--------------- stratosphere/ncm/source/ncm_fs.hpp | 4 +-- stratosphere/ncm/source/ncm_make_path.cpp | 24 ++++---------- stratosphere/ncm/source/ncm_path_utils.cpp | 10 ++---- stratosphere/ncm/source/ncm_path_utils.hpp | 8 ++--- .../ncm/source/ncm_readonlycontentstorage.cpp | 6 +--- 7 files changed, 22 insertions(+), 70 deletions(-) diff --git a/stratosphere/ncm/source/ncm_contentstorage.cpp b/stratosphere/ncm/source/ncm_contentstorage.cpp index b71d371ef..c3080129e 100644 --- a/stratosphere/ncm/source/ncm_contentstorage.cpp +++ b/stratosphere/ncm/source/ncm_contentstorage.cpp @@ -30,9 +30,7 @@ namespace ams::ncm { R_TRY(fs::CheckContentStorageDirectoriesExist(root_path)); const size_t root_path_len = strnlen(root_path, FS_MAX_PATH-1); - if (root_path_len >= FS_MAX_PATH-1) { - std::abort(); - } + AMS_ABORT_UNLESS(root_path_len < FS_MAX_PATH-1); strncpy(this->root_path, root_path, FS_MAX_PATH-2); this->make_content_path_func = *content_path_func; @@ -457,9 +455,8 @@ namespace ams::ncm { bool is_development = false; - if (R_FAILED(splIsDevelopment(&is_development)) || !is_development) { - std::abort(); - } + AMS_ABORT_UNLESS(R_SUCCEEDED(splIsDevelopment(&is_development))); + AMS_ABORT_UNLESS(is_development); this->ClearContentCache(); diff --git a/stratosphere/ncm/source/ncm_fs.cpp b/stratosphere/ncm/source/ncm_fs.cpp index 491146635..c529c808c 100644 --- a/stratosphere/ncm/source/ncm_fs.cpp +++ b/stratosphere/ncm/source/ncm_fs.cpp @@ -221,10 +221,7 @@ namespace ams::ncm::fs { FsFileSystem fs; R_TRY(fsOpenSaveDataFileSystemBySystemSaveDataId(&fs, space_id, &save)); - - if (fsdevMountDevice(mount_point, fs) == -1) { - std::abort(); - } + AMS_ABORT_UNLESS(fsdevMountDevice(mount_point, fs) != -1); return ResultSuccess(); } @@ -244,10 +241,7 @@ namespace ams::ncm::fs { FsFileSystem fs; R_TRY(fsOpenContentStorageFileSystem(&fs, id)); - - if (fsdevMountDevice(mount_point, fs) == -1) { - std::abort(); - } + AMS_ABORT_UNLESS(fsdevMountDevice(mount_point, fs) != -1); switch (id) { case FsContentStorageId_System: @@ -269,16 +263,11 @@ namespace ams::ncm::fs { } Result MountGameCardPartition(const char* mount_point, const FsGameCardHandle handle, FsGameCardPartition partition) { - if (partition > 2) { - std::abort(); - } + AMS_ABORT_UNLESS(partition <= 2); FsFileSystem fs; R_TRY(fsOpenGameCardFileSystem(&fs, &handle, partition)); - - if (fsdevMountDevice(mount_point, fs) == -1) { - std::abort(); - } + AMS_ABORT_UNLESS(fsdevMountDevice(mount_point, fs) != -1); MountName mount = {0}; snprintf(mount.name, sizeof(MountName), "%s%s%08x", GameCardMountNameBase, GameCardPartitionLetters[partition], handle.value); @@ -288,14 +277,9 @@ namespace ams::ncm::fs { Result Unmount(const char* mount_point) { R_UNLESS(mount_point, ams::fs::ResultNullptrArgument()); - /* Erase any content storage mappings which may potentially exist. */ g_mount_content_storage.erase(mount_point); - - if (fsdevUnmountDevice(mount_point) == -1) { - std::abort(); - } - + AMS_ABORT_UNLESS(fsdevUnmountDevice(mount_point) != -1); return ResultSuccess(); } @@ -311,10 +295,7 @@ namespace ams::ncm::fs { char translated_path[FS_MAX_PATH] = {0}; std::string common_mount_name = g_mount_content_storage[mount_name.name]; - if (fsdevTranslatePath(path, NULL, translated_path) == -1) { - std::abort(); - } - + AMS_ABORT_UNLESS(fsdevTranslatePath(path, NULL, translated_path) != -1); snprintf(out_common_path, out_len, "%s:%s", common_mount_name.c_str(), translated_path); return ResultSuccess(); } diff --git a/stratosphere/ncm/source/ncm_fs.hpp b/stratosphere/ncm/source/ncm_fs.hpp index 1ba2c150e..9609987c6 100644 --- a/stratosphere/ncm/source/ncm_fs.hpp +++ b/stratosphere/ncm/source/ncm_fs.hpp @@ -69,9 +69,7 @@ namespace ams::ncm::fs { } char current_path[FS_MAX_PATH]; - if (snprintf(current_path, FS_MAX_PATH-1, "%s/%s", root_path, dir_entry->d_name) < 0) { - std::abort(); - } + AMS_ABORT_UNLESS(snprintf(current_path, FS_MAX_PATH-1, "%s/%s", root_path, dir_entry->d_name) >= 0); bool should_continue = true; bool should_retry_dir_read = false; diff --git a/stratosphere/ncm/source/ncm_make_path.cpp b/stratosphere/ncm/source/ncm_make_path.cpp index 8e7bb2f84..83484a428 100644 --- a/stratosphere/ncm/source/ncm_make_path.cpp +++ b/stratosphere/ncm/source/ncm_make_path.cpp @@ -38,9 +38,7 @@ namespace ams::ncm::path { void MakeContentPathFlat(char* path_out, ContentId content_id, const char* root) { char content_name[FS_MAX_PATH] = {0}; GetContentFileName(content_name, content_id); - if (snprintf(path_out, FS_MAX_PATH-1, "%s/%s", root, content_name) < 0) { - std::abort(); - } + AMS_ABORT_UNLESS(snprintf(path_out, FS_MAX_PATH-1, "%s/%s", root, content_name) >= 0); } void MakeContentPathDualLayered(char* path_out, ContentId content_id, const char* root) { @@ -50,44 +48,34 @@ namespace ams::ncm::path { const u32 hash_upper = (hash >> 10) & 0x3f; GetContentFileName(content_name, content_id); - if (snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%08X/%s", root, hash_upper, hash_lower, content_name) < 0) { - std::abort(); - } + AMS_ABORT_UNLESS(snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%08X/%s", root, hash_upper, hash_lower, content_name) >= 0); } void MakeContentPath10BitLayered(char* path_out, ContentId content_id, const char* root) { char content_name[FS_MAX_PATH] = {0}; const u32 hash = (Get16BitSha256HashPrefix(content_id.uuid) >> 6) & 0x3FF; GetContentFileName(content_name, content_id); - if (snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%s", root, hash, content_name) < 0) { - std::abort(); - } + AMS_ABORT_UNLESS(snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%s", root, hash, content_name) >= 0); } void MakeContentPathHashByteLayered(char* path_out, ContentId content_id, const char* root) { char content_name[FS_MAX_PATH] = {0}; const u32 hash_byte = static_cast(Get8BitSha256HashPrefix(content_id.uuid)); GetContentFileName(content_name, content_id); - if (snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%s", root, hash_byte, content_name) < 0) { - std::abort(); - } + AMS_ABORT_UNLESS(snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%s", root, hash_byte, content_name) >= 0); } void MakePlaceHolderPathFlat(char* path_out, PlaceHolderId placeholder_id, const char* root) { char placeholder_name[FS_MAX_PATH] = {0}; GetPlaceHolderFileName(placeholder_name, placeholder_id); - if (snprintf(path_out, FS_MAX_PATH-1, "%s/%s", root, placeholder_name) < 0) { - std::abort(); - } + AMS_ABORT_UNLESS(snprintf(path_out, FS_MAX_PATH-1, "%s/%s", root, placeholder_name) >= 0); } void MakePlaceHolderPathHashByteLayered(char* path_out, PlaceHolderId placeholder_id, const char* root) { char placeholder_name[FS_MAX_PATH] = {0}; const u32 hash_byte = static_cast(Get8BitSha256HashPrefix(placeholder_id.uuid)); GetPlaceHolderFileName(placeholder_name, placeholder_id); - if (snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%s", root, hash_byte, placeholder_name) < 0) { - std::abort(); - } + AMS_ABORT_UNLESS(snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%s", root, hash_byte, placeholder_name) >= 0); } } diff --git a/stratosphere/ncm/source/ncm_path_utils.cpp b/stratosphere/ncm/source/ncm_path_utils.cpp index db8314d3c..33d62ab39 100644 --- a/stratosphere/ncm/source/ncm_path_utils.cpp +++ b/stratosphere/ncm/source/ncm_path_utils.cpp @@ -26,18 +26,14 @@ namespace ams::ncm::path { const size_t len = strnlen(content_path, FS_MAX_PATH-1); const size_t len_no_extension = len - 4; - if (len_no_extension > len || len_no_extension >= FS_MAX_PATH-1) { - std::abort(); - } + AMS_ABORT_UNLESS(len_no_extension <= len); + AMS_ABORT_UNLESS(len_no_extension < FS_MAX_PATH-1); strncpy(tmp_path, content_path, len_no_extension); memcpy(out, tmp_path, FS_MAX_PATH-1); const size_t out_len = strnlen(out, FS_MAX_PATH-1); - if (out_len + 9 >= FS_MAX_PATH-1) { - std::abort(); - } - + AMS_ABORT_UNLESS(out_len + 9 < FS_MAX_PATH-1); strncat(out, ".cnmt.nca", 0x2ff - out_len); } diff --git a/stratosphere/ncm/source/ncm_path_utils.hpp b/stratosphere/ncm/source/ncm_path_utils.hpp index ea413848a..dadf67928 100644 --- a/stratosphere/ncm/source/ncm_path_utils.hpp +++ b/stratosphere/ncm/source/ncm_path_utils.hpp @@ -22,16 +22,12 @@ namespace ams::ncm::path { inline void GetContentRootPath(char* out_content_root, const char* root_path) { /* TODO: Replace with BoundedString? */ - if (snprintf(out_content_root, FS_MAX_PATH-1, "%s%s", root_path, "/registered") < 0) { - std::abort(); - } + AMS_ABORT_UNLESS(snprintf(out_content_root, FS_MAX_PATH-1, "%s%s", root_path, "/registered") >= 0); } inline void GetPlaceHolderRootPath(char* out_placeholder_root, const char* root_path) { /* TODO: Replace with BoundedString? */ - if (snprintf(out_placeholder_root, FS_MAX_PATH, "%s%s", root_path, "/placehld") < 0) { - std::abort(); - } + AMS_ABORT_UNLESS(snprintf(out_placeholder_root, FS_MAX_PATH, "%s%s", root_path, "/placehld") >= 0); } void GetContentMetaPath(char* out, ContentId content_id, MakeContentPathFunc path_func, const char* root_path); diff --git a/stratosphere/ncm/source/ncm_readonlycontentstorage.cpp b/stratosphere/ncm/source/ncm_readonlycontentstorage.cpp index 9c358f5ed..3585eb8fc 100644 --- a/stratosphere/ncm/source/ncm_readonlycontentstorage.cpp +++ b/stratosphere/ncm/source/ncm_readonlycontentstorage.cpp @@ -24,11 +24,7 @@ namespace ams::ncm { R_TRY(this->EnsureEnabled()); const size_t root_path_len = strnlen(root_path, FS_MAX_PATH-1); - - if (root_path_len >= FS_MAX_PATH-1) { - std::abort(); - } - + AMS_ABORT_UNLESS(root_path_len < FS_MAX_PATH-1); strncpy(this->root_path, root_path, FS_MAX_PATH-2); this->make_content_path_func = *content_path_func; return ResultSuccess();