mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-25 20:02:40 +01:00
config: do not use dynamic memory + bail out early on error
This commit is contained in:
parent
05db65dbbc
commit
1dc06d9a35
@ -109,37 +109,32 @@ bool GameConfig::parseConfig(
|
||||
GameConfig::ParseType srcType, const std::string &source,
|
||||
ParseType destType, std::string &destination)
|
||||
{
|
||||
bool success = true;
|
||||
pt::ptree srcTree;
|
||||
|
||||
if ((srcType == ParseType::STRING) || (srcType == ParseType::FILE)) {
|
||||
std::istream *istream = nullptr;
|
||||
try {
|
||||
switch (srcType) {
|
||||
case ParseType::STRING:
|
||||
istream = new std::istringstream(source);
|
||||
pt::read_ini(source, srcTree);
|
||||
break;
|
||||
case ParseType::FILE:
|
||||
istream = new std::ifstream(source);
|
||||
{
|
||||
std::ifstream ifs(source);
|
||||
pt::read_ini(ifs, srcTree);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//Cannot reach here
|
||||
success = false;
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
if (istream != nullptr) {
|
||||
try {
|
||||
pt::read_ini(*istream, srcTree);
|
||||
} catch (pt::ini_parser_error &e) {
|
||||
success = false;
|
||||
RW_MESSAGE(e.what());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
success = false;
|
||||
RW_MESSAGE("Unable to create stream from source.");
|
||||
}
|
||||
delete istream;
|
||||
}
|
||||
|
||||
bool success = true;
|
||||
|
||||
auto read_config = [&](const std::string &key, auto &target,
|
||||
const auto &defaultValue, auto &translator,
|
||||
bool optional=true) {
|
||||
@ -196,6 +191,9 @@ bool GameConfig::parseConfig(
|
||||
|
||||
read_config("input.invert_y", this->m_inputInvertY, false, boolt);
|
||||
|
||||
if (!success)
|
||||
return success;
|
||||
|
||||
if ((destType == ParseType::STRING) || (destType == ParseType::FILE)) {
|
||||
std::ostringstream ostream;
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user