Skip to content

Commit 470c730

Browse files
committed
Merge #10898: Fix invalid checks (NULL checks after dereference, redundant checks, etc.)
76fed83 Avoid NULL pointer dereference when _walletModel is NULL (which is valid) (practicalswift) 4971a9a Use two boolean literals instead of re-using variable (practicalswift) b5fb339 Remove duplicate uriParts.size() > 0 check (practicalswift) 7466991 Remove redundant check (!ecc is always true) (practicalswift) 55224af Remove redundant NULL checks after new (practicalswift) Pull request description: Contains: * Remove redundant `NULL` checks after throwing `new` * Remove redundant check (`!ecc` is always true) * Remove duplicate `uriParts.size() > 0` check * Use two boolean literals instead of re-using variable Tree-SHA512: 30e9af8a9d5c8184836f8267b492aeb4e26eca171a3be08f634b3f39b3055b9fa9f06623f6c69b294ca13bf99743f7645cfac2b25e014ff74687bd085a997895
2 parents f74459d + 76fed83 commit 470c730

File tree

5 files changed

+9
-16
lines changed

5 files changed

+9
-16
lines changed

src/bitcoin-tx.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,18 +690,18 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command,
690690
else if (command == "outaddr")
691691
MutateTxAddOutAddr(tx, commandVal);
692692
else if (command == "outpubkey") {
693-
if (!ecc) { ecc.reset(new Secp256k1Init()); }
693+
ecc.reset(new Secp256k1Init());
694694
MutateTxAddOutPubKey(tx, commandVal);
695695
} else if (command == "outmultisig") {
696-
if (!ecc) { ecc.reset(new Secp256k1Init()); }
696+
ecc.reset(new Secp256k1Init());
697697
MutateTxAddOutMultiSig(tx, commandVal);
698698
} else if (command == "outscript")
699699
MutateTxAddOutScript(tx, commandVal);
700700
else if (command == "outdata")
701701
MutateTxAddOutData(tx, commandVal);
702702

703703
else if (command == "sign") {
704-
if (!ecc) { ecc.reset(new Secp256k1Init()); }
704+
ecc.reset(new Secp256k1Init());
705705
MutateTxSign(tx, commandVal);
706706
}
707707

src/net_processing.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,19 +379,17 @@ void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman* connman) {
379379
}
380380
}
381381
connman->ForNode(nodeid, [connman](CNode* pfrom){
382-
bool fAnnounceUsingCMPCTBLOCK = false;
383382
uint64_t nCMPCTBLOCKVersion = (pfrom->GetLocalServices() & NODE_WITNESS) ? 2 : 1;
384383
if (lNodesAnnouncingHeaderAndIDs.size() >= 3) {
385384
// As per BIP152, we only get 3 of our peers to announce
386385
// blocks using compact encodings.
387-
connman->ForNode(lNodesAnnouncingHeaderAndIDs.front(), [connman, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion](CNode* pnodeStop){
388-
connman->PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetSendVersion()).Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion));
386+
connman->ForNode(lNodesAnnouncingHeaderAndIDs.front(), [connman, nCMPCTBLOCKVersion](CNode* pnodeStop){
387+
connman->PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetSendVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/false, nCMPCTBLOCKVersion));
389388
return true;
390389
});
391390
lNodesAnnouncingHeaderAndIDs.pop_front();
392391
}
393-
fAnnounceUsingCMPCTBLOCK = true;
394-
connman->PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion));
392+
connman->PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/true, nCMPCTBLOCKVersion));
395393
lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId());
396394
return true;
397395
});

src/qt/walletview.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ void WalletView::setWalletModel(WalletModel *_walletModel)
122122
overviewPage->setWalletModel(_walletModel);
123123
receiveCoinsPage->setModel(_walletModel);
124124
sendCoinsPage->setModel(_walletModel);
125-
usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel());
126-
usedSendingAddressesPage->setModel(_walletModel->getAddressTableModel());
125+
usedReceivingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
126+
usedSendingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
127127

128128
if (_walletModel)
129129
{

src/rest.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,8 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
409409

410410
if (uriParts.size() > 0)
411411
{
412-
413412
//inputs is sent over URI scheme (/rest/getutxos/checkmempool/txid1-n/txid2-n/...)
414-
if (uriParts.size() > 0 && uriParts[0] == "checkmempool")
415-
fCheckMemPool = true;
413+
if (uriParts[0] == "checkmempool") fCheckMemPool = true;
416414

417415
for (size_t i = (fCheckMemPool) ? 1 : 0; i < uriParts.size(); i++)
418416
{

src/validation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,7 +2613,6 @@ static CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
26132613

26142614
// Construct new block index object
26152615
CBlockIndex* pindexNew = new CBlockIndex(block);
2616-
assert(pindexNew);
26172616
// We assign the sequence id to blocks only when the full data is available,
26182617
// to avoid miners withholding blocks but broadcasting headers, to get a
26192618
// competitive advantage.
@@ -3443,8 +3442,6 @@ CBlockIndex * InsertBlockIndex(uint256 hash)
34433442

34443443
// Create new
34453444
CBlockIndex* pindexNew = new CBlockIndex();
3446-
if (!pindexNew)
3447-
throw std::runtime_error(std::string(__func__) + ": new CBlockIndex failed");
34483445
mi = mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first;
34493446
pindexNew->phashBlock = &((*mi).first);
34503447

0 commit comments

Comments
 (0)