Contains:
- Remove redundant
NULLchecks after throwingnew - Remove redundant check (
!eccis always true) - Remove duplicate
uriParts.size() > 0check - Use two boolean literals instead of re-using variable
Contains:
NULL checks after throwing new!ecc is always true)uriParts.size() > 0 check426 | @@ -427,9 +427,8 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) 427 | 428 | if (uriParts.size() > 0) 429 | { 430 | - 431 | //inputs is sent over URI scheme (/rest/getutxos/checkmempool/txid1-n/txid2-n/...) 432 | - if (uriParts.size() > 0 && uriParts[0] == "checkmempool") 433 | + if (uriParts[0] == "checkmempool") 434 | fCheckMemPool = true;
add braces or put on same line according do the dev notes.
424 | // As per BIP152, we only get 3 of our peers to announce 425 | // blocks using compact encodings. 426 | - connman.ForNode(lNodesAnnouncingHeaderAndIDs.front(), [&connman, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion](CNode* pnodeStop){ 427 | - connman.PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetSendVersion()).Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion)); 428 | + connman.ForNode(lNodesAnnouncingHeaderAndIDs.front(), [&connman, nCMPCTBLOCKVersion](CNode* pnodeStop) { 429 | + connman.PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetSendVersion()).Make(NetMsgType::SENDCMPCT, false, nCMPCTBLOCKVersion));
Now the code is less readable, as I have to guess or look up what false means here. I'd restore the var in this case (same issue below).
Fixed by adding two comments :-)
686 | @@ -687,18 +687,18 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command, 687 | else if (command == "outaddr") 688 | MutateTxAddOutAddr(tx, commandVal); 689 | else if (command == "outpubkey") { 690 | - if (!ecc) { ecc.reset(new Secp256k1Init()); } 691 | + ecc.reset(new Secp256k1Init());
A bit off-topic (removing the !ecc check looks good):
Secp256k1Init is pretty obscure here. Why is it needed for those few commands but not others?Pinging @sipa, the author of this.
Some libsecp256k1 calls require a context, and some don't. The secp256k1.h header explains which ones, but perhaps that information should be duplicated into at least the pubkey.h/key.h interfaces?
121 | @@ -122,11 +122,12 @@ void WalletView::setWalletModel(WalletModel *_walletModel) 122 | overviewPage->setWalletModel(_walletModel); 123 | receiveCoinsPage->setModel(_walletModel); 124 | sendCoinsPage->setModel(_walletModel); 125 | - usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); 126 | - usedSendingAddressesPage->setModel(_walletModel->getAddressTableModel()); 127 | 128 | if (_walletModel)
After a quick research it looks like _walletModel is never passed as NULL. So it would be good to change the argument from a pointer to a reference and remove this check.
@benma Thanks for reviewing! Good feedback. All items addressed. Looks good? :-)
424 | // As per BIP152, we only get 3 of our peers to announce 425 | // blocks using compact encodings. 426 | - connman.ForNode(lNodesAnnouncingHeaderAndIDs.front(), [&connman, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion](CNode* pnodeStop){ 427 | - connman.PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetSendVersion()).Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion)); 428 | + connman.ForNode(lNodesAnnouncingHeaderAndIDs.front(), [&connman, nCMPCTBLOCKVersion](CNode* pnodeStop){ 429 | + connman.PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetSendVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/false, nCMPCTBLOCKVersion));
I am not sure whether I like this 😆
Maybe nicer to define two constants for true/false, or an enum?
I commend the effort to reduce the number of lines, but in some cases, being descriptive is worth it.
utACK anyway, I'll leave the decision to you.
utACK da5f591c03e04cfc159aa9d8ed1036576f51aa25
Rebased!
Rebased! :-)
47 | @@ -48,7 +48,7 @@ class WalletView : public QStackedWidget 48 | The wallet model represents a bitcoin wallet, and offers access to the list of transactions, address book and sending 49 | functionality. 50 | */ 51 | - void setWalletModel(WalletModel *walletModel); 52 | + void setWalletModel(WalletModel& walletModel);
Please don't change the setWalletModel() interface. It is supposed to be consistent over all objects, and setting a NULL model is meaningful: it should be possible to use the view classes without a model for simple testing.
@laanwj I've now removed the Move NULL check prior to dereference commit.
Please note that setting a NULL model will result in a null pointer dereference in current master. Should I fix that?
What about:
diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp
index 971f5e0..a56a400 100644
--- a/src/qt/walletview.cpp
+++ b/src/qt/walletview.cpp
@@ -122,8 +122,8 @@ void WalletView::setWalletModel(WalletModel *_walletModel)
overviewPage->setWalletModel(_walletModel);
receiveCoinsPage->setModel(_walletModel);
sendCoinsPage->setModel(_walletModel);
- usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel());
- usedSendingAddressesPage->setModel(_walletModel->getAddressTableModel());
+ usedReceivingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
+ usedSendingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
@practicalshift Yes that should be fixed, looks good to me!
@laanwj I've now added a NULL check for _walletModel. Looks good now? :-)
utACK 76fed838f381a6efba175f3650ec7e9dc73016d3 @practicalswift, how are you finding these changes? Are you using a linter tool? Or methodically going through the source code in some way and reviewing it?
@ryanofsky I use a combination of manual code review, static analysis and fuzzing to find potential issues. In the Apple Swift project most of my results have been from fuzzing (using my own compiler fuzzer): see my apple/swift contributions here.
Thanks. It could be educational (and also nice to give credit) if you mentioned the specific static analysis & fuzzing tools were that used in your commit messages and PR descriptions.
Agree with @ryanofsky, also for useful when reviewing!
Echoing @ryanofsky, would even be useful to fill this info in on already merged PRs (people often refer to them long after the fact).
@ryanofsky @promag @JeremyRubin Sure! Thanks for showing interest! That is appreciated.
Here are pointers to some of the open source tools that I use regularly:
libFuzzer - see PR #10440 (please review!)afl-fuzz - see PR #10415 and #10409valgrind - see PR #11035 (please review!)clang-tidy - see PR #10735clang-format - see PR #10602pycodestyle - see PR #9508AddressSanitizer (ASan: -fsanitize=address)LeakSanitizer (LSan: -fsanitize=leak)MemorySanitizer (MSan: -fsanitize=memory)ThreadSanitizer (TSan: -fsanitize=thread)UndefinedBehaviorSanitizer (UBSan: -fsanitize=undefined)flintppoclintcppcheckThe list is not at all exhaustive - I try to use as many tools as possible to increase diversity in the classes of issues covered. In addition to the above I use some custom/proprietary analysis tools/scripts, but they are not that interesting or general.
If you want to help, please review the open PR:s mentioned above to increase the chance of them getting merged :-)
Can this be merged? Has two utACKs and is a small, minor change.
Looks good to me, utACK 76fed83