Skip to content

Commit 13a5f69

Browse files
laanwjPastaPastaPasta
authored andcommittedJan 12, 2020
Merge bitcoin#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
1 parent b81ddd2 commit 13a5f69

File tree

5 files changed

+9
-16
lines changed

5 files changed

+9
-16
lines changed
 

‎src/dash-tx.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -660,18 +660,18 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command,
660660
else if (command == "outaddr")
661661
MutateTxAddOutAddr(tx, commandVal);
662662
else if (command == "outpubkey") {
663-
if (!ecc) { ecc.reset(new Secp256k1Init()); }
663+
ecc.reset(new Secp256k1Init());
664664
MutateTxAddOutPubKey(tx, commandVal);
665665
} else if (command == "outmultisig") {
666-
if (!ecc) { ecc.reset(new Secp256k1Init()); }
666+
ecc.reset(new Secp256k1Init());
667667
MutateTxAddOutMultiSig(tx, commandVal);
668668
} else if (command == "outscript")
669669
MutateTxAddOutScript(tx, commandVal);
670670
else if (command == "outdata")
671671
MutateTxAddOutData(tx, commandVal);
672672

673673
else if (command == "sign") {
674-
if (!ecc) { ecc.reset(new Secp256k1Init()); }
674+
ecc.reset(new Secp256k1Init());
675675
MutateTxSign(tx, commandVal);
676676
}
677677

‎src/net_processing.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -441,19 +441,17 @@ void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman* connman) {
441441
}
442442
}
443443
connman->ForNode(nodeid, [connman](CNode* pfrom){
444-
bool fAnnounceUsingCMPCTBLOCK = false;
445444
uint64_t nCMPCTBLOCKVersion = 1;
446445
if (lNodesAnnouncingHeaderAndIDs.size() >= 3) {
447446
// As per BIP152, we only get 3 of our peers to announce
448447
// blocks using compact encodings.
449-
connman->ForNode(lNodesAnnouncingHeaderAndIDs.front(), [connman, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion](CNode* pnodeStop){
450-
connman->PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetSendVersion()).Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion));
448+
connman->ForNode(lNodesAnnouncingHeaderAndIDs.front(), [connman, nCMPCTBLOCKVersion](CNode* pnodeStop){
449+
connman->PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetSendVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/false, nCMPCTBLOCKVersion));
451450
return true;
452451
});
453452
lNodesAnnouncingHeaderAndIDs.pop_front();
454453
}
455-
fAnnounceUsingCMPCTBLOCK = true;
456-
connman->PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion));
454+
connman->PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/true, nCMPCTBLOCKVersion));
457455
lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId());
458456
return true;
459457
});

‎src/qt/walletview.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ void WalletView::setWalletModel(WalletModel *_walletModel)
156156
}
157157
receiveCoinsPage->setModel(_walletModel);
158158
sendCoinsPage->setModel(_walletModel);
159-
usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel());
160-
usedSendingAddressesPage->setModel(_walletModel->getAddressTableModel());
159+
usedReceivingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
160+
usedSendingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
161161

162162
if (_walletModel)
163163
{

‎src/rest.cpp

+1-3
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

-3
Original file line numberDiff line numberDiff line change
@@ -3041,7 +3041,6 @@ static CBlockIndex* AddToBlockIndex(const CBlockHeader& block, enum BlockStatus
30413041

30423042
// Construct new block index object
30433043
CBlockIndex* pindexNew = new CBlockIndex(block);
3044-
assert(pindexNew);
30453044
// We assign the sequence id to blocks only when the full data is available,
30463045
// to avoid miners withholding blocks but broadcasting headers, to get a
30473046
// competitive advantage.
@@ -3866,8 +3865,6 @@ CBlockIndex * InsertBlockIndex(uint256 hash)
38663865

38673866
// Create new
38683867
CBlockIndex* pindexNew = new CBlockIndex();
3869-
if (!pindexNew)
3870-
throw std::runtime_error(std::string(__func__) + ": new CBlockIndex failed");
38713868
mi = mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first;
38723869
pindexNew->phashBlock = &((*mi).first);
38733870

0 commit comments

Comments
 (0)