Skip to content

Commit e0e18a1

Browse files
committed
refactoring: Check IsArgKnown() early
1 parent dbf4f3f commit e0e18a1

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

src/util/system.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -403,20 +403,20 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
403403
if (key.length() > 1 && key[1] == '-')
404404
key.erase(0, 1);
405405

406-
// Check for -nofoo
407-
if (InterpretNegatedOption(key, val)) {
408-
m_override_args[key].clear();
409-
} else {
410-
m_override_args[key].push_back(val);
411-
}
412-
413406
// Check that the arg is known
414407
if (!(IsSwitchChar(key[0]) && key.size() == 1)) {
415408
if (!IsArgKnown(key)) {
416409
error = strprintf("Invalid parameter %s", key.c_str());
417410
return false;
418411
}
419412
}
413+
414+
// Check for -nofoo
415+
if (InterpretNegatedOption(key, val)) {
416+
m_override_args[key].clear();
417+
} else {
418+
m_override_args[key].push_back(val);
419+
}
420420
}
421421

422422
// we do not allow -includeconf from command line, so we clear it here
@@ -434,17 +434,23 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
434434

435435
bool ArgsManager::IsArgKnown(const std::string& key) const
436436
{
437+
assert(key[0] == '-');
438+
437439
size_t option_index = key.find('.');
438-
std::string arg_no_net;
439440
if (option_index == std::string::npos) {
440-
arg_no_net = key;
441+
option_index = 1;
441442
} else {
442-
arg_no_net = std::string("-") + key.substr(option_index + 1, std::string::npos);
443+
++option_index;
443444
}
445+
if (key.substr(option_index, 2) == "no") {
446+
option_index += 2;
447+
}
448+
449+
const std::string base_arg_name = '-' + key.substr(option_index);
444450

445451
LOCK(cs_args);
446452
for (const auto& arg_map : m_available_args) {
447-
if (arg_map.second.count(arg_no_net)) return true;
453+
if (arg_map.second.count(base_arg_name)) return true;
448454
}
449455
return false;
450456
}
@@ -840,23 +846,23 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
840846
}
841847
for (const std::pair<std::string, std::string>& option : options) {
842848
std::string strKey = std::string("-") + option.first;
843-
std::string strValue = option.second;
844-
845-
if (InterpretNegatedOption(strKey, strValue)) {
846-
m_config_args[strKey].clear();
847-
} else {
848-
m_config_args[strKey].push_back(strValue);
849-
}
850-
851849
// Check that the arg is known
852850
if (!IsArgKnown(strKey)) {
853851
if (!ignore_invalid_keys) {
854852
error = strprintf("Invalid configuration value %s", option.first.c_str());
855853
return false;
856854
} else {
857855
LogPrintf("Ignoring unknown configuration value %s\n", option.first);
856+
continue;
858857
}
859858
}
859+
860+
std::string strValue = option.second;
861+
if (InterpretNegatedOption(strKey, strValue)) {
862+
m_config_args[strKey].clear();
863+
} else {
864+
m_config_args[strKey].push_back(strValue);
865+
}
860866
}
861867
return true;
862868
}

0 commit comments

Comments
 (0)