From 452c61db7a2ab4df5894b46fee3d7534e8b3db1e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Jun 2019 20:54:24 -0400 Subject: [PATCH] setsys_settings_items: Simplify buffer management in LoadConfiguration() We can use a std::string here instead of setting up a scope guard and manual allocations. We also don't need to care about null-termination, as c_str() will automatically ensure this is done when passing it into ini_parse_string(). --- .../source/set_mitm/setsys_settings_items.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) 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 ef483d696..e19965119 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_settings_items.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_settings_items.cpp @@ -252,24 +252,20 @@ void SettingsItemManager::LoadConfiguration() { ON_SCOPE_EXIT { fsFileClose(&config_file); }; - + /* Allocate buffer. */ - char *config_buf = new char[0x10000]; - std::memset(config_buf, 0, 0x10000); - ON_SCOPE_EXIT { - delete[] config_buf; - }; - + std::string config_buf(0xFFFF, '\0'); + /* Read from file. */ if (R_SUCCEEDED(rc)) { 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)) { - ini_parse_string(config_buf, SettingsItemIniHandler, &rc); + ini_parse_string(config_buf.c_str(), SettingsItemIniHandler, &rc); } - + /* Report error if we encountered one. */ if (R_FAILED(rc) && !g_threw_fatal) { g_threw_fatal = true;