mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-18 17:11:23 +00:00
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().
This commit is contained in:
parent
50e307b4b7
commit
452c61db7a
@ -252,24 +252,20 @@ void SettingsItemManager::LoadConfiguration() {
|
|||||||
ON_SCOPE_EXIT {
|
ON_SCOPE_EXIT {
|
||||||
fsFileClose(&config_file);
|
fsFileClose(&config_file);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* 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. */
|
||||||
if (R_FAILED(rc) && !g_threw_fatal) {
|
if (R_FAILED(rc) && !g_threw_fatal) {
|
||||||
g_threw_fatal = true;
|
g_threw_fatal = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user