Skip to content

Commit fa29842

Browse files
author
MarcoFalke
committed
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.
1 parent 1d281da commit fa29842

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ static void ParseGetInfoResult(UniValue& result)
10591059
}
10601060
#endif
10611061

1062-
if (gArgs.IsArgSet("-color")) {
1062+
{
10631063
const std::string color{gArgs.GetArg("-color", DEFAULT_COLOR_SETTING)};
10641064
if (color == "always") {
10651065
should_colorize = true;

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,14 +1044,14 @@ bool AppInitParameterInteraction(const ArgsManager& args)
10441044
}
10451045
}
10461046

1047-
if (args.IsArgSet("-blockmaxweight")) {
1047+
{
10481048
const auto max_block_weight = args.GetIntArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT);
10491049
if (max_block_weight > MAX_BLOCK_WEIGHT) {
10501050
return InitError(strprintf(_("Specified -blockmaxweight (%d) exceeds consensus maximum block weight (%d)"), max_block_weight, MAX_BLOCK_WEIGHT));
10511051
}
10521052
}
10531053

1054-
if (args.IsArgSet("-blockreservedweight")) {
1054+
{
10551055
const auto block_reserved_weight = args.GetIntArg("-blockreservedweight", DEFAULT_BLOCK_RESERVED_WEIGHT);
10561056
if (block_reserved_weight > MAX_BLOCK_WEIGHT) {
10571057
return InitError(strprintf(_("Specified -blockreservedweight (%d) exceeds consensus maximum block weight (%d)"), block_reserved_weight, MAX_BLOCK_WEIGHT));

0 commit comments

Comments
 (0)