From 81aa5c7ec7968a25b08de27934dedccee39c7266 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 28 Mar 2019 23:04:13 -0700 Subject: [PATCH] set_mitm: result defs instead of magics --- .../source/set_mitm/setsys_mitm_service.cpp | 2 +- .../source/set_mitm/setsys_settings_items.cpp | 40 +++++++++---------- stratosphere/libstratosphere | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp index e12e3d5a0..fa3ad5af4 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp @@ -90,7 +90,7 @@ Result SetSysMitmService::GetSettingsItemValue(Out out_size, OutBuffer } if (out_value.buffer == nullptr) { - return 0x19A69; + return ResultSettingsItemValueBufferNull; } if (in_name.num_elements < SET_MAX_NAME_SIZE) { diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_settings_items.cpp b/stratosphere/ams_mitm/source/set_mitm/setsys_settings_items.cpp index 800bce844..489717ecd 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_settings_items.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_settings_items.cpp @@ -73,18 +73,18 @@ static bool IsCorrectFormat(const char *str, size_t len) { Result SettingsItemManager::ValidateName(const char *name, size_t max_size) { if (name == nullptr) { - return 0x19269; + return ResultSettingsItemNameNull; } const size_t name_len = strnlen(name, std::min(max_size, MaxNameLength + 1)); if (name_len == 0) { - return 0x1BA69; + return ResultSettingsItemNameEmpty; } else if (name_len > MaxNameLength) { - return 0x1E269; + return ResultSettingsItemNameTooLong; } if (!IsCorrectFormat(name, name_len)) { - return 0x20A69; + return ResultSettingsItemNameInvalidFormat; } return ResultSuccess; @@ -96,18 +96,18 @@ Result SettingsItemManager::ValidateName(const char *name) { Result SettingsItemManager::ValidateKey(const char *key, size_t max_size) { if (key == nullptr) { - return 0x19469; + return ResultSettingsItemKeyNull; } const size_t key_len = strnlen(key, std::min(max_size, MaxKeyLength + 1)); if (key_len == 0) { - return 0x1BC69; + return ResultSettingsItemKeyEmpty; } else if (key_len > MaxKeyLength) { - return 0x1E469; + return ResultSettingsItemKeyTooLong; } if (!IsCorrectFormat(key, key_len)) { - return 0x20C69; + return ResultSettingsItemKeyInvalidFormat; } return ResultSuccess; @@ -141,7 +141,7 @@ static Result ParseValue(const char *name, const char *key, const char *val_tup) const char *type = val_tup; if (delimiter == NULL) { - return 0x20E69; + return ResultSettingsItemValueInvalidFormat; } while (isspace(*type) && type != delimiter) { @@ -151,7 +151,7 @@ static Result ParseValue(const char *name, const char *key, const char *val_tup) size_t type_len = delimiter - type; size_t value_len = strlen(value_str); if (delimiter == NULL || value_len == 0 || type_len == 0) { - return 0x20E69; + return ResultSettingsItemValueInvalidFormat; } std::string kv = std::string(name) + "!" + std::string(key); @@ -162,17 +162,17 @@ static Result ParseValue(const char *name, const char *key, const char *val_tup) value.size = value_len + 1; value.data = reinterpret_cast(strdup(value_str)); if (value.data == nullptr) { - return 0xCC69; + return ResultSettingsItemValueAllocationFailed; } } else if (strncasecmp(type, "hex", type_len) == 0 || strncasecmp(type, "bytes", type_len) == 0) { /* hex */ if (value_len % 2 || !IsHexadecimal(value_str)) { - return 0x20E69; + return ResultSettingsItemValueInvalidFormat; } value.size = value_len / 2; u8 *data = reinterpret_cast(malloc(value.size)); if (data == nullptr) { - return 0xCC69; + return ResultSettingsItemValueAllocationFailed; } memset(data, 0, value.size); @@ -186,7 +186,7 @@ static Result ParseValue(const char *name, const char *key, const char *val_tup) value.size = sizeof(u8); u8 *data = reinterpret_cast(malloc(value.size)); if (data == nullptr) { - return 0xCC69; + return ResultSettingsItemValueAllocationFailed; } *data = (u8)(strtoul(value_str, nullptr, 0)); value.data = reinterpret_cast(data); @@ -195,7 +195,7 @@ static Result ParseValue(const char *name, const char *key, const char *val_tup) value.size = sizeof(u16); u16 *data = reinterpret_cast(malloc(value.size)); if (data == nullptr) { - return 0xCC69; + return ResultSettingsItemValueAllocationFailed; } *data = (u16)(strtoul(value_str, nullptr, 0)); value.data = reinterpret_cast(data); @@ -204,7 +204,7 @@ static Result ParseValue(const char *name, const char *key, const char *val_tup) value.size = sizeof(u32); u32 *data = reinterpret_cast(malloc(value.size)); if (data == nullptr) { - return 0xCC69; + return ResultSettingsItemValueAllocationFailed; } *data = (u32)(strtoul(value_str, nullptr, 0)); value.data = reinterpret_cast(data); @@ -213,12 +213,12 @@ static Result ParseValue(const char *name, const char *key, const char *val_tup) value.size = sizeof(u64); u64 *data = reinterpret_cast(malloc(value.size)); if (data == nullptr) { - return 0xCC69; + return ResultSettingsItemValueAllocationFailed; } *data = (u64)(strtoul(value_str, nullptr, 0)); value.data = reinterpret_cast(data); } else { - return 0x20E69; + return ResultSettingsItemValueInvalidFormat; } g_settings_items[kv] = value; @@ -283,7 +283,7 @@ Result SettingsItemManager::GetValueSize(const char *name, const char *key, u64 auto it = g_settings_items.find(kv); if (it == g_settings_items.end()) { - return 0x1669; + return ResultSettingsItemNotFound; } *out_size = it->second.size; @@ -295,7 +295,7 @@ Result SettingsItemManager::GetValue(const char *name, const char *key, void *ou auto it = g_settings_items.find(kv); if (it == g_settings_items.end()) { - return 0x1669; + return ResultSettingsItemNotFound; } size_t copy_size = it->second.size; diff --git a/stratosphere/libstratosphere b/stratosphere/libstratosphere index 1034e0744..37b74c7d7 160000 --- a/stratosphere/libstratosphere +++ b/stratosphere/libstratosphere @@ -1 +1 @@ -Subproject commit 1034e0744afcdaecaeb4ab6cb05c6011c75bfb3e +Subproject commit 37b74c7d754c6e6e73278864264940cba4f651db