refactor: Remove redundant call to IsArgSet

Checking for IsArgSet before calling GetArg while providing an arbitrary
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.

Even better would be to provide the true fallback value and sanitize it
as if it were user-input, but this can be done in a follow-up.

Removing the redundant call to IsArgSet will have to be done either way,
so do it now.
This commit is contained in:
MarcoFalke
2025-02-18 15:43:11 +01:00
parent fa29842c1f
commit fa2b529f92
4 changed files with 39 additions and 40 deletions

View File

@@ -1038,9 +1038,9 @@ bool AppInitParameterInteraction(const ArgsManager& args)
// Sanity check argument for min fee for including tx in block
// TODO: Harmonize which arguments need sanity checking and where that happens
if (args.IsArgSet("-blockmintxfee")) {
if (!ParseMoney(args.GetArg("-blockmintxfee", ""))) {
return InitError(AmountErrMsg("blockmintxfee", args.GetArg("-blockmintxfee", "")));
if (const auto arg{args.GetArg("-blockmintxfee")}) {
if (!ParseMoney(*arg)) {
return InitError(AmountErrMsg("blockmintxfee", *arg));
}
}
@@ -1183,11 +1183,10 @@ bool CheckHostPortOptions(const ArgsManager& args) {
"-port",
"-rpcport",
}) {
if (args.IsArgSet(port_option)) {
const std::string port = args.GetArg(port_option, "");
if (const auto port{args.GetArg(port_option)}) {
uint16_t n;
if (!ParseUInt16(port, &n) || n == 0) {
return InitError(InvalidPortErrMsg(port_option, port));
if (!ParseUInt16(*port, &n) || n == 0) {
return InitError(InvalidPortErrMsg(port_option, *port));
}
}
}