Merge #15109: refactor: Use C++11 default member initializers

fa2510d5c1cdf9c2cd5cc9887302ced4378c7202 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:
Wladimir J. van der Laan 2019-01-09 14:59:57 +01:00 committed by pbattu
parent 1c3f12aacc
commit 95d588e9b4
15 changed files with 35 additions and 80 deletions

View File

@ -29,33 +29,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;
@ -67,25 +65,12 @@ public:
READWRITE(obj.source, obj.nLastSuccess, obj.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
@ -108,7 +93,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

View File

@ -129,7 +129,6 @@ public:
struct HTTPPathHandler
{
HTTPPathHandler() {}
HTTPPathHandler(std::string _prefix, bool _exactMatch, HTTPRequestHandler _handler):
prefix(_prefix), exactMatch(_exactMatch), handler(_handler)
{

View File

@ -2889,13 +2889,6 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) :
addrman(Params().AllowMultiplePorts()),
nSeed0(nSeed0In), nSeed1(nSeed1In)
{
fNetworkActive = true;
fAddressesInitialized = false;
nLastNodeId = 0;
nPrevNodeCount = 0;
nSendBufferMaxSize = 0;
nReceiveFloodSize = 0;
flagInterruptMsgProc = false;
SetTryNewOutboundPeer(false);
Options connOptions;

View File

@ -561,12 +561,12 @@ private:
// whitelisted (as well as those connecting to whitelisted binds).
std::vector<NetWhitelistPermissions> vWhitelistedRange;
unsigned int nSendBufferMaxSize;
unsigned int nReceiveFloodSize;
unsigned int nSendBufferMaxSize{0};
unsigned int nReceiveFloodSize{0};
std::vector<ListenSocket> vhListenSocket;
std::atomic<bool> fNetworkActive;
bool fAddressesInitialized;
std::atomic<bool> fNetworkActive{true};
bool fAddressesInitialized{false};
CAddrMan addrman;
std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
CCriticalSection cs_vOneShots;
@ -581,8 +581,8 @@ private:
std::list<CNode*> vNodesDisconnected;
std::unordered_map<SOCKET, CNode*> mapSocketToNode;
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;
@ -607,7 +607,7 @@ private:
std::condition_variable condMsgProc;
Mutex mutexMsgProc;
std::atomic<bool> flagInterruptMsgProc;
std::atomic<bool> flagInterruptMsgProc{false};
CThreadInterrupt interruptNet;

View File

@ -432,7 +432,6 @@ public:
private:
const char* GetCommandInternal() const;
// TODO: make private (improves encapsulation)
public:
int type;
uint256 hash;

View File

@ -42,8 +42,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;
@ -89,8 +89,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();

View File

@ -51,8 +51,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 */
@ -111,8 +111,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);

View File

@ -17,8 +17,6 @@
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
QAbstractTableModel(parent), walletModel(parent)
{
nReceiveRequestsMaxId = 0;
// Load entries from wallet
std::vector<std::string> vReceiveRequests;
parent->loadReceiveRequests(vReceiveRequests);

View File

@ -86,7 +86,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();

View File

@ -39,8 +39,6 @@ WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, interfaces:
cachedCoinJoinRounds(0)
{
fHaveWatchOnly = m_wallet->haveWatchOnly();
fForceCheckBalanceChanged = false;
addressTableModel = new AddressTableModel(this);
transactionTableModel = new TransactionTableModel(this);
recentRequestsTableModel = new RecentRequestsTableModel(this);

View File

@ -226,7 +226,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)

View File

@ -16,14 +16,11 @@ class CAddrManTest : public CAddrMan
{
private:
bool deterministic;
uint64_t state;
public:
explicit CAddrManTest(bool makeDeterministic = true,
std::vector<bool> asmap = std::vector<bool>())
{
state = 1;
if (makeDeterministic) {
// Set addrman addr placement to be deterministic.
MakeDeterministic();

View File

@ -1439,15 +1439,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;
}
};

View File

@ -1341,18 +1341,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;

View File

@ -250,22 +250,18 @@ void WalletBatch::ListAccountCreditDebit(const std::string& strAccount, std::lis
class CWalletScanState {
public:
unsigned int nKeys;
unsigned int nCKeys;
unsigned int nWatchKeys;
unsigned int nHDPubKeys;
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 nHDPubKeys{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 = nHDPubKeys = nKeyMeta = m_unknown_records = 0;
fIsEncrypted = false;
fAnyUnordered = false;
nFileVersion = 0;
}
};