refactor: Remove IsArgSet guard when fallback value is provided

Checking for IsArgSet before calling GetArg while providing the args
default value as fallback is both confusing and fragile.

It is confusing, because the provided fallback is dead code. So it would
be better to just call GetArg without a fallback.

However, ignoring the fallback value is fragile, because it would not be
sanitized.

Fix all issues by sanitizing the fallback value.
This commit is contained in:
MarcoFalke 2025-02-18 12:56:59 +01:00
parent 1d281daf86
commit fa29842c1f
No known key found for this signature in database
2 changed files with 3 additions and 3 deletions

View file

@ -1059,7 +1059,7 @@ static void ParseGetInfoResult(UniValue& result)
} }
#endif #endif
if (gArgs.IsArgSet("-color")) { {
const std::string color{gArgs.GetArg("-color", DEFAULT_COLOR_SETTING)}; const std::string color{gArgs.GetArg("-color", DEFAULT_COLOR_SETTING)};
if (color == "always") { if (color == "always") {
should_colorize = true; should_colorize = true;

View file

@ -1044,14 +1044,14 @@ bool AppInitParameterInteraction(const ArgsManager& args)
} }
} }
if (args.IsArgSet("-blockmaxweight")) { {
const auto max_block_weight = args.GetIntArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT); const auto max_block_weight = args.GetIntArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT);
if (max_block_weight > MAX_BLOCK_WEIGHT) { if (max_block_weight > MAX_BLOCK_WEIGHT) {
return InitError(strprintf(_("Specified -blockmaxweight (%d) exceeds consensus maximum block weight (%d)"), max_block_weight, MAX_BLOCK_WEIGHT)); return InitError(strprintf(_("Specified -blockmaxweight (%d) exceeds consensus maximum block weight (%d)"), max_block_weight, MAX_BLOCK_WEIGHT));
} }
} }
if (args.IsArgSet("-blockreservedweight")) { {
const auto block_reserved_weight = args.GetIntArg("-blockreservedweight", DEFAULT_BLOCK_RESERVED_WEIGHT); const auto block_reserved_weight = args.GetIntArg("-blockreservedweight", DEFAULT_BLOCK_RESERVED_WEIGHT);
if (block_reserved_weight > MAX_BLOCK_WEIGHT) { if (block_reserved_weight > MAX_BLOCK_WEIGHT) {
return InitError(strprintf(_("Specified -blockreservedweight (%d) exceeds consensus maximum block weight (%d)"), block_reserved_weight, MAX_BLOCK_WEIGHT)); return InitError(strprintf(_("Specified -blockreservedweight (%d) exceeds consensus maximum block weight (%d)"), block_reserved_weight, MAX_BLOCK_WEIGHT));