Skip to content

Commit 7d9c572

Browse files
authored
refactor: trivial fixes for dead, useless code and minor fixes for dash specific code (#5793)
## Issue being fixed or feature implemented Dead-code, useless conditions can be potential source of bug. ## What was done? See each particular commit. This particular commit "fix: check ptr in assert before usage" fixes potential UB - `assert` is better than UB. All other commits are not fixing any real issue, just to tidy-up code a bit or to shut a potential warning. ## How Has This Been Tested? Run unit/functional tests. ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
1 parent 74c7f20 commit 7d9c572

File tree

7 files changed

+10
-26
lines changed

7 files changed

+10
-26
lines changed

src/evo/cbtx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CCbTx
4242
int32_t nHeight{0};
4343
uint256 merkleRootMNList;
4444
uint256 merkleRootQuorums;
45-
uint32_t bestCLHeightDiff;
45+
uint32_t bestCLHeightDiff{0};
4646
CBLSSignature bestCLSignature;
4747
CAmount creditPoolBalance{0};
4848

src/evo/mnhftx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,12 @@ std::optional<CMNHFManager::Signals> CMNHFManager::GetFromCache(const CBlockInde
330330

331331
void CMNHFManager::AddToCache(const Signals& signals, const CBlockIndex* const pindex)
332332
{
333+
assert(pindex != nullptr);
333334
const uint256& blockHash = pindex->GetBlockHash();
334335
{
335336
LOCK(cs_cache);
336337
mnhfCache.insert(blockHash, signals);
337338
}
338-
assert(pindex != nullptr);
339339
{
340340
LOCK(cs_cache);
341341
if (ThresholdState::ACTIVE != v20_activation.State(pindex->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) return;

src/governance/governance.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,6 @@ void CGovernanceManager::UpdateCachesAndClean()
367367
while (it != mapObjects.end()) {
368368
CGovernanceObject* pObj = &((*it).second);
369369

370-
if (!pObj) {
371-
++it;
372-
continue;
373-
}
374-
375370
uint256 nHash = it->first;
376371
std::string strHash = nHash.ToString();
377372

src/llmq/signing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ CQuorumCPtr CSigningManager::SelectQuorumForSigning(const Consensus::LLMQParams&
10201020
//Extract last 64 bits of selectionHash
10211021
uint64_t b = selectionHash.GetUint64(3);
10221022
//Take last n bits of b
1023-
uint64_t signer = (((1 << n) - 1) & (b >> (64 - n - 1)));
1023+
uint64_t signer = (((1ull << n) - 1) & (b >> (64 - n - 1)));
10241024

10251025
if (signer > quorums.size()) {
10261026
return nullptr;

src/net.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,8 +3291,7 @@ void CExplicitNetCleanup::callCleanup()
32913291
{
32923292
// Explicit call to destructor of CNetCleanup because it's not implicitly called
32933293
// when the wallet is restarted from within the wallet itself.
3294-
CNetCleanup *tmp = new CNetCleanup();
3295-
delete tmp; // Stroustrup's gonna kill me for that
3294+
CNetCleanup tmp;
32963295
}
32973296

32983297
void CConnman::Interrupt()
@@ -3955,7 +3954,6 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
39553954
statsClient.count("bandwidth.message." + SanitizeString(msg.command.c_str()) + ".bytesSent", nTotalSize, 1.0f);
39563955
statsClient.inc("message.sent." + SanitizeString(msg.command.c_str()), 1.0f);
39573956

3958-
size_t nBytesSent = 0;
39593957
{
39603958
LOCK(pnode->cs_vSend);
39613959
bool hasPendingData = !pnode->vSendMsg.empty();
@@ -3986,8 +3984,6 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
39863984
if (!hasPendingData && wakeupSelectNeeded)
39873985
WakeSelect();
39883986
}
3989-
if (nBytesSent)
3990-
RecordBytesSent(nBytesSent);
39913987
}
39923988

39933989
bool CConnman::ForNode(const CService& addr, std::function<bool(const CNode* pnode)> cond, std::function<bool(CNode* pnode)> func)

src/qt/coincontroldialog.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *
481481
unsigned int nBytesInputs = 0;
482482
unsigned int nQuantity = 0;
483483
bool fUnselectedSpent{false};
484-
bool fUnselectedNonMixed{false};
485484

486485
std::vector<COutPoint> vCoinControl;
487486
m_coin_control.ListSelected(vCoinControl);
@@ -575,7 +574,7 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *
575574

576575
// actually update labels
577576
int nDisplayUnit = BitcoinUnits::DASH;
578-
if (model && model->getOptionsModel())
577+
if (model->getOptionsModel())
579578
nDisplayUnit = model->getOptionsModel()->getDisplayUnit();
580579

581580
QLabel *l1 = dialog->findChild<QLabel *>("labelCoinControlQuantity");
@@ -639,10 +638,6 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *
639638
QMessageBox::warning(dialog, "CoinControl",
640639
tr("Some coins were unselected because they were spent."),
641640
QMessageBox::Ok, QMessageBox::Ok);
642-
} else if (fUnselectedNonMixed) {
643-
QMessageBox::warning(dialog, "CoinControl",
644-
tr("Some coins were unselected because they do not have enough mixing rounds."),
645-
QMessageBox::Ok, QMessageBox::Ok);
646641
}
647642
}
648643

src/qt/overviewpage.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,10 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances)
219219

220220
updateCoinJoinProgress();
221221

222-
if (walletModel) {
223-
int numISLocks = walletModel->getNumISLocks();
224-
if(cachedNumISLocks != numISLocks) {
225-
cachedNumISLocks = numISLocks;
226-
ui->listTransactions->update();
227-
}
222+
int numISLocks = walletModel->getNumISLocks();
223+
if(cachedNumISLocks != numISLocks) {
224+
cachedNumISLocks = numISLocks;
225+
ui->listTransactions->update();
228226
}
229227
}
230228

@@ -638,7 +636,7 @@ void OverviewPage::toggleCoinJoin(){
638636
}
639637

640638
// if wallet is locked, ask for a passphrase
641-
if (walletModel && walletModel->getEncryptionStatus() == WalletModel::Locked)
639+
if (walletModel->getEncryptionStatus() == WalletModel::Locked)
642640
{
643641
WalletModel::UnlockContext ctx(walletModel->requestUnlock(true));
644642
if(!ctx.isValid())

0 commit comments

Comments
 (0)