From 6ad0328f1c3e145d3224197eafd0f66b17cc1a1c Mon Sep 17 00:00:00 2001 From: practicalswift Date: Tue, 26 Jun 2018 17:19:31 +0200 Subject: [PATCH] Don't assert(foo()) where foo has side effects --- src/bench/block_assemble.cpp | 3 ++- src/bench/checkblock.cpp | 9 ++++++--- src/httprpc.cpp | 5 +++-- src/script/sign.cpp | 3 ++- src/test/txvalidation_tests.cpp | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/bench/block_assemble.cpp b/src/bench/block_assemble.cpp index 36fa175a7..2bd67654a 100644 --- a/src/bench/block_assemble.cpp +++ b/src/bench/block_assemble.cpp @@ -41,7 +41,8 @@ static CTxIn MineBlock(const CScript& coinbase_scriptPubKey) auto block = PrepareBlock(coinbase_scriptPubKey); while (!CheckProofOfWork(block->GetHash(), block->nBits, Params().GetConsensus())) { - assert(++block->nNonce); + ++block->nNonce; + assert(block->nNonce); } bool processed{ProcessNewBlock(Params(), block, true, nullptr)}; diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp index fac7e079a..387ae1769 100644 --- a/src/bench/checkblock.cpp +++ b/src/bench/checkblock.cpp @@ -28,7 +28,8 @@ static void DeserializeBlockTest(benchmark::State& state) while (state.KeepRunning()) { CBlock block; stream >> block; - assert(stream.Rewind(sizeof(block_bench::block413567))); + bool rewound = stream.Rewind(sizeof(block_bench::block413567)); + assert(rewound); } } @@ -45,10 +46,12 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state) while (state.KeepRunning()) { CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here stream >> block; - assert(stream.Rewind(sizeof(block_bench::block413567))); + bool rewound = stream.Rewind(sizeof(block_bench::block413567)); + assert(rewound); CValidationState validationState; - assert(CheckBlock(block, validationState, chainParams->GetConsensus())); + bool checked = CheckBlock(block, validationState, chainParams->GetConsensus()); + assert(checked); } } diff --git a/src/httprpc.cpp b/src/httprpc.cpp index de2437943..aec92711c 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -240,8 +240,9 @@ bool StartHTTPRPC() // ifdef can be removed once we switch to better endpoint support and API versioning RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC); #endif - assert(EventBase()); - httpRPCTimerInterface = MakeUnique(EventBase()); + struct event_base* eventBase = EventBase(); + assert(eventBase); + httpRPCTimerInterface = MakeUnique(eventBase); RPCSetTimerInterface(httpRPCTimerInterface.get()); return true; } diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 60a8a2655..541d90e78 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -424,7 +424,8 @@ bool IsSolvable(const SigningProvider& provider, const CScript& script) static_assert(STANDARD_SCRIPT_VERIFY_FLAGS & SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, "IsSolvable requires standard script flags to include WITNESS_PUBKEYTYPE"); if (ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, script, sigs)) { // VerifyScript check is just defensive, and should never fail. - assert(VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER)); + bool verified = VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER); + assert(verified); return true; } return false; diff --git a/src/test/txvalidation_tests.cpp b/src/test/txvalidation_tests.cpp index 2d1eb7b77..473ec5add 100644 --- a/src/test/txvalidation_tests.cpp +++ b/src/test/txvalidation_tests.cpp @@ -30,7 +30,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup) coinbaseTx.vout[0].nValue = 1 * CENT; coinbaseTx.vout[0].scriptPubKey = scriptPubKey; - assert(CTransaction(coinbaseTx).IsCoinBase()); + BOOST_CHECK(CTransaction(coinbaseTx).IsCoinBase()); CValidationState state;