Merge #12516: Avoid unintentional unsigned integer wraparounds in tests

2736c9e05 Avoid unintentional unsigned integer wraparounds in tests (practicalswift)

Pull request description:

  Avoid unintentional unsigned integer wraparounds in tests.

  This is a subset of #11535 as suggested by @MarcoFalke :-)

Tree-SHA512: 4f4ee8a08870101a3f7451aefa77ae06aaf44e3c3b2f7555faa2b8a8503f97f34e34dffcf65154278f15767dc9823955f52d1aa7b39930b390e57cdf2b65e0f3
This commit is contained in:
Wladimir J. van der Laan 2018-03-05 18:56:33 +01:00
commit 7f99964321
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D
3 changed files with 5 additions and 5 deletions

View File

@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt)
test.erase(InsecureRandRange(test.size())); test.erase(InsecureRandRange(test.size()));
} }
if (InsecureRandBits(3) == 2) { if (InsecureRandBits(3) == 2) {
int new_size = std::max<int>(0, std::min<int>(30, test.size() + (InsecureRandRange(5)) - 2)); int new_size = std::max(0, std::min(30, (int)test.size() + (int)InsecureRandRange(5) - 2));
test.resize(new_size); test.resize(new_size);
} }
if (InsecureRandBits(3) == 3) { if (InsecureRandBits(3) == 3) {

View File

@ -56,8 +56,8 @@ BOOST_AUTO_TEST_CASE(manythreads)
int counter[10] = { 0 }; int counter[10] = { 0 };
FastRandomContext rng(42); FastRandomContext rng(42);
auto zeroToNine = [](FastRandomContext& rc) -> int { return rc.randrange(10); }; // [0, 9] auto zeroToNine = [](FastRandomContext& rc) -> int { return rc.randrange(10); }; // [0, 9]
auto randomMsec = [](FastRandomContext& rc) -> int { return -11 + rc.randrange(1012); }; // [-11, 1000] auto randomMsec = [](FastRandomContext& rc) -> int { return -11 + (int)rc.randrange(1012); }; // [-11, 1000]
auto randomDelta = [](FastRandomContext& rc) -> int { return -1000 + rc.randrange(2001); }; // [-1000, 1000] auto randomDelta = [](FastRandomContext& rc) -> int { return -1000 + (int)rc.randrange(2001); }; // [-1000, 1000]
boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now(); boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now();
boost::chrono::system_clock::time_point now = start; boost::chrono::system_clock::time_point now = start;

View File

@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
wtx.mapValue["comment"] = "y"; wtx.mapValue["comment"] = "y";
{ {
CMutableTransaction tx(*wtx.tx); CMutableTransaction tx(*wtx.tx);
--tx.nLockTime; // Just to change the hash :) ++tx.nLockTime; // Just to change the hash :)
wtx.SetTx(MakeTransactionRef(std::move(tx))); wtx.SetTx(MakeTransactionRef(std::move(tx)));
} }
pwalletMain->AddToWallet(wtx); pwalletMain->AddToWallet(wtx);
@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
wtx.mapValue["comment"] = "x"; wtx.mapValue["comment"] = "x";
{ {
CMutableTransaction tx(*wtx.tx); CMutableTransaction tx(*wtx.tx);
--tx.nLockTime; // Just to change the hash :) ++tx.nLockTime; // Just to change the hash :)
wtx.SetTx(MakeTransactionRef(std::move(tx))); wtx.SetTx(MakeTransactionRef(std::move(tx)));
} }
pwalletMain->AddToWallet(wtx); pwalletMain->AddToWallet(wtx);