Skip to content

Commit 551d7bf

Browse files
committed
Merge #11132: Document assumptions that are being made to avoid NULL pointer dereferences
fdc3293 Document assumptions that are being made to avoid NULL pointer dereferences (practicalswift) Pull request description: Document assumptions (via `assert(…)`:s) that are being made avoid `NULL` pointer dereferences. Rationale: * Make it clear to human reviewers and non-human static analyzers that what might look like potential `NULL` pointer dereferences are written the way they are intentionally (these cases are currently flagged by various static analyzers). Tree-SHA512: b424328195e2680e1e4ec546298f718c49e5ad182147dc004de580693db1b50eec4065e1c4f232bdb302baa12954265a50ba21cb5ba4ff30248535b2de778672
2 parents 2847480 + fdc3293 commit 551d7bf

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

src/qt/walletframe.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "bitcoingui.h"
88
#include "walletview.h"
99

10+
#include <cassert>
1011
#include <cstdio>
1112

1213
#include <QHBoxLayout>
@@ -69,6 +70,7 @@ bool WalletFrame::setCurrentWallet(const QString& name)
6970

7071
WalletView *walletView = mapWalletViews.value(name);
7172
walletStack->setCurrentWidget(walletView);
73+
assert(walletView);
7274
walletView->updateEncryptionStatus();
7375
return true;
7476
}

src/validation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
17111711
// before the first had been spent. Since those coinbases are sufficiently buried its no longer possible to create further
17121712
// duplicate transactions descending from the known pairs either.
17131713
// If we're on the known chain at height greater than where BIP34 activated, we can save the db accesses needed for the BIP30 check.
1714+
assert(pindex->pprev);
17141715
CBlockIndex *pindexBIP34height = pindex->pprev->GetAncestor(chainparams.GetConsensus().BIP34Height);
17151716
//Only continue to enforce if we're below BIP34 activation height or the block hash at that height doesn't correspond.
17161717
fEnforceBIP30 = fEnforceBIP30 && (!pindexBIP34height || !(pindexBIP34height->GetBlockHash() == chainparams.GetConsensus().BIP34Hash));
@@ -1850,6 +1851,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
18501851
if (!pblocktree->WriteTxIndex(vPos))
18511852
return AbortNode(state, "Failed to write transaction index");
18521853

1854+
assert(pindex->phashBlock);
18531855
// add this block to the view's block chain
18541856
view.SetBestBlock(pindex->GetBlockHash());
18551857

src/wallet/wallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ void CWallet::SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator> ran
519519
const uint256& hash = it->second;
520520
CWalletTx* copyTo = &mapWallet[hash];
521521
if (copyFrom == copyTo) continue;
522+
assert(copyFrom && "Oldest wallet transaction in range assumed to have been found.");
522523
if (!copyFrom->IsEquivalentTo(*copyTo)) continue;
523524
copyTo->mapValue = copyFrom->mapValue;
524525
copyTo->vOrderForm = copyFrom->vOrderForm;

0 commit comments

Comments
 (0)