Skip to content

Commit 010ec27

Browse files
laanwjgades
authored andcommitted
Merge bitcoin#15109: refactor: Use C++11 default member initializers
fa2510d Use C++11 default member initializers (MarcoFalke) Pull request description: Changes: * Remove unused constructors that leave some members uninitialized * Remove manual initialization in each constructor and prefer C++11 default member initializers This is not a stylistic change, but a change that avoids bugs such as: * fix uninitialized read when stringifying an addrLocal bitcoin#14728 * qt: Initialize members in WalletModel bitcoin#12426 * net: correctly initialize nMinPingUsecTime dashpay#6636 * ... Tree-SHA512: 0f896f3b9fcc464d5fc7525f7c86343ef9ce9fb13425fbc68e9a9728fd8710c2b4e2fd039ee08279ea41ff20fd92b7185cf5cca95a0bcb6a5340a1e6f03cae6b
1 parent 2b5e59f commit 010ec27

15 files changed

+35
-80
lines changed

src/addrman.h

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,31 @@
3030
*/
3131
class CAddrInfo : public CAddress
3232
{
33-
34-
3533
public:
3634
//! last try whatsoever by us (memory only)
37-
int64_t nLastTry;
35+
int64_t nLastTry{0};
3836

3937
//! last counted attempt (memory only)
40-
int64_t nLastCountAttempt;
38+
int64_t nLastCountAttempt{0};
4139

4240
private:
4341
//! where knowledge about this address first came from
4442
CNetAddr source;
4543

4644
//! last successful connection by us
47-
int64_t nLastSuccess;
45+
int64_t nLastSuccess{0};
4846

4947
//! connection attempts since last successful attempt
50-
int nAttempts;
48+
int nAttempts{0};
5149

5250
//! reference count in new sets (memory only)
53-
int nRefCount;
51+
int nRefCount{0};
5452

5553
//! in tried set? (memory only)
56-
bool fInTried;
54+
bool fInTried{false};
5755

5856
//! position in vRandom
59-
int nRandomPos;
57+
int nRandomPos{-1};
6058

6159
friend class CAddrMan;
6260

@@ -68,25 +66,12 @@ class CAddrInfo : public CAddress
6866
READWRITE(obj.source, obj.nLastSuccess, obj.nAttempts);
6967
}
7068

71-
void Init()
72-
{
73-
nLastSuccess = 0;
74-
nLastTry = 0;
75-
nLastCountAttempt = 0;
76-
nAttempts = 0;
77-
nRefCount = 0;
78-
fInTried = false;
79-
nRandomPos = -1;
80-
}
81-
8269
CAddrInfo(const CAddress &addrIn, const CNetAddr &addrSource) : CAddress(addrIn), source(addrSource)
8370
{
84-
Init();
8571
}
8672

8773
CAddrInfo() : CAddress(), source()
8874
{
89-
Init();
9075
}
9176

9277
//! Calculate in which "tried" bucket this entry belongs
@@ -109,7 +94,6 @@ class CAddrInfo : public CAddress
10994

11095
//! Calculate the relative chance this entry should be given when selecting nodes to connect to
11196
double GetChance(int64_t nNow = GetAdjustedTime()) const;
112-
11397
};
11498

11599
/** Stochastic address manager

src/httpserver.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ class WorkQueue
131131

132132
struct HTTPPathHandler
133133
{
134-
HTTPPathHandler() {}
135134
HTTPPathHandler(std::string _prefix, bool _exactMatch, HTTPRequestHandler _handler):
136135
prefix(_prefix), exactMatch(_exactMatch), handler(_handler)
137136
{

src/net.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,13 +2905,6 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) :
29052905
addrman(Params().AllowMultiplePorts()),
29062906
nSeed0(nSeed0In), nSeed1(nSeed1In)
29072907
{
2908-
fNetworkActive = true;
2909-
fAddressesInitialized = false;
2910-
nLastNodeId = 0;
2911-
nPrevNodeCount = 0;
2912-
nSendBufferMaxSize = 0;
2913-
nReceiveFloodSize = 0;
2914-
flagInterruptMsgProc = false;
29152908
SetTryNewOutboundPeer(false);
29162909

29172910
Options connOptions;

src/net.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,12 @@ friend class CNode;
556556
// whitelisted (as well as those connecting to whitelisted binds).
557557
std::vector<NetWhitelistPermissions> vWhitelistedRange;
558558

559-
unsigned int nSendBufferMaxSize;
560-
unsigned int nReceiveFloodSize;
559+
unsigned int nSendBufferMaxSize{0};
560+
unsigned int nReceiveFloodSize{0};
561561

562562
std::vector<ListenSocket> vhListenSocket;
563-
std::atomic<bool> fNetworkActive;
564-
bool fAddressesInitialized;
563+
std::atomic<bool> fNetworkActive{true};
564+
bool fAddressesInitialized{false};
565565
CAddrMan addrman;
566566
std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
567567
CCriticalSection cs_vOneShots;
@@ -576,8 +576,8 @@ friend class CNode;
576576
std::list<CNode*> vNodesDisconnected;
577577
std::unordered_map<SOCKET, CNode*> mapSocketToNode;
578578
mutable CCriticalSection cs_vNodes;
579-
std::atomic<NodeId> nLastNodeId;
580-
unsigned int nPrevNodeCount;
579+
std::atomic<NodeId> nLastNodeId{0};
580+
unsigned int nPrevNodeCount{0};
581581

582582
/** Services this instance offers */
583583
ServiceFlags nLocalServices;
@@ -602,7 +602,7 @@ friend class CNode;
602602

603603
std::condition_variable condMsgProc;
604604
Mutex mutexMsgProc;
605-
std::atomic<bool> flagInterruptMsgProc;
605+
std::atomic<bool> flagInterruptMsgProc{false};
606606

607607
CThreadInterrupt interruptNet;
608608

src/protocol.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ class CInv
453453
private:
454454
const char* GetCommandInternal() const;
455455

456-
// TODO: make private (improves encapsulation)
457456
public:
458457
int type;
459458
uint256 hash;

src/qt/bantablemodel.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class BanTablePriv
4141
public:
4242
/** Local cache of peer information */
4343
QList<CCombinedBan> cachedBanlist;
44-
/** Column to sort nodes by */
45-
int sortColumn;
44+
/** Column to sort nodes by (default to unsorted) */
45+
int sortColumn{-1};
4646
/** Order (ascending or descending) to sort nodes by */
4747
Qt::SortOrder sortOrder;
4848

@@ -88,8 +88,6 @@ BanTableModel::BanTableModel(interfaces::Node& node, ClientModel *parent) :
8888
{
8989
columns << tr("IP/Netmask") << tr("Banned Until");
9090
priv.reset(new BanTablePriv());
91-
// default to unsorted
92-
priv->sortColumn = -1;
9391

9492
// load initial data
9593
refresh();

src/qt/peertablemodel.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class PeerTablePriv
5050
public:
5151
/** Local cache of peer information */
5252
QList<CNodeCombinedStats> cachedNodeStats;
53-
/** Column to sort nodes by */
54-
int sortColumn;
53+
/** Column to sort nodes by (default to unsorted) */
54+
int sortColumn{-1};
5555
/** Order (ascending or descending) to sort nodes by */
5656
Qt::SortOrder sortOrder;
5757
/** Index of rows by node ID */
@@ -110,8 +110,6 @@ PeerTableModel::PeerTableModel(interfaces::Node& node, ClientModel *parent) :
110110
{
111111
columns << tr("NodeId") << tr("Node/Service") << tr("Ping") << tr("Sent") << tr("Received") << tr("User Agent");
112112
priv.reset(new PeerTablePriv());
113-
// default to unsorted
114-
priv->sortColumn = -1;
115113

116114
// set up timer for auto refresh
117115
timer = new QTimer(this);

src/qt/recentrequeststablemodel.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
1717
QAbstractTableModel(parent), walletModel(parent)
1818
{
19-
nReceiveRequestsMaxId = 0;
20-
2119
// Load entries from wallet
2220
std::vector<std::string> vReceiveRequests;
2321
parent->loadReceiveRequests(vReceiveRequests);

src/qt/recentrequeststablemodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public Q_SLOTS:
8787
WalletModel *walletModel;
8888
QStringList columns;
8989
QList<RecentRequestEntry> list;
90-
int64_t nReceiveRequestsMaxId;
90+
int64_t nReceiveRequestsMaxId{0};
9191

9292
/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
9393
void updateAmountColumnTitle();

src/qt/walletmodel.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, interfaces:
4040
cachedCoinJoinRounds(0)
4141
{
4242
fHaveWatchOnly = m_wallet->haveWatchOnly();
43-
fForceCheckBalanceChanged = false;
44-
4543
addressTableModel = new AddressTableModel(this);
4644
transactionTableModel = new TransactionTableModel(this);
4745
recentRequestsTableModel = new RecentRequestsTableModel(this);

0 commit comments

Comments
 (0)