1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-18 09:56:40 +00:00

Merge pull request #550 from lioncash/resource

setsys_settings_items: Minor cleanup to string buffer management
This commit is contained in:
SciresM 2019-06-03 19:58:06 -07:00 committed by GitHub
commit f29ab6d0f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -154,7 +154,7 @@ static Result ParseValue(const char *name, const char *key, const char *val_tup)
return ResultSettingsItemValueInvalidFormat; return ResultSettingsItemValueInvalidFormat;
} }
std::string kv = std::string(name) + "!" + std::string(key); std::string kv = std::string(name).append("!").append(key);
SettingsItemValue value; SettingsItemValue value;
if (strncasecmp(type, "str", type_len) == 0 || strncasecmp(type, "string", type_len) == 0) { if (strncasecmp(type, "str", type_len) == 0 || strncasecmp(type, "string", type_len) == 0) {
@ -254,20 +254,16 @@ void SettingsItemManager::LoadConfiguration() {
}; };
/* Allocate buffer. */ /* Allocate buffer. */
char *config_buf = new char[0x10000]; std::string config_buf(0xFFFF, '\0');
std::memset(config_buf, 0, 0x10000);
ON_SCOPE_EXIT {
delete[] config_buf;
};
/* Read from file. */ /* Read from file. */
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
size_t actual_size; size_t actual_size;
rc = fsFileRead(&config_file, 0, config_buf, 0xFFFF, FS_READOPTION_NONE, &actual_size); rc = fsFileRead(&config_file, 0, config_buf.data(), config_buf.size(), FS_READOPTION_NONE, &actual_size);
} }
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
ini_parse_string(config_buf, SettingsItemIniHandler, &rc); ini_parse_string(config_buf.c_str(), SettingsItemIniHandler, &rc);
} }
/* Report error if we encountered one. */ /* Report error if we encountered one. */
@ -279,7 +275,7 @@ void SettingsItemManager::LoadConfiguration() {
} }
Result SettingsItemManager::GetValueSize(const char *name, const char *key, u64 *out_size) { Result SettingsItemManager::GetValueSize(const char *name, const char *key, u64 *out_size) {
std::string kv = std::string(name) + "!" + std::string(key); const std::string kv = std::string(name).append("!").append(key);
auto it = g_settings_items.find(kv); auto it = g_settings_items.find(kv);
if (it == g_settings_items.end()) { if (it == g_settings_items.end()) {
@ -291,7 +287,7 @@ Result SettingsItemManager::GetValueSize(const char *name, const char *key, u64
} }
Result SettingsItemManager::GetValue(const char *name, const char *key, void *out, size_t max_size, u64 *out_size) { Result SettingsItemManager::GetValue(const char *name, const char *key, void *out, size_t max_size, u64 *out_size) {
std::string kv = std::string(name) + "!" + std::string(key); const std::string kv = std::string(name).append("!").append(key);
auto it = g_settings_items.find(kv); auto it = g_settings_items.find(kv);
if (it == g_settings_items.end()) { if (it == g_settings_items.end()) {