Skip to content

Commit c433828

Browse files
author
Ross Nicoll
committed
Handle no chain tip available in InvalidChainFound()
Handle the case where no chain tip is available, in InvalidChainFound(). This fixes a null pointer deference when running unit tests, if the genesis block or block validation code is broken.
1 parent 633fe10 commit c433828

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,9 +1196,11 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
11961196
pindexNew->GetBlockHash().ToString(), pindexNew->nHeight,
11971197
log(pindexNew->nChainWork.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S",
11981198
pindexNew->GetBlockTime()));
1199+
CBlockIndex *tip = chainActive.Tip();
1200+
assert (tip);
11991201
LogPrintf("%s: current best=%s height=%d log2_work=%.8g date=%s\n", __func__,
1200-
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->nChainWork.getdouble())/log(2.0),
1201-
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()));
1202+
tip->GetBlockHash().ToString(), chainActive.Height(), log(tip->nChainWork.getdouble())/log(2.0),
1203+
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", tip->GetBlockTime()));
12021204
CheckForkWarningConditions();
12031205
}
12041206

0 commit comments

Comments
 (0)