Skip to content

Commit 6ad0328

Browse files
Don't assert(foo()) where foo has side effects
1 parent 0212187 commit 6ad0328

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

src/bench/block_assemble.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ static CTxIn MineBlock(const CScript& coinbase_scriptPubKey)
4141
auto block = PrepareBlock(coinbase_scriptPubKey);
4242

4343
while (!CheckProofOfWork(block->GetHash(), block->nBits, Params().GetConsensus())) {
44-
assert(++block->nNonce);
44+
++block->nNonce;
45+
assert(block->nNonce);
4546
}
4647

4748
bool processed{ProcessNewBlock(Params(), block, true, nullptr)};

src/bench/checkblock.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ static void DeserializeBlockTest(benchmark::State& state)
2828
while (state.KeepRunning()) {
2929
CBlock block;
3030
stream >> block;
31-
assert(stream.Rewind(sizeof(block_bench::block413567)));
31+
bool rewound = stream.Rewind(sizeof(block_bench::block413567));
32+
assert(rewound);
3233
}
3334
}
3435

@@ -45,10 +46,12 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state)
4546
while (state.KeepRunning()) {
4647
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
4748
stream >> block;
48-
assert(stream.Rewind(sizeof(block_bench::block413567)));
49+
bool rewound = stream.Rewind(sizeof(block_bench::block413567));
50+
assert(rewound);
4951

5052
CValidationState validationState;
51-
assert(CheckBlock(block, validationState, chainParams->GetConsensus()));
53+
bool checked = CheckBlock(block, validationState, chainParams->GetConsensus());
54+
assert(checked);
5255
}
5356
}
5457

src/httprpc.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ bool StartHTTPRPC()
240240
// ifdef can be removed once we switch to better endpoint support and API versioning
241241
RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC);
242242
#endif
243-
assert(EventBase());
244-
httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(EventBase());
243+
struct event_base* eventBase = EventBase();
244+
assert(eventBase);
245+
httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(eventBase);
245246
RPCSetTimerInterface(httpRPCTimerInterface.get());
246247
return true;
247248
}

src/script/sign.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ bool IsSolvable(const SigningProvider& provider, const CScript& script)
424424
static_assert(STANDARD_SCRIPT_VERIFY_FLAGS & SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, "IsSolvable requires standard script flags to include WITNESS_PUBKEYTYPE");
425425
if (ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, script, sigs)) {
426426
// VerifyScript check is just defensive, and should never fail.
427-
assert(VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER));
427+
bool verified = VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER);
428+
assert(verified);
428429
return true;
429430
}
430431
return false;

src/test/txvalidation_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
3030
coinbaseTx.vout[0].nValue = 1 * CENT;
3131
coinbaseTx.vout[0].scriptPubKey = scriptPubKey;
3232

33-
assert(CTransaction(coinbaseTx).IsCoinBase());
33+
BOOST_CHECK(CTransaction(coinbaseTx).IsCoinBase());
3434

3535
CValidationState state;
3636

0 commit comments

Comments
 (0)