mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-01 00:34:01 +02:00
Merge bitcoin/bitcoin#34582: rpc: Properly parse -rpcworkqueue/-rpcthreads
fa5672dcafrefactor: [gui] Use SettingTo<int64_t> over deprecated SettingToInt (MarcoFalke)fac3ecaf69rpc: Properly parse -rpcworkqueue/-rpcthreads (MarcoFalke)faee36f63butil: Add SettingTo<Int>() and GetArg<Int>() (MarcoFalke) Pull request description: The integral arg parsing has many issues: * There is no way to parse an unsigned integral type at all * There is no way to parse an integral type of less width than int64_t * As a result, calling code splatters confusing c-style casts just to let the code compile. However, usually there are no range checks and proper range handling. For example, when someone (maybe for testing) wants to set the rpc work queue to the maximum possible number, there is no easy way to do so without reading the source code and manually crafting the exact integer value. Using the "9999 hack" will silently set it to `-1` (!) To test: `/bld-cmake/bin/bitcoin-qt -datadir=/tmp -regtest -rpcworkqueue=99999999999999999999999999 -printtoconsole=1 -server=1 -debug=http | grep 'set work queue of depth'` Before: ``` [http] set work queue of depth -1 ``` After: ``` [http] set work queue of depth 2147483647 ACKs for top commit: stickies-v: ACKfa5672dcafpinheadmz: ACKfa5672dcafsedited: ACKfa5672dcafTree-SHA512: e5060453a0aa1c4e27080e928b0ae2d1015fe487246e4059866eef415f301bc7712ce306d95076ce5b66a5e57c620715b33998192c0ff06b0384085a0390c714
This commit is contained in:
@@ -247,26 +247,41 @@ BOOST_AUTO_TEST_CASE(intarg)
|
||||
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
|
||||
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
|
||||
SetupArgs(local_args, {foo, bar});
|
||||
|
||||
ResetArgs(local_args, "");
|
||||
BOOST_CHECK(!local_args.GetArg<int64_t>("-foo").has_value());
|
||||
BOOST_CHECK(!local_args.GetArg<uint8_t>("-bar").has_value());
|
||||
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 11), 11);
|
||||
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), 0);
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{222}), 222);
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{0}), 0);
|
||||
|
||||
ResetArgs(local_args, "-foo -bar");
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg<int64_t>("-foo"), 0);
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg<uint8_t>("-bar"), 0);
|
||||
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 11), 0);
|
||||
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 11), 0);
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{222}), 0);
|
||||
|
||||
// Check under-/overflow behavior.
|
||||
ResetArgs(local_args, "-foo=-9223372036854775809 -bar=9223372036854775808");
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg<int64_t>("-foo"), std::numeric_limits<int64_t>::min());
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg<uint8_t>("-bar"), std::numeric_limits<uint8_t>::max());
|
||||
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), std::numeric_limits<int64_t>::min());
|
||||
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 0), std::numeric_limits<int64_t>::max());
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", uint8_t{0}), std::numeric_limits<uint8_t>::min());
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{0}), std::numeric_limits<uint8_t>::max());
|
||||
|
||||
ResetArgs(local_args, "-foo=11 -bar=12");
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg<int64_t>("-foo"), 11);
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg<uint8_t>("-bar"), 12);
|
||||
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), 11);
|
||||
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 11), 12);
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{11}), 12);
|
||||
|
||||
ResetArgs(local_args, "-foo=NaN -bar=NotANumber");
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg<int64_t>("-foo"), 0);
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg<uint8_t>("-bar"), 0);
|
||||
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 1), 0);
|
||||
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 11), 0);
|
||||
BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{11}), 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(patharg)
|
||||
|
||||
Reference in New Issue
Block a user