Browse Source

Merge #10645: Use nullptr (C++11) instead of zero (0) as the null pointer constant

36d326e8b Use nullptr instead of zero (0) as the null pointer constant (practicalswift)

Pull request description:

  Use `nullptr` instead of zero (0) as the null pointer constant.

  The road towards `nullptr` (C++11) is split into two PRs:
  * `NULL` → `nullptr` is handled in PR #10483 (scripted)
  * `0` → `nullptr` is handled in PR #10645 (manual, this PR)

  By using the C++11 keyword `nullptr` we are guaranteed a prvalue of type `std::nullptr_t`.

  For a more thorough discussion, see "A name for the null pointer: nullptr" (Sutter &
  Stroustrup), http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2431.pdf

Tree-SHA512: 5412404b40a94ea2d9fc8f81573559c4ffe559749301d486b09d41a7a736345ad602d08ac590930bb00a49692b6075520cf3d543e4da6ccd5b29fa9bcc3f15ea
0.16
MarcoFalke 7 years ago
parent
commit
c484ec6c9b
No known key found for this signature in database
GPG Key ID: D2EA4850E7528B25
  1. 4
      src/bench/lockedpool.cpp
  2. 2
      src/coins.cpp
  3. 4
      src/httprpc.cpp
  4. 14
      src/httpserver.cpp
  5. 10
      src/net.cpp
  6. 4
      src/netbase.h
  7. 2
      src/support/lockedpool.h
  8. 2
      src/sync.cpp
  9. 8
      src/torcontrol.cpp
  10. 2
      src/validation.h
  11. 4
      src/wallet/rpcwallet.cpp
  12. 16
      src/wallet/wallet.cpp
  13. 2
      src/wallet/walletdb.cpp
  14. 2
      src/zmq/zmqabstractnotifier.h
  15. 2
      src/zmq/zmqnotificationinterface.cpp
  16. 4
      src/zmq/zmqpublishnotifier.cpp

4
src/bench/lockedpool.cpp

@ -21,14 +21,14 @@ static void BenchLockedPool(benchmark::State& state)
std::vector<void*> addr; std::vector<void*> addr;
for (int x=0; x<ASIZE; ++x) for (int x=0; x<ASIZE; ++x)
addr.push_back(0); addr.push_back(nullptr);
uint32_t s = 0x12345678; uint32_t s = 0x12345678;
while (state.KeepRunning()) { while (state.KeepRunning()) {
for (int x=0; x<BITER; ++x) { for (int x=0; x<BITER; ++x) {
int idx = s & (addr.size()-1); int idx = s & (addr.size()-1);
if (s & 0x80000000) { if (s & 0x80000000) {
b.free(addr[idx]); b.free(addr[idx]);
addr[idx] = 0; addr[idx] = nullptr;
} else if(!addr[idx]) { } else if(!addr[idx]) {
addr[idx] = b.alloc((s >> 16) & (MSIZE-1)); addr[idx] = b.alloc((s >> 16) & (MSIZE-1));
} }

2
src/coins.cpp

@ -14,7 +14,7 @@ bool CCoinsView::GetCoin(const COutPoint &outpoint, Coin &coin) const { return f
uint256 CCoinsView::GetBestBlock() const { return uint256(); } uint256 CCoinsView::GetBestBlock() const { return uint256(); }
std::vector<uint256> CCoinsView::GetHeadBlocks() const { return std::vector<uint256>(); } std::vector<uint256> CCoinsView::GetHeadBlocks() const { return std::vector<uint256>(); }
bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; } bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; }
CCoinsViewCursor *CCoinsView::Cursor() const { return 0; } CCoinsViewCursor *CCoinsView::Cursor() const { return nullptr; }
bool CCoinsView::HaveCoin(const COutPoint &outpoint) const bool CCoinsView::HaveCoin(const COutPoint &outpoint) const
{ {

4
src/httprpc.cpp

@ -62,7 +62,7 @@ private:
/* Pre-base64-encoded authentication token */ /* Pre-base64-encoded authentication token */
static std::string strRPCUserColonPass; static std::string strRPCUserColonPass;
/* Stored RPC timer interface (for unregistration) */ /* Stored RPC timer interface (for unregistration) */
static HTTPRPCTimerInterface* httpRPCTimerInterface = 0; static HTTPRPCTimerInterface* httpRPCTimerInterface = nullptr;
static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const UniValue& id) static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const UniValue& id)
{ {
@ -255,6 +255,6 @@ void StopHTTPRPC()
if (httpRPCTimerInterface) { if (httpRPCTimerInterface) {
RPCUnsetTimerInterface(httpRPCTimerInterface); RPCUnsetTimerInterface(httpRPCTimerInterface);
delete httpRPCTimerInterface; delete httpRPCTimerInterface;
httpRPCTimerInterface = 0; httpRPCTimerInterface = nullptr;
} }
} }

14
src/httpserver.cpp

@ -164,13 +164,13 @@ struct HTTPPathHandler
/** HTTP module state */ /** HTTP module state */
//! libevent event loop //! libevent event loop
static struct event_base* eventBase = 0; static struct event_base* eventBase = nullptr;
//! HTTP server //! HTTP server
struct evhttp* eventHTTP = 0; struct evhttp* eventHTTP = nullptr;
//! List of subnets to allow RPC connections from //! List of subnets to allow RPC connections from
static std::vector<CSubNet> rpc_allow_subnets; static std::vector<CSubNet> rpc_allow_subnets;
//! Work queue for handling longer requests off the event loop thread //! Work queue for handling longer requests off the event loop thread
static WorkQueue<HTTPClosure>* workQueue = 0; static WorkQueue<HTTPClosure>* workQueue = nullptr;
//! Handlers for (sub)paths //! Handlers for (sub)paths
std::vector<HTTPPathHandler> pathHandlers; std::vector<HTTPPathHandler> pathHandlers;
//! Bound listening sockets //! Bound listening sockets
@ -495,11 +495,11 @@ void StopHTTPServer()
} }
if (eventHTTP) { if (eventHTTP) {
evhttp_free(eventHTTP); evhttp_free(eventHTTP);
eventHTTP = 0; eventHTTP = nullptr;
} }
if (eventBase) { if (eventBase) {
event_base_free(eventBase); event_base_free(eventBase);
eventBase = 0; eventBase = nullptr;
} }
LogPrint(BCLog::HTTP, "Stopped HTTP server\n"); LogPrint(BCLog::HTTP, "Stopped HTTP server\n");
} }
@ -601,9 +601,9 @@ void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
evbuffer_add(evb, strReply.data(), strReply.size()); evbuffer_add(evb, strReply.data(), strReply.size());
HTTPEvent* ev = new HTTPEvent(eventBase, true, HTTPEvent* ev = new HTTPEvent(eventBase, true,
std::bind(evhttp_send_reply, req, nStatus, (const char*)nullptr, (struct evbuffer *)nullptr)); std::bind(evhttp_send_reply, req, nStatus, (const char*)nullptr, (struct evbuffer *)nullptr));
ev->trigger(0); ev->trigger(nullptr);
replySent = true; replySent = true;
req = 0; // transferred back to main thread req = nullptr; // transferred back to main thread
} }
CService HTTPRequest::GetPeer() CService HTTPRequest::GetPeer()

10
src/net.cpp

@ -1438,9 +1438,9 @@ void CConnman::WakeMessageHandler()
void ThreadMapPort() void ThreadMapPort()
{ {
std::string port = strprintf("%u", GetListenPort()); std::string port = strprintf("%u", GetListenPort());
const char * multicastif = 0; const char * multicastif = nullptr;
const char * minissdpdpath = 0; const char * minissdpdpath = nullptr;
struct UPNPDev * devlist = 0; struct UPNPDev * devlist = nullptr;
char lanaddr[64]; char lanaddr[64];
#ifndef UPNPDISCOVER_SUCCESS #ifndef UPNPDISCOVER_SUCCESS
@ -1510,13 +1510,13 @@ void ThreadMapPort()
{ {
r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0); r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0);
LogPrintf("UPNP_DeletePortMapping() returned: %d\n", r); LogPrintf("UPNP_DeletePortMapping() returned: %d\n", r);
freeUPNPDevlist(devlist); devlist = 0; freeUPNPDevlist(devlist); devlist = nullptr;
FreeUPNPUrls(&urls); FreeUPNPUrls(&urls);
throw; throw;
} }
} else { } else {
LogPrintf("No valid UPnP IGDs found\n"); LogPrintf("No valid UPnP IGDs found\n");
freeUPNPDevlist(devlist); devlist = 0; freeUPNPDevlist(devlist); devlist = nullptr;
if (r != 0) if (r != 0)
FreeUPNPUrls(&urls); FreeUPNPUrls(&urls);
} }

4
src/netbase.h

@ -50,8 +50,8 @@ bool Lookup(const char *pszName, CService& addr, int portDefault, bool fAllowLoo
bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions); bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
CService LookupNumeric(const char *pszName, int portDefault = 0); CService LookupNumeric(const char *pszName, int portDefault = 0);
bool LookupSubNet(const char *pszName, CSubNet& subnet); bool LookupSubNet(const char *pszName, CSubNet& subnet);
bool ConnectSocket(const CService &addr, SOCKET& hSocketRet, int nTimeout, bool *outProxyConnectionFailed = 0); bool ConnectSocket(const CService &addr, SOCKET& hSocketRet, int nTimeout, bool *outProxyConnectionFailed = nullptr);
bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest, int portDefault, int nTimeout, bool *outProxyConnectionFailed = 0); bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest, int portDefault, int nTimeout, bool *outProxyConnectionFailed = nullptr);
/** Return readable error string for a network error code */ /** Return readable error string for a network error code */
std::string NetworkErrorString(int err); std::string NetworkErrorString(int err);
/** Close socket and set hSocket to INVALID_SOCKET */ /** Close socket and set hSocket to INVALID_SOCKET */

2
src/support/lockedpool.h

@ -150,7 +150,7 @@ public:
* If this callback is provided and returns false, the allocation fails (hard fail), if * If this callback is provided and returns false, the allocation fails (hard fail), if
* it returns true the allocation proceeds, but it could warn. * it returns true the allocation proceeds, but it could warn.
*/ */
LockedPool(std::unique_ptr<LockedPageAllocator> allocator, LockingFailed_Callback lf_cb_in = 0); LockedPool(std::unique_ptr<LockedPageAllocator> allocator, LockingFailed_Callback lf_cb_in = nullptr);
~LockedPool(); ~LockedPool();
/** Allocate size bytes from this arena. /** Allocate size bytes from this arena.

2
src/sync.cpp

@ -162,7 +162,7 @@ void DeleteLock(void* cs)
return; return;
} }
boost::unique_lock<boost::mutex> lock(lockdata.dd_mutex); boost::unique_lock<boost::mutex> lock(lockdata.dd_mutex);
std::pair<void*, void*> item = std::make_pair(cs, (void*)0); std::pair<void*, void*> item = std::make_pair(cs, nullptr);
LockOrders::iterator it = lockdata.lockorders.lower_bound(item); LockOrders::iterator it = lockdata.lockorders.lower_bound(item);
while (it != lockdata.lockorders.end() && it->first.first == cs) { while (it != lockdata.lockorders.end() && it->first.first == cs) {
std::pair<void*, void*> invitem = std::make_pair(it->first.second, it->first.first); std::pair<void*, void*> invitem = std::make_pair(it->first.second, it->first.first);

8
src/torcontrol.cpp

@ -121,7 +121,7 @@ private:
}; };
TorControlConnection::TorControlConnection(struct event_base *_base): TorControlConnection::TorControlConnection(struct event_base *_base):
base(_base), b_conn(0) base(_base), b_conn(nullptr)
{ {
} }
@ -227,7 +227,7 @@ bool TorControlConnection::Disconnect()
{ {
if (b_conn) if (b_conn)
bufferevent_free(b_conn); bufferevent_free(b_conn);
b_conn = 0; b_conn = nullptr;
return true; return true;
} }
@ -476,7 +476,7 @@ TorController::~TorController()
{ {
if (reconnect_ev) { if (reconnect_ev) {
event_free(reconnect_ev); event_free(reconnect_ev);
reconnect_ev = 0; reconnect_ev = nullptr;
} }
if (service.IsValid()) { if (service.IsValid()) {
RemoveLocal(service); RemoveLocal(service);
@ -770,7 +770,7 @@ void StopTorControl()
if (gBase) { if (gBase) {
torControlThread.join(); torControlThread.join();
event_base_free(gBase); event_base_free(gBase);
gBase = 0; gBase = nullptr;
} }
} }

2
src/validation.h

@ -365,7 +365,7 @@ private:
PrecomputedTransactionData *txdata; PrecomputedTransactionData *txdata;
public: public:
CScriptCheck(): amount(0), ptxTo(0), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {} CScriptCheck(): amount(0), ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
CScriptCheck(const CScript& scriptPubKeyIn, const CAmount amountIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) : CScriptCheck(const CScript& scriptPubKeyIn, const CAmount amountIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
scriptPubKey(scriptPubKeyIn), amount(amountIn), scriptPubKey(scriptPubKeyIn), amount(amountIn),
ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { } ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }

4
src/wallet/rpcwallet.cpp

@ -1644,10 +1644,10 @@ UniValue listtransactions(const JSONRPCRequest& request)
for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
{ {
CWalletTx *const pwtx = (*it).second.first; CWalletTx *const pwtx = (*it).second.first;
if (pwtx != 0) if (pwtx != nullptr)
ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter); ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter);
CAccountingEntry *const pacentry = (*it).second.second; CAccountingEntry *const pacentry = (*it).second.second;
if (pacentry != 0) if (pacentry != nullptr)
AcentryToJSON(*pacentry, strAccount, ret); AcentryToJSON(*pacentry, strAccount, ret);
if ((int)ret.size() >= (nCount+nFrom)) break; if ((int)ret.size() >= (nCount+nFrom)) break;

16
src/wallet/wallet.cpp

@ -739,13 +739,13 @@ DBErrors CWallet::ReorderTransactions()
for (std::map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) for (std::map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{ {
CWalletTx* wtx = &((*it).second); CWalletTx* wtx = &((*it).second);
txByTime.insert(std::make_pair(wtx->nTimeReceived, TxPair(wtx, (CAccountingEntry*)0))); txByTime.insert(std::make_pair(wtx->nTimeReceived, TxPair(wtx, nullptr)));
} }
std::list<CAccountingEntry> acentries; std::list<CAccountingEntry> acentries;
walletdb.ListAccountCreditDebit("", acentries); walletdb.ListAccountCreditDebit("", acentries);
for (CAccountingEntry& entry : acentries) for (CAccountingEntry& entry : acentries)
{ {
txByTime.insert(std::make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry))); txByTime.insert(std::make_pair(entry.nTime, TxPair(nullptr, &entry)));
} }
nOrderPosNext = 0; nOrderPosNext = 0;
@ -754,7 +754,7 @@ DBErrors CWallet::ReorderTransactions()
{ {
CWalletTx *const pwtx = (*it).second.first; CWalletTx *const pwtx = (*it).second.first;
CAccountingEntry *const pacentry = (*it).second.second; CAccountingEntry *const pacentry = (*it).second.second;
int64_t& nOrderPos = (pwtx != 0) ? pwtx->nOrderPos : pacentry->nOrderPos; int64_t& nOrderPos = (pwtx != nullptr) ? pwtx->nOrderPos : pacentry->nOrderPos;
if (nOrderPos == -1) if (nOrderPos == -1)
{ {
@ -939,7 +939,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
{ {
wtx.nTimeReceived = GetAdjustedTime(); wtx.nTimeReceived = GetAdjustedTime();
wtx.nOrderPos = IncOrderPosNext(&walletdb); wtx.nOrderPos = IncOrderPosNext(&walletdb);
wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0))); wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
wtx.nTimeSmart = ComputeTimeSmart(wtx); wtx.nTimeSmart = ComputeTimeSmart(wtx);
AddToSpends(hash); AddToSpends(hash);
} }
@ -1004,7 +1004,7 @@ bool CWallet::LoadToWallet(const CWalletTx& wtxIn)
mapWallet[hash] = wtxIn; mapWallet[hash] = wtxIn;
CWalletTx& wtx = mapWallet[hash]; CWalletTx& wtx = mapWallet[hash];
wtx.BindWallet(this); wtx.BindWallet(this);
wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0))); wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
AddToSpends(hash); AddToSpends(hash);
for (const CTxIn& txin : wtx.tx->vin) { for (const CTxIn& txin : wtx.tx->vin) {
if (mapWallet.count(txin.prevout.hash)) { if (mapWallet.count(txin.prevout.hash)) {
@ -1794,7 +1794,7 @@ CAmount CWalletTx::GetImmatureCredit(bool fUseCache) const
CAmount CWalletTx::GetAvailableCredit(bool fUseCache) const CAmount CWalletTx::GetAvailableCredit(bool fUseCache) const
{ {
if (pwallet == 0) if (pwallet == nullptr)
return 0; return 0;
// Must wait until coinbase is safely deep enough in the chain before valuing it // Must wait until coinbase is safely deep enough in the chain before valuing it
@ -1838,7 +1838,7 @@ CAmount CWalletTx::GetImmatureWatchOnlyCredit(const bool& fUseCache) const
CAmount CWalletTx::GetAvailableWatchOnlyCredit(const bool& fUseCache) const CAmount CWalletTx::GetAvailableWatchOnlyCredit(const bool& fUseCache) const
{ {
if (pwallet == 0) if (pwallet == nullptr)
return 0; return 0;
// Must wait until coinbase is safely deep enough in the chain before valuing it // Must wait until coinbase is safely deep enough in the chain before valuing it
@ -3026,7 +3026,7 @@ bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry, CWalletDB *pwa
laccentries.push_back(acentry); laccentries.push_back(acentry);
CAccountingEntry & entry = laccentries.back(); CAccountingEntry & entry = laccentries.back();
wtxOrdered.insert(std::make_pair(entry.nOrderPos, TxPair((CWalletTx*)0, &entry))); wtxOrdered.insert(std::make_pair(entry.nOrderPos, TxPair(nullptr, &entry)));
return true; return true;
} }

2
src/wallet/walletdb.cpp

@ -621,7 +621,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
pwallet->laccentries.clear(); pwallet->laccentries.clear();
ListAccountCreditDebit("*", pwallet->laccentries); ListAccountCreditDebit("*", pwallet->laccentries);
for (CAccountingEntry& entry : pwallet->laccentries) { for (CAccountingEntry& entry : pwallet->laccentries) {
pwallet->wtxOrdered.insert(make_pair(entry.nOrderPos, CWallet::TxPair((CWalletTx*)0, &entry))); pwallet->wtxOrdered.insert(make_pair(entry.nOrderPos, CWallet::TxPair(nullptr, &entry)));
} }
return result; return result;

2
src/zmq/zmqabstractnotifier.h

@ -15,7 +15,7 @@ typedef CZMQAbstractNotifier* (*CZMQNotifierFactory)();
class CZMQAbstractNotifier class CZMQAbstractNotifier
{ {
public: public:
CZMQAbstractNotifier() : psocket(0) { } CZMQAbstractNotifier() : psocket(nullptr) { }
virtual ~CZMQAbstractNotifier(); virtual ~CZMQAbstractNotifier();
template <typename T> template <typename T>

2
src/zmq/zmqnotificationinterface.cpp

@ -120,7 +120,7 @@ void CZMQNotificationInterface::Shutdown()
} }
zmq_ctx_destroy(pcontext); zmq_ctx_destroy(pcontext);
pcontext = 0; pcontext = nullptr;
} }
} }

4
src/zmq/zmqpublishnotifier.cpp

@ -126,7 +126,7 @@ void CZMQAbstractPublishNotifier::Shutdown()
zmq_close(psocket); zmq_close(psocket);
} }
psocket = 0; psocket = nullptr;
} }
bool CZMQAbstractPublishNotifier::SendMessage(const char *command, const void* data, size_t size) bool CZMQAbstractPublishNotifier::SendMessage(const char *command, const void* data, size_t size)
@ -136,7 +136,7 @@ bool CZMQAbstractPublishNotifier::SendMessage(const char *command, const void* d
/* send three parts, command & data & a LE 4byte sequence number */ /* send three parts, command & data & a LE 4byte sequence number */
unsigned char msgseq[sizeof(uint32_t)]; unsigned char msgseq[sizeof(uint32_t)];
WriteLE32(&msgseq[0], nSequence); WriteLE32(&msgseq[0], nSequence);
int rc = zmq_send_multipart(psocket, command, strlen(command), data, size, msgseq, (size_t)sizeof(uint32_t), (void*)0); int rc = zmq_send_multipart(psocket, command, strlen(command), data, size, msgseq, (size_t)sizeof(uint32_t), nullptr);
if (rc == -1) if (rc == -1)
return false; return false;

Loading…
Cancel
Save