Skip to content

Commit 3f12515

Browse files
committed
Merge #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 #14728 * qt: Initialize members in WalletModel #12426 * net: correctly initialize nMinPingUsecTime #6636 * ... Tree-SHA512: 0f896f3b9fcc464d5fc7525f7c86343ef9ce9fb13425fbc68e9a9728fd8710c2b4e2fd039ee08279ea41ff20fd92b7185cf5cca95a0bcb6a5340a1e6f03cae6b
2 parents e12a480 + fa2510d commit 3f12515

15 files changed

+35
-82
lines changed

src/addrman.h

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,31 @@
2323
*/
2424
class CAddrInfo : public CAddress
2525
{
26-
27-
2826
public:
2927
//! last try whatsoever by us (memory only)
30-
int64_t nLastTry;
28+
int64_t nLastTry{0};
3129

3230
//! last counted attempt (memory only)
33-
int64_t nLastCountAttempt;
31+
int64_t nLastCountAttempt{0};
3432

3533
private:
3634
//! where knowledge about this address first came from
3735
CNetAddr source;
3836

3937
//! last successful connection by us
40-
int64_t nLastSuccess;
38+
int64_t nLastSuccess{0};
4139

4240
//! connection attempts since last successful attempt
43-
int nAttempts;
41+
int nAttempts{0};
4442

4543
//! reference count in new sets (memory only)
46-
int nRefCount;
44+
int nRefCount{0};
4745

4846
//! in tried set? (memory only)
49-
bool fInTried;
47+
bool fInTried{false};
5048

5149
//! position in vRandom
52-
int nRandomPos;
50+
int nRandomPos{-1};
5351

5452
friend class CAddrMan;
5553

@@ -65,25 +63,12 @@ class CAddrInfo : public CAddress
6563
READWRITE(nAttempts);
6664
}
6765

68-
void Init()
69-
{
70-
nLastSuccess = 0;
71-
nLastTry = 0;
72-
nLastCountAttempt = 0;
73-
nAttempts = 0;
74-
nRefCount = 0;
75-
fInTried = false;
76-
nRandomPos = -1;
77-
}
78-
7966
CAddrInfo(const CAddress &addrIn, const CNetAddr &addrSource) : CAddress(addrIn), source(addrSource)
8067
{
81-
Init();
8268
}
8369

8470
CAddrInfo() : CAddress(), source()
8571
{
86-
Init();
8772
}
8873

8974
//! Calculate in which "tried" bucket this entry belongs
@@ -106,7 +91,6 @@ class CAddrInfo : public CAddress
10691

10792
//! Calculate the relative chance this entry should be given when selecting nodes to connect to
10893
double GetChance(int64_t nNow = GetAdjustedTime()) const;
109-
11094
};
11195

11296
/** Stochastic address manager

src/httpserver.cpp

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

125125
struct HTTPPathHandler
126126
{
127-
HTTPPathHandler() {}
128127
HTTPPathHandler(std::string _prefix, bool _exactMatch, HTTPRequestHandler _handler):
129128
prefix(_prefix), exactMatch(_exactMatch), handler(_handler)
130129
{

src/net.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,14 +2316,6 @@ void CConnman::SetNetworkActive(bool active)
23162316

23172317
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSeed1(nSeed1In)
23182318
{
2319-
fNetworkActive = true;
2320-
setBannedIsDirty = false;
2321-
fAddressesInitialized = false;
2322-
nLastNodeId = 0;
2323-
nPrevNodeCount = 0;
2324-
nSendBufferMaxSize = 0;
2325-
nReceiveFloodSize = 0;
2326-
flagInterruptMsgProc = false;
23272319
SetTryNewOutboundPeer(false);
23282320

23292321
Options connOptions;

src/net.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,15 @@ class CConnman
404404
// whitelisted (as well as those connecting to whitelisted binds).
405405
std::vector<CSubNet> vWhitelistedRange;
406406

407-
unsigned int nSendBufferMaxSize;
408-
unsigned int nReceiveFloodSize;
407+
unsigned int nSendBufferMaxSize{0};
408+
unsigned int nReceiveFloodSize{0};
409409

410410
std::vector<ListenSocket> vhListenSocket;
411-
std::atomic<bool> fNetworkActive;
411+
std::atomic<bool> fNetworkActive{true};
412412
banmap_t setBanned GUARDED_BY(cs_setBanned);
413413
CCriticalSection cs_setBanned;
414-
bool setBannedIsDirty GUARDED_BY(cs_setBanned);
415-
bool fAddressesInitialized;
414+
bool setBannedIsDirty GUARDED_BY(cs_setBanned){false};
415+
bool fAddressesInitialized{false};
416416
CAddrMan addrman;
417417
std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
418418
CCriticalSection cs_vOneShots;
@@ -421,8 +421,8 @@ class CConnman
421421
std::vector<CNode*> vNodes;
422422
std::list<CNode*> vNodesDisconnected;
423423
mutable CCriticalSection cs_vNodes;
424-
std::atomic<NodeId> nLastNodeId;
425-
unsigned int nPrevNodeCount;
424+
std::atomic<NodeId> nLastNodeId{0};
425+
unsigned int nPrevNodeCount{0};
426426

427427
/** Services this instance offers */
428428
ServiceFlags nLocalServices;
@@ -446,7 +446,7 @@ class CConnman
446446

447447
std::condition_variable condMsgProc;
448448
Mutex mutexMsgProc;
449-
std::atomic<bool> flagInterruptMsgProc;
449+
std::atomic<bool> flagInterruptMsgProc{false};
450450

451451
CThreadInterrupt interruptNet;
452452

src/protocol.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ class CInv
402402
std::string GetCommand() const;
403403
std::string ToString() const;
404404

405-
// TODO: make private (improves encapsulation)
406405
public:
407406
int type;
408407
uint256 hash;

src/qt/bantablemodel.cpp

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

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

9391
// load initial data
9492
refresh();

src/qt/peertablemodel.cpp

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

114112
// set up timer for auto refresh
115113
timer = new QTimer(this);

src/qt/recentrequeststablemodel.cpp

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

src/qt/recentrequeststablemodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public Q_SLOTS:
9494
WalletModel *walletModel;
9595
QStringList columns;
9696
QList<RecentRequestEntry> list;
97-
int64_t nReceiveRequestsMaxId;
97+
int64_t nReceiveRequestsMaxId{0};
9898

9999
/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
100100
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
cachedNumBlocks(0)
4141
{
4242
fHaveWatchOnly = m_wallet->haveWatchOnly();
43-
fForceCheckBalanceChanged = false;
44-
4543
addressTableModel = new AddressTableModel(this);
4644
transactionTableModel = new TransactionTableModel(platformStyle, this);
4745
recentRequestsTableModel = new RecentRequestsTableModel(this);

0 commit comments

Comments
 (0)