Protect from null ptr on chain tip

This commit is contained in:
Michael Toutonghi
2018-07-14 21:45:38 -07:00
parent 7756dac0c7
commit 37ad688668
4 changed files with 43 additions and 26 deletions

View File

@@ -424,6 +424,7 @@ public:
class CChain {
private:
std::vector<CBlockIndex*> vChain;
CBlockIndex *lastTip;
public:
/** Returns the index entry for the genesis block of this chain, or NULL if none. */
@@ -436,6 +437,11 @@ public:
return vChain.size() > 0 ? vChain[vChain.size() - 1] : NULL;
}
/** Returns the last tip of the chain, or NULL if none. */
CBlockIndex *LastTip() const {
return vChain.size() > 0 ? lastTip : NULL;
}
/** Returns the index entry at a particular height in this chain, or NULL if no such height exists. */
CBlockIndex *operator[](int nHeight) const {
if (nHeight < 0 || nHeight >= (int)vChain.size())