Merge #15109: refactor: Use C++11 default member initializers
fa2510d5c1
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
This commit is contained in:
commit
3f12515199
15 changed files with 35 additions and 82 deletions
|
@ -23,33 +23,31 @@
|
|||
*/
|
||||
class CAddrInfo : public CAddress
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
//! last try whatsoever by us (memory only)
|
||||
int64_t nLastTry;
|
||||
int64_t nLastTry{0};
|
||||
|
||||
//! last counted attempt (memory only)
|
||||
int64_t nLastCountAttempt;
|
||||
int64_t nLastCountAttempt{0};
|
||||
|
||||
private:
|
||||
//! where knowledge about this address first came from
|
||||
CNetAddr source;
|
||||
|
||||
//! last successful connection by us
|
||||
int64_t nLastSuccess;
|
||||
int64_t nLastSuccess{0};
|
||||
|
||||
//! connection attempts since last successful attempt
|
||||
int nAttempts;
|
||||
int nAttempts{0};
|
||||
|
||||
//! reference count in new sets (memory only)
|
||||
int nRefCount;
|
||||
int nRefCount{0};
|
||||
|
||||
//! in tried set? (memory only)
|
||||
bool fInTried;
|
||||
bool fInTried{false};
|
||||
|
||||
//! position in vRandom
|
||||
int nRandomPos;
|
||||
int nRandomPos{-1};
|
||||
|
||||
friend class CAddrMan;
|
||||
|
||||
|
@ -65,25 +63,12 @@ public:
|
|||
READWRITE(nAttempts);
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
nLastSuccess = 0;
|
||||
nLastTry = 0;
|
||||
nLastCountAttempt = 0;
|
||||
nAttempts = 0;
|
||||
nRefCount = 0;
|
||||
fInTried = false;
|
||||
nRandomPos = -1;
|
||||
}
|
||||
|
||||
CAddrInfo(const CAddress &addrIn, const CNetAddr &addrSource) : CAddress(addrIn), source(addrSource)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
CAddrInfo() : CAddress(), source()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
//! Calculate in which "tried" bucket this entry belongs
|
||||
|
@ -106,7 +91,6 @@ public:
|
|||
|
||||
//! Calculate the relative chance this entry should be given when selecting nodes to connect to
|
||||
double GetChance(int64_t nNow = GetAdjustedTime()) const;
|
||||
|
||||
};
|
||||
|
||||
/** Stochastic address manager
|
||||
|
|
|
@ -124,7 +124,6 @@ public:
|
|||
|
||||
struct HTTPPathHandler
|
||||
{
|
||||
HTTPPathHandler() {}
|
||||
HTTPPathHandler(std::string _prefix, bool _exactMatch, HTTPRequestHandler _handler):
|
||||
prefix(_prefix), exactMatch(_exactMatch), handler(_handler)
|
||||
{
|
||||
|
|
|
@ -2316,14 +2316,6 @@ void CConnman::SetNetworkActive(bool active)
|
|||
|
||||
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSeed1(nSeed1In)
|
||||
{
|
||||
fNetworkActive = true;
|
||||
setBannedIsDirty = false;
|
||||
fAddressesInitialized = false;
|
||||
nLastNodeId = 0;
|
||||
nPrevNodeCount = 0;
|
||||
nSendBufferMaxSize = 0;
|
||||
nReceiveFloodSize = 0;
|
||||
flagInterruptMsgProc = false;
|
||||
SetTryNewOutboundPeer(false);
|
||||
|
||||
Options connOptions;
|
||||
|
|
16
src/net.h
16
src/net.h
|
@ -404,15 +404,15 @@ private:
|
|||
// whitelisted (as well as those connecting to whitelisted binds).
|
||||
std::vector<CSubNet> vWhitelistedRange;
|
||||
|
||||
unsigned int nSendBufferMaxSize;
|
||||
unsigned int nReceiveFloodSize;
|
||||
unsigned int nSendBufferMaxSize{0};
|
||||
unsigned int nReceiveFloodSize{0};
|
||||
|
||||
std::vector<ListenSocket> vhListenSocket;
|
||||
std::atomic<bool> fNetworkActive;
|
||||
std::atomic<bool> fNetworkActive{true};
|
||||
banmap_t setBanned GUARDED_BY(cs_setBanned);
|
||||
CCriticalSection cs_setBanned;
|
||||
bool setBannedIsDirty GUARDED_BY(cs_setBanned);
|
||||
bool fAddressesInitialized;
|
||||
bool setBannedIsDirty GUARDED_BY(cs_setBanned){false};
|
||||
bool fAddressesInitialized{false};
|
||||
CAddrMan addrman;
|
||||
std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
|
||||
CCriticalSection cs_vOneShots;
|
||||
|
@ -421,8 +421,8 @@ private:
|
|||
std::vector<CNode*> vNodes;
|
||||
std::list<CNode*> vNodesDisconnected;
|
||||
mutable CCriticalSection cs_vNodes;
|
||||
std::atomic<NodeId> nLastNodeId;
|
||||
unsigned int nPrevNodeCount;
|
||||
std::atomic<NodeId> nLastNodeId{0};
|
||||
unsigned int nPrevNodeCount{0};
|
||||
|
||||
/** Services this instance offers */
|
||||
ServiceFlags nLocalServices;
|
||||
|
@ -446,7 +446,7 @@ private:
|
|||
|
||||
std::condition_variable condMsgProc;
|
||||
Mutex mutexMsgProc;
|
||||
std::atomic<bool> flagInterruptMsgProc;
|
||||
std::atomic<bool> flagInterruptMsgProc{false};
|
||||
|
||||
CThreadInterrupt interruptNet;
|
||||
|
||||
|
|
|
@ -402,7 +402,6 @@ public:
|
|||
std::string GetCommand() const;
|
||||
std::string ToString() const;
|
||||
|
||||
// TODO: make private (improves encapsulation)
|
||||
public:
|
||||
int type;
|
||||
uint256 hash;
|
||||
|
|
|
@ -40,8 +40,8 @@ class BanTablePriv
|
|||
public:
|
||||
/** Local cache of peer information */
|
||||
QList<CCombinedBan> cachedBanlist;
|
||||
/** Column to sort nodes by */
|
||||
int sortColumn;
|
||||
/** Column to sort nodes by (default to unsorted) */
|
||||
int sortColumn{-1};
|
||||
/** Order (ascending or descending) to sort nodes by */
|
||||
Qt::SortOrder sortOrder;
|
||||
|
||||
|
@ -87,8 +87,6 @@ BanTableModel::BanTableModel(interfaces::Node& node, ClientModel *parent) :
|
|||
{
|
||||
columns << tr("IP/Netmask") << tr("Banned Until");
|
||||
priv.reset(new BanTablePriv());
|
||||
// default to unsorted
|
||||
priv->sortColumn = -1;
|
||||
|
||||
// load initial data
|
||||
refresh();
|
||||
|
|
|
@ -49,8 +49,8 @@ class PeerTablePriv
|
|||
public:
|
||||
/** Local cache of peer information */
|
||||
QList<CNodeCombinedStats> cachedNodeStats;
|
||||
/** Column to sort nodes by */
|
||||
int sortColumn;
|
||||
/** Column to sort nodes by (default to unsorted) */
|
||||
int sortColumn{-1};
|
||||
/** Order (ascending or descending) to sort nodes by */
|
||||
Qt::SortOrder sortOrder;
|
||||
/** Index of rows by node ID */
|
||||
|
@ -108,8 +108,6 @@ PeerTableModel::PeerTableModel(interfaces::Node& node, ClientModel *parent) :
|
|||
{
|
||||
columns << tr("NodeId") << tr("Node/Service") << tr("Ping") << tr("Sent") << tr("Received") << tr("User Agent");
|
||||
priv.reset(new PeerTablePriv());
|
||||
// default to unsorted
|
||||
priv->sortColumn = -1;
|
||||
|
||||
// set up timer for auto refresh
|
||||
timer = new QTimer(this);
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
|
||||
QAbstractTableModel(parent), walletModel(parent)
|
||||
{
|
||||
nReceiveRequestsMaxId = 0;
|
||||
|
||||
// Load entries from wallet
|
||||
std::vector<std::string> vReceiveRequests;
|
||||
parent->loadReceiveRequests(vReceiveRequests);
|
||||
|
|
|
@ -94,7 +94,7 @@ private:
|
|||
WalletModel *walletModel;
|
||||
QStringList columns;
|
||||
QList<RecentRequestEntry> list;
|
||||
int64_t nReceiveRequestsMaxId;
|
||||
int64_t nReceiveRequestsMaxId{0};
|
||||
|
||||
/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
|
||||
void updateAmountColumnTitle();
|
||||
|
|
|
@ -40,8 +40,6 @@ WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, interfaces:
|
|||
cachedNumBlocks(0)
|
||||
{
|
||||
fHaveWatchOnly = m_wallet->haveWatchOnly();
|
||||
fForceCheckBalanceChanged = false;
|
||||
|
||||
addressTableModel = new AddressTableModel(this);
|
||||
transactionTableModel = new TransactionTableModel(platformStyle, this);
|
||||
recentRequestsTableModel = new RecentRequestsTableModel(this);
|
||||
|
|
|
@ -235,7 +235,7 @@ private:
|
|||
interfaces::Node& m_node;
|
||||
|
||||
bool fHaveWatchOnly;
|
||||
bool fForceCheckBalanceChanged;
|
||||
bool fForceCheckBalanceChanged{false};
|
||||
|
||||
// Wallet has an options model for wallet-specific options
|
||||
// (transaction fee, for example)
|
||||
|
|
|
@ -12,13 +12,9 @@
|
|||
|
||||
class CAddrManTest : public CAddrMan
|
||||
{
|
||||
uint64_t state;
|
||||
|
||||
public:
|
||||
explicit CAddrManTest(bool makeDeterministic = true)
|
||||
{
|
||||
state = 1;
|
||||
|
||||
if (makeDeterministic) {
|
||||
// Set addrman addr placement to be deterministic.
|
||||
MakeDeterministic();
|
||||
|
|
|
@ -1020,15 +1020,12 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)
|
|||
|
||||
struct tallyitem
|
||||
{
|
||||
CAmount nAmount;
|
||||
int nConf;
|
||||
CAmount nAmount{0};
|
||||
int nConf{std::numeric_limits<int>::max()};
|
||||
std::vector<uint256> txids;
|
||||
bool fIsWatchonly;
|
||||
bool fIsWatchonly{false};
|
||||
tallyitem()
|
||||
{
|
||||
nAmount = 0;
|
||||
nConf = std::numeric_limits<int>::max();
|
||||
fIsWatchonly = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1178,18 +1178,16 @@ class CReserveKey final : public CReserveScript
|
|||
{
|
||||
protected:
|
||||
CWallet* pwallet;
|
||||
int64_t nIndex;
|
||||
int64_t nIndex{-1};
|
||||
CPubKey vchPubKey;
|
||||
bool fInternal;
|
||||
bool fInternal{false};
|
||||
|
||||
public:
|
||||
explicit CReserveKey(CWallet* pwalletIn)
|
||||
{
|
||||
nIndex = -1;
|
||||
pwallet = pwalletIn;
|
||||
fInternal = false;
|
||||
}
|
||||
|
||||
CReserveKey() = default;
|
||||
CReserveKey(const CReserveKey&) = delete;
|
||||
CReserveKey& operator=(const CReserveKey&) = delete;
|
||||
|
||||
|
|
|
@ -153,21 +153,17 @@ bool WalletBatch::WriteMinVersion(int nVersion)
|
|||
|
||||
class CWalletScanState {
|
||||
public:
|
||||
unsigned int nKeys;
|
||||
unsigned int nCKeys;
|
||||
unsigned int nWatchKeys;
|
||||
unsigned int nKeyMeta;
|
||||
unsigned int m_unknown_records;
|
||||
bool fIsEncrypted;
|
||||
bool fAnyUnordered;
|
||||
int nFileVersion;
|
||||
unsigned int nKeys{0};
|
||||
unsigned int nCKeys{0};
|
||||
unsigned int nWatchKeys{0};
|
||||
unsigned int nKeyMeta{0};
|
||||
unsigned int m_unknown_records{0};
|
||||
bool fIsEncrypted{false};
|
||||
bool fAnyUnordered{false};
|
||||
int nFileVersion{0};
|
||||
std::vector<uint256> vWalletUpgrade;
|
||||
|
||||
CWalletScanState() {
|
||||
nKeys = nCKeys = nWatchKeys = nKeyMeta = m_unknown_records = 0;
|
||||
fIsEncrypted = false;
|
||||
fAnyUnordered = false;
|
||||
nFileVersion = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue