Skip to content

Commit 281cf99

Browse files
Do not run functions with necessary side-effects in assert()
1 parent f35e4d9 commit 281cf99

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
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/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)