mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
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:
parent
1c3f12aacc
commit
95d588e9b4
@ -29,33 +29,31 @@
|
|||||||
*/
|
*/
|
||||||
class CAddrInfo : public CAddress
|
class CAddrInfo : public CAddress
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! last try whatsoever by us (memory only)
|
//! last try whatsoever by us (memory only)
|
||||||
int64_t nLastTry;
|
int64_t nLastTry{0};
|
||||||
|
|
||||||
//! last counted attempt (memory only)
|
//! last counted attempt (memory only)
|
||||||
int64_t nLastCountAttempt;
|
int64_t nLastCountAttempt{0};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! where knowledge about this address first came from
|
//! where knowledge about this address first came from
|
||||||
CNetAddr source;
|
CNetAddr source;
|
||||||
|
|
||||||
//! last successful connection by us
|
//! last successful connection by us
|
||||||
int64_t nLastSuccess;
|
int64_t nLastSuccess{0};
|
||||||
|
|
||||||
//! connection attempts since last successful attempt
|
//! connection attempts since last successful attempt
|
||||||
int nAttempts;
|
int nAttempts{0};
|
||||||
|
|
||||||
//! reference count in new sets (memory only)
|
//! reference count in new sets (memory only)
|
||||||
int nRefCount;
|
int nRefCount{0};
|
||||||
|
|
||||||
//! in tried set? (memory only)
|
//! in tried set? (memory only)
|
||||||
bool fInTried;
|
bool fInTried{false};
|
||||||
|
|
||||||
//! position in vRandom
|
//! position in vRandom
|
||||||
int nRandomPos;
|
int nRandomPos{-1};
|
||||||
|
|
||||||
friend class CAddrMan;
|
friend class CAddrMan;
|
||||||
|
|
||||||
@ -67,25 +65,12 @@ public:
|
|||||||
READWRITE(obj.source, obj.nLastSuccess, obj.nAttempts);
|
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)
|
CAddrInfo(const CAddress &addrIn, const CNetAddr &addrSource) : CAddress(addrIn), source(addrSource)
|
||||||
{
|
{
|
||||||
Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CAddrInfo() : CAddress(), source()
|
CAddrInfo() : CAddress(), source()
|
||||||
{
|
{
|
||||||
Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Calculate in which "tried" bucket this entry belongs
|
//! 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
|
//! Calculate the relative chance this entry should be given when selecting nodes to connect to
|
||||||
double GetChance(int64_t nNow = GetAdjustedTime()) const;
|
double GetChance(int64_t nNow = GetAdjustedTime()) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Stochastic address manager
|
/** Stochastic address manager
|
||||||
|
@ -129,7 +129,6 @@ public:
|
|||||||
|
|
||||||
struct HTTPPathHandler
|
struct HTTPPathHandler
|
||||||
{
|
{
|
||||||
HTTPPathHandler() {}
|
|
||||||
HTTPPathHandler(std::string _prefix, bool _exactMatch, HTTPRequestHandler _handler):
|
HTTPPathHandler(std::string _prefix, bool _exactMatch, HTTPRequestHandler _handler):
|
||||||
prefix(_prefix), exactMatch(_exactMatch), handler(_handler)
|
prefix(_prefix), exactMatch(_exactMatch), handler(_handler)
|
||||||
{
|
{
|
||||||
|
@ -2889,13 +2889,6 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) :
|
|||||||
addrman(Params().AllowMultiplePorts()),
|
addrman(Params().AllowMultiplePorts()),
|
||||||
nSeed0(nSeed0In), nSeed1(nSeed1In)
|
nSeed0(nSeed0In), nSeed1(nSeed1In)
|
||||||
{
|
{
|
||||||
fNetworkActive = true;
|
|
||||||
fAddressesInitialized = false;
|
|
||||||
nLastNodeId = 0;
|
|
||||||
nPrevNodeCount = 0;
|
|
||||||
nSendBufferMaxSize = 0;
|
|
||||||
nReceiveFloodSize = 0;
|
|
||||||
flagInterruptMsgProc = false;
|
|
||||||
SetTryNewOutboundPeer(false);
|
SetTryNewOutboundPeer(false);
|
||||||
|
|
||||||
Options connOptions;
|
Options connOptions;
|
||||||
|
14
src/net.h
14
src/net.h
@ -561,12 +561,12 @@ private:
|
|||||||
// whitelisted (as well as those connecting to whitelisted binds).
|
// whitelisted (as well as those connecting to whitelisted binds).
|
||||||
std::vector<NetWhitelistPermissions> vWhitelistedRange;
|
std::vector<NetWhitelistPermissions> vWhitelistedRange;
|
||||||
|
|
||||||
unsigned int nSendBufferMaxSize;
|
unsigned int nSendBufferMaxSize{0};
|
||||||
unsigned int nReceiveFloodSize;
|
unsigned int nReceiveFloodSize{0};
|
||||||
|
|
||||||
std::vector<ListenSocket> vhListenSocket;
|
std::vector<ListenSocket> vhListenSocket;
|
||||||
std::atomic<bool> fNetworkActive;
|
std::atomic<bool> fNetworkActive{true};
|
||||||
bool fAddressesInitialized;
|
bool fAddressesInitialized{false};
|
||||||
CAddrMan addrman;
|
CAddrMan addrman;
|
||||||
std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
|
std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
|
||||||
CCriticalSection cs_vOneShots;
|
CCriticalSection cs_vOneShots;
|
||||||
@ -581,8 +581,8 @@ private:
|
|||||||
std::list<CNode*> vNodesDisconnected;
|
std::list<CNode*> vNodesDisconnected;
|
||||||
std::unordered_map<SOCKET, CNode*> mapSocketToNode;
|
std::unordered_map<SOCKET, CNode*> mapSocketToNode;
|
||||||
mutable CCriticalSection cs_vNodes;
|
mutable CCriticalSection cs_vNodes;
|
||||||
std::atomic<NodeId> nLastNodeId;
|
std::atomic<NodeId> nLastNodeId{0};
|
||||||
unsigned int nPrevNodeCount;
|
unsigned int nPrevNodeCount{0};
|
||||||
|
|
||||||
/** Services this instance offers */
|
/** Services this instance offers */
|
||||||
ServiceFlags nLocalServices;
|
ServiceFlags nLocalServices;
|
||||||
@ -607,7 +607,7 @@ private:
|
|||||||
|
|
||||||
std::condition_variable condMsgProc;
|
std::condition_variable condMsgProc;
|
||||||
Mutex mutexMsgProc;
|
Mutex mutexMsgProc;
|
||||||
std::atomic<bool> flagInterruptMsgProc;
|
std::atomic<bool> flagInterruptMsgProc{false};
|
||||||
|
|
||||||
CThreadInterrupt interruptNet;
|
CThreadInterrupt interruptNet;
|
||||||
|
|
||||||
|
@ -432,7 +432,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
const char* GetCommandInternal() const;
|
const char* GetCommandInternal() const;
|
||||||
|
|
||||||
// TODO: make private (improves encapsulation)
|
|
||||||
public:
|
public:
|
||||||
int type;
|
int type;
|
||||||
uint256 hash;
|
uint256 hash;
|
||||||
|
@ -42,8 +42,8 @@ class BanTablePriv
|
|||||||
public:
|
public:
|
||||||
/** Local cache of peer information */
|
/** Local cache of peer information */
|
||||||
QList<CCombinedBan> cachedBanlist;
|
QList<CCombinedBan> cachedBanlist;
|
||||||
/** Column to sort nodes by */
|
/** Column to sort nodes by (default to unsorted) */
|
||||||
int sortColumn;
|
int sortColumn{-1};
|
||||||
/** Order (ascending or descending) to sort nodes by */
|
/** Order (ascending or descending) to sort nodes by */
|
||||||
Qt::SortOrder sortOrder;
|
Qt::SortOrder sortOrder;
|
||||||
|
|
||||||
@ -89,8 +89,6 @@ BanTableModel::BanTableModel(interfaces::Node& node, ClientModel *parent) :
|
|||||||
{
|
{
|
||||||
columns << tr("IP/Netmask") << tr("Banned Until");
|
columns << tr("IP/Netmask") << tr("Banned Until");
|
||||||
priv.reset(new BanTablePriv());
|
priv.reset(new BanTablePriv());
|
||||||
// default to unsorted
|
|
||||||
priv->sortColumn = -1;
|
|
||||||
|
|
||||||
// load initial data
|
// load initial data
|
||||||
refresh();
|
refresh();
|
||||||
|
@ -51,8 +51,8 @@ class PeerTablePriv
|
|||||||
public:
|
public:
|
||||||
/** Local cache of peer information */
|
/** Local cache of peer information */
|
||||||
QList<CNodeCombinedStats> cachedNodeStats;
|
QList<CNodeCombinedStats> cachedNodeStats;
|
||||||
/** Column to sort nodes by */
|
/** Column to sort nodes by (default to unsorted) */
|
||||||
int sortColumn;
|
int sortColumn{-1};
|
||||||
/** Order (ascending or descending) to sort nodes by */
|
/** Order (ascending or descending) to sort nodes by */
|
||||||
Qt::SortOrder sortOrder;
|
Qt::SortOrder sortOrder;
|
||||||
/** Index of rows by node ID */
|
/** 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");
|
columns << tr("NodeId") << tr("Node/Service") << tr("Ping") << tr("Sent") << tr("Received") << tr("User Agent");
|
||||||
priv.reset(new PeerTablePriv());
|
priv.reset(new PeerTablePriv());
|
||||||
// default to unsorted
|
|
||||||
priv->sortColumn = -1;
|
|
||||||
|
|
||||||
// set up timer for auto refresh
|
// set up timer for auto refresh
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
|
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
|
||||||
QAbstractTableModel(parent), walletModel(parent)
|
QAbstractTableModel(parent), walletModel(parent)
|
||||||
{
|
{
|
||||||
nReceiveRequestsMaxId = 0;
|
|
||||||
|
|
||||||
// Load entries from wallet
|
// Load entries from wallet
|
||||||
std::vector<std::string> vReceiveRequests;
|
std::vector<std::string> vReceiveRequests;
|
||||||
parent->loadReceiveRequests(vReceiveRequests);
|
parent->loadReceiveRequests(vReceiveRequests);
|
||||||
|
@ -86,7 +86,7 @@ private:
|
|||||||
WalletModel *walletModel;
|
WalletModel *walletModel;
|
||||||
QStringList columns;
|
QStringList columns;
|
||||||
QList<RecentRequestEntry> list;
|
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. */
|
/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
|
||||||
void updateAmountColumnTitle();
|
void updateAmountColumnTitle();
|
||||||
|
@ -39,8 +39,6 @@ WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, interfaces:
|
|||||||
cachedCoinJoinRounds(0)
|
cachedCoinJoinRounds(0)
|
||||||
{
|
{
|
||||||
fHaveWatchOnly = m_wallet->haveWatchOnly();
|
fHaveWatchOnly = m_wallet->haveWatchOnly();
|
||||||
fForceCheckBalanceChanged = false;
|
|
||||||
|
|
||||||
addressTableModel = new AddressTableModel(this);
|
addressTableModel = new AddressTableModel(this);
|
||||||
transactionTableModel = new TransactionTableModel(this);
|
transactionTableModel = new TransactionTableModel(this);
|
||||||
recentRequestsTableModel = new RecentRequestsTableModel(this);
|
recentRequestsTableModel = new RecentRequestsTableModel(this);
|
||||||
|
@ -226,7 +226,7 @@ private:
|
|||||||
interfaces::Node& m_node;
|
interfaces::Node& m_node;
|
||||||
|
|
||||||
bool fHaveWatchOnly;
|
bool fHaveWatchOnly;
|
||||||
bool fForceCheckBalanceChanged;
|
bool fForceCheckBalanceChanged{false};
|
||||||
|
|
||||||
// Wallet has an options model for wallet-specific options
|
// Wallet has an options model for wallet-specific options
|
||||||
// (transaction fee, for example)
|
// (transaction fee, for example)
|
||||||
|
@ -16,14 +16,11 @@ class CAddrManTest : public CAddrMan
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool deterministic;
|
bool deterministic;
|
||||||
uint64_t state;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CAddrManTest(bool makeDeterministic = true,
|
explicit CAddrManTest(bool makeDeterministic = true,
|
||||||
std::vector<bool> asmap = std::vector<bool>())
|
std::vector<bool> asmap = std::vector<bool>())
|
||||||
{
|
{
|
||||||
state = 1;
|
|
||||||
|
|
||||||
if (makeDeterministic) {
|
if (makeDeterministic) {
|
||||||
// Set addrman addr placement to be deterministic.
|
// Set addrman addr placement to be deterministic.
|
||||||
MakeDeterministic();
|
MakeDeterministic();
|
||||||
|
@ -1439,15 +1439,12 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
struct tallyitem
|
struct tallyitem
|
||||||
{
|
{
|
||||||
CAmount nAmount;
|
CAmount nAmount{0};
|
||||||
int nConf;
|
int nConf{std::numeric_limits<int>::max()};
|
||||||
std::vector<uint256> txids;
|
std::vector<uint256> txids;
|
||||||
bool fIsWatchonly;
|
bool fIsWatchonly{false};
|
||||||
tallyitem()
|
tallyitem()
|
||||||
{
|
{
|
||||||
nAmount = 0;
|
|
||||||
nConf = std::numeric_limits<int>::max();
|
|
||||||
fIsWatchonly = false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1341,18 +1341,16 @@ class CReserveKey final : public CReserveScript
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
CWallet* pwallet;
|
CWallet* pwallet;
|
||||||
int64_t nIndex;
|
int64_t nIndex{-1};
|
||||||
CPubKey vchPubKey;
|
CPubKey vchPubKey;
|
||||||
bool fInternal;
|
bool fInternal{false};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CReserveKey(CWallet* pwalletIn)
|
explicit CReserveKey(CWallet* pwalletIn)
|
||||||
{
|
{
|
||||||
nIndex = -1;
|
|
||||||
pwallet = pwalletIn;
|
pwallet = pwalletIn;
|
||||||
fInternal = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CReserveKey() = default;
|
|
||||||
CReserveKey(const CReserveKey&) = delete;
|
CReserveKey(const CReserveKey&) = delete;
|
||||||
CReserveKey& operator=(const CReserveKey&) = delete;
|
CReserveKey& operator=(const CReserveKey&) = delete;
|
||||||
|
|
||||||
|
@ -250,22 +250,18 @@ void WalletBatch::ListAccountCreditDebit(const std::string& strAccount, std::lis
|
|||||||
|
|
||||||
class CWalletScanState {
|
class CWalletScanState {
|
||||||
public:
|
public:
|
||||||
unsigned int nKeys;
|
unsigned int nKeys{0};
|
||||||
unsigned int nCKeys;
|
unsigned int nCKeys{0};
|
||||||
unsigned int nWatchKeys;
|
unsigned int nWatchKeys{0};
|
||||||
unsigned int nHDPubKeys;
|
unsigned int nHDPubKeys{0};
|
||||||
unsigned int nKeyMeta;
|
unsigned int nKeyMeta{0};
|
||||||
unsigned int m_unknown_records;
|
unsigned int m_unknown_records{0};
|
||||||
bool fIsEncrypted;
|
bool fIsEncrypted{false};
|
||||||
bool fAnyUnordered;
|
bool fAnyUnordered{false};
|
||||||
int nFileVersion;
|
int nFileVersion{0};
|
||||||
std::vector<uint256> vWalletUpgrade;
|
std::vector<uint256> vWalletUpgrade;
|
||||||
|
|
||||||
CWalletScanState() {
|
CWalletScanState() {
|
||||||
nKeys = nCKeys = nWatchKeys = nHDPubKeys = nKeyMeta = m_unknown_records = 0;
|
|
||||||
fIsEncrypted = false;
|
|
||||||
fAnyUnordered = false;
|
|
||||||
nFileVersion = 0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user