Skip to content

Commit

Permalink
[Trivial] Check for pindex != nullptr during loops
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Oct 27, 2019
1 parent 9ece682 commit dce9b67
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ bool AppInit2()
if (GetBoolArg("-reindexaccumulators", false)) {
if (chainHeight > Params().Zerocoin_Block_V2_Start()) {
CBlockIndex *pindex = chainActive[Params().Zerocoin_Block_V2_Start()];
while (pindex->nHeight < std::min(chainActive.Height(), Params().Zerocoin_Block_Last_Checkpoint()+1)) {
while (pindex && pindex->nHeight < std::min(chainActive.Height(), Params().Zerocoin_Block_Last_Checkpoint()+1)) {
if (!count(listAccCheckpointsNoDB.begin(), listAccCheckpointsNoDB.end(),
pindex->nAccumulatorCheckpoint))
listAccCheckpointsNoDB.emplace_back(pindex->nAccumulatorCheckpoint);
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3056,7 +3056,7 @@ bool ReindexAccumulators(std::list<uint256>& listMissingCheckpoints, std::string

// find each checkpoint that is missing
CBlockIndex* pindex = chainActive[nZerocoinStart];
while (pindex->nHeight <= Params().Zerocoin_Block_Last_Checkpoint()) {
while (pindex && pindex->nHeight <= Params().Zerocoin_Block_Last_Checkpoint()) {
uiInterface.ShowProgress(_("Calculating missing accumulators..."), std::max(1, std::min(99, (int)((double)(pindex->nHeight - nZerocoinStart) / (double)(chainActive.Height() - nZerocoinStart) * 100))));

if (ShutdownRequested())
Expand Down
4 changes: 2 additions & 2 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,

const int nHeight = pindexPrev->nHeight + 1;

// Make sure to create the correct block version after zerocoin is enabled
if(nHeight >= Params().Block_V7_StartHeight()) {
// Make sure to create the correct block version
if (nHeight >= Params().Block_V7_StartHeight()) {
pblock->nVersion = 7; //!> Removes accumulator checkpoints
} else {
pblock->nVersion = 6; //!> Supports V2 Stake Modifiers.
Expand Down
2 changes: 1 addition & 1 deletion src/stakeinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool CZPivStake::GetModifier(uint64_t& nStakeModifier)
int64_t nTimeBlockFrom = pindex->GetBlockTime();
// zPIV staking is disabled long before block v7 (and checkpoint is not included in blocks since v7)
// just return false for now. !TODO: refactor/remove this method
while (pindex->nHeight + 1 <= std::min(chainActive.Height(), Params().Zerocoin_Block_Last_Checkpoint()-1)) {
while (pindex && pindex->nHeight + 1 <= std::min(chainActive.Height(), Params().Zerocoin_Block_Last_Checkpoint()-1)) {
if (pindex->GetBlockTime() - nTimeBlockFrom > 60 * 60) {
nStakeModifier = pindex->nAccumulatorCheckpoint.Get64();
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/zpiv/accumulators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int GetChecksumHeight(uint32_t nChecksum, libzerocoin::CoinDenomination denomina
return 0;

//Search through blocks to find the checksum
while (pindex->nHeight <= Params().Zerocoin_Block_Last_Checkpoint()) {
while (pindex && pindex->nHeight <= Params().Zerocoin_Block_Last_Checkpoint()) {
if (ParseChecksum(pindex->nAccumulatorCheckpoint, denomination) == nChecksum)
return pindex->nHeight;

Expand Down Expand Up @@ -276,7 +276,7 @@ bool CalculateAccumulatorCheckpoint(int nHeight, uint256& nCheckpoint, Accumulat
int nTotalMintsFound = 0;
CBlockIndex *pindex = chainActive[nHeightCheckpoint - 20];

while (pindex->nHeight < nHeight - 10) {
while (pindex && pindex->nHeight < nHeight - 10) {
// checking whether we should stop this process due to a shutdown request
if (ShutdownRequested())
return false;
Expand Down Expand Up @@ -362,7 +362,7 @@ int ComputeAccumulatedCoins(int nHeightEnd, libzerocoin::CoinDenomination denom)
{
CBlockIndex* pindex = chainActive[GetZerocoinStartHeight()];
int n = 0;
while (pindex->nHeight < nHeightEnd) {
while (pindex && pindex->nHeight < nHeightEnd) {
n += count(pindex->vMintDenominationsInBlock.begin(), pindex->vMintDenominationsInBlock.end(), denom);
pindex = chainActive.Next(pindex);
}
Expand Down

0 comments on commit dce9b67

Please sign in to comment.