Skip to content

Commit 1811e48

Browse files
committed
Merge #20575: Do not run functions with necessary side-effects in assert()
5021810 Make CanFlushToDisk a const member function (practicalswift) 281cf99 Do not run functions with necessary side-effects in assert() (practicalswift) Pull request description: Do not run functions with necessary side-effects in `assert()`. ACKs for top commit: laanwj: Code review ACK 5021810 sipa: utACK 5021810 theStack: Code Review ACK 5021810 🟢 Tree-SHA512: 38b7faccc2f16a499f9b7b1b962b49eb58580b2a2bbf63ea49dcc418a5ecc8f21a0972fa953f66db9509c7239af67cfa2f9266423fd220963d091034d7332b96
2 parents 4acbcfa + 5021810 commit 1811e48

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/bench/chacha_poly_aead.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ static void CHACHA20_POLY1305_AEAD(benchmark::Bench& bench, size_t buffersize, b
3131
uint32_t len = 0;
3232
bench.batch(buffersize).unit("byte").run([&] {
3333
// encrypt or decrypt the buffer with a static key
34-
assert(aead.Crypt(seqnr_payload, seqnr_aad, aad_pos, out.data(), out.size(), in.data(), buffersize, true));
34+
const bool crypt_ok_1 = aead.Crypt(seqnr_payload, seqnr_aad, aad_pos, out.data(), out.size(), in.data(), buffersize, true);
35+
assert(crypt_ok_1);
3536

3637
if (include_decryption) {
3738
// if we decrypt, include the GetLength
38-
assert(aead.GetLength(&len, seqnr_aad, aad_pos, in.data()));
39-
assert(aead.Crypt(seqnr_payload, seqnr_aad, aad_pos, out.data(), out.size(), in.data(), buffersize, true));
39+
const bool get_length_ok = aead.GetLength(&len, seqnr_aad, aad_pos, in.data());
40+
assert(get_length_ok);
41+
const bool crypt_ok_2 = aead.Crypt(seqnr_payload, seqnr_aad, aad_pos, out.data(), out.size(), in.data(), buffersize, true);
42+
assert(crypt_ok_2);
4043
}
4144

4245
// increase main sequence number

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ class CChainState
562562

563563
//! @returns whether or not the CoinsViews object has been fully initialized and we can
564564
//! safely flush this object to disk.
565-
bool CanFlushToDisk() EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
565+
bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
566566
return m_coins_views && m_coins_views->m_cacheview;
567567
}
568568

src/wallet/test/coinselector_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ static void add_coin(CWallet& wallet, const CAmount& nValue, int nAge = 6*24, bo
6464
if (spendable) {
6565
CTxDestination dest;
6666
std::string error;
67-
assert(wallet.GetNewDestination(OutputType::BECH32, "", dest, error));
67+
const bool destination_ok = wallet.GetNewDestination(OutputType::BECH32, "", dest, error);
68+
assert(destination_ok);
6869
tx.vout[nInput].scriptPubKey = GetScriptForDestination(dest);
6970
}
7071
if (fIsFromMe) {

0 commit comments

Comments
 (0)