diff --git a/src/addrman.cpp b/src/addrman.cpp index ad76b9850c944..bc262c23e1ac4 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -80,13 +80,13 @@ CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId) { std::map::iterator it = mapAddr.find(addr); if (it == mapAddr.end()) - return NULL; + return nullptr; if (pnId) *pnId = (*it).second; std::map::iterator it2 = mapInfo.find((*it).second); if (it2 != mapInfo.end()) return &(*it2).second; - return NULL; + return nullptr; } CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, int* pnId) diff --git a/src/arith_uint256.h b/src/arith_uint256.h index e51b15cfc8ca9..0f14c17f10c3e 100644 --- a/src/arith_uint256.h +++ b/src/arith_uint256.h @@ -353,7 +353,7 @@ class arith_uint256 : public base_uint<256> { * complexities of the sign bit and using base 256 are probably an * implementation accident. */ - arith_uint256& SetCompact(uint32_t nCompact, bool *pfNegative = NULL, bool *pfOverflow = NULL); + arith_uint256& SetCompact(uint32_t nCompact, bool *pfNegative = nullptr, bool *pfOverflow = nullptr); uint32_t GetCompact(bool fNegative = false) const; uint32_t Get32(int n = 0) const { return pn[2 * n]; } diff --git a/src/base58.cpp b/src/base58.cpp index 5cb452432fe2c..fd81c0850fdb5 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -40,7 +40,7 @@ bool DecodeBase58(const char* psz, std::vector& vch, int max_ret_ while (*psz && !isspace(*psz)) { // Decode base58 character const char* ch = strchr(pszBase58, *psz); - if (ch == NULL) + if (ch == nullptr) return false; // Apply "b256 = b256 * 58 + ch". int carry = ch - pszBase58; diff --git a/src/base58.h b/src/base58.h index 2a26c43209615..2d7a520bfccf2 100644 --- a/src/base58.h +++ b/src/base58.h @@ -26,7 +26,7 @@ /** * Encode a byte sequence as a base58-encoded string. - * pbegin and pend cannot be NULL, unless both are. + * pbegin and pend cannot be nullptr, unless both are. */ std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend); @@ -38,7 +38,7 @@ std::string EncodeBase58(const std::vector& vch); /** * Decode a base58-encoded string (psz) into a byte vector (vchRet). * return true if decoding is successful. - * psz cannot be NULL. + * psz cannot be nullptr. */ NODISCARD bool DecodeBase58(const char* psz, std::vector& vchRet, int max_ret_len); diff --git a/src/budget/budgetmanager.cpp b/src/budget/budgetmanager.cpp index 10bb93398eb74..9cf51d3b9133b 100644 --- a/src/budget/budgetmanager.cpp +++ b/src/budget/budgetmanager.cpp @@ -624,7 +624,7 @@ void CBudgetManager::VoteOnFinalizedBudgets() } } std::string strError = ""; - if (!UpdateFinalizedBudget(vote, NULL, strError)) { + if (!UpdateFinalizedBudget(vote, nullptr, strError)) { LogPrintf("%s: Error submitting vote - %s\n", __func__, strError); continue; } diff --git a/src/chain.cpp b/src/chain.cpp index 5ef1ea00c2a25..b9a2baad95096 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -13,7 +13,7 @@ */ void CChain::SetTip(CBlockIndex* pindex) { - if (pindex == NULL) { + if (pindex == nullptr) { vChain.clear(); return; } @@ -333,7 +333,7 @@ bool CBlockIndex::RaiseValidity(enum BlockStatus nUpTo) } /** Find the last common ancestor two blocks have. - * Both pa and pb must be non-NULL. */ + * Both pa and pb must be non-nullptr. */ const CBlockIndex* LastCommonAncestor(const CBlockIndex* pa, const CBlockIndex* pb) { if (pa->nHeight > pb->nHeight) { diff --git a/src/chain.h b/src/chain.h index cd20e255844f3..bdc4e54901e03 100644 --- a/src/chain.h +++ b/src/chain.h @@ -395,17 +395,17 @@ class CChain std::vector vChain; public: - /** Returns the index entry for the genesis block of this chain, or NULL if none. */ + /** Returns the index entry for the genesis block of this chain, or nullptr if none. */ CBlockIndex* Genesis() const { - return vChain.size() > 0 ? vChain[0] : NULL; + return vChain.size() > 0 ? vChain[0] : nullptr; } - /** Returns the index entry for the tip of this chain, or NULL if none. */ + /** Returns the index entry for the tip of this chain, or nullptr if none. */ CBlockIndex* Tip(bool fProofOfStake = false) const { if (vChain.size() < 1) - return NULL; + return nullptr; CBlockIndex* pindex = vChain[vChain.size() - 1]; @@ -416,11 +416,11 @@ class CChain return pindex; } - /** Returns the index entry at a particular height in this chain, or NULL if no such height exists. */ + /** Returns the index entry at a particular height in this chain, or nullptr if no such height exists. */ CBlockIndex* operator[](int nHeight) const { if (nHeight < 0 || nHeight >= (int)vChain.size()) - return NULL; + return nullptr; return vChain[nHeight]; } @@ -437,13 +437,13 @@ class CChain return (*this)[pindex->nHeight] == pindex; } - /** Find the successor of a block in this chain, or NULL if the given index is not found or is the tip. */ + /** Find the successor of a block in this chain, or nullptr if the given index is not found or is the tip. */ CBlockIndex* Next(const CBlockIndex* pindex) const { if (Contains(pindex)) return (*this)[pindex->nHeight + 1]; else - return NULL; + return nullptr; } /** Return the maximal height in the chain. Is equal to chain.Tip() ? chain.Tip()->nHeight : -1. */ @@ -456,7 +456,7 @@ class CChain void SetTip(CBlockIndex* pindex); /** Return a CBlockLocator that refers to a block in this chain (by default the tip). */ - CBlockLocator GetLocator(const CBlockIndex* pindex = NULL) const; + CBlockLocator GetLocator(const CBlockIndex* pindex = nullptr) const; /** Find the last common block between this chain and a block index entry. */ const CBlockIndex* FindFork(const CBlockIndex* pindex) const; diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 00f798b4596d1..d85abfcf42ceb 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -42,10 +42,10 @@ bool CheckBlock(int nHeight, const uint256& hash, bool fMatchesCheckpoint) //! Guess how far we are in the verification process at the given block index double GuessVerificationProgress(const CBlockIndex* pindex, bool fSigchecks) { - if (pindex == NULL) + if (pindex == nullptr) return 0.0; - int64_t nNow = time(NULL); + int64_t nNow = time(nullptr); double fSigcheckVerificationFactor = fSigchecks ? SIGCHECK_VERIFICATION_FACTOR : 1.0; double fWorkBefore = 0.0; // Amount of work done before pindex diff --git a/src/checkqueue.h b/src/checkqueue.h index e64cdf502474c..78f7f1b4d97e2 100644 --- a/src/checkqueue.h +++ b/src/checkqueue.h @@ -177,8 +177,8 @@ class CCheckQueueControl public: CCheckQueueControl(CCheckQueue* pqueueIn) : pqueue(pqueueIn), fDone(false) { - // passed queue is supposed to be unused, or NULL - if (pqueue != NULL) { + // passed queue is supposed to be unused, or nullptr + if (pqueue != nullptr) { bool isIdle = pqueue->IsIdle(); assert(isIdle); } @@ -186,7 +186,7 @@ class CCheckQueueControl bool Wait() { - if (pqueue == NULL) + if (pqueue == nullptr) return true; bool fRet = pqueue->Wait(); fDone = true; @@ -195,7 +195,7 @@ class CCheckQueueControl void Add(std::vector& vChecks) { - if (pqueue != NULL) + if (pqueue != nullptr) pqueue->Add(vChecks); } diff --git a/src/consensus/merkle.cpp b/src/consensus/merkle.cpp index b783a50478286..87e2ca6608a62 100644 --- a/src/consensus/merkle.cpp +++ b/src/consensus/merkle.cpp @@ -128,13 +128,13 @@ static void MerkleComputation(const std::vector& leaves, uint256* proot uint256 ComputeMerkleRoot(const std::vector& leaves, bool* mutated) { uint256 hash; - MerkleComputation(leaves, &hash, mutated, -1, NULL); + MerkleComputation(leaves, &hash, mutated, -1, nullptr); return hash; } std::vector ComputeMerkleBranch(const std::vector& leaves, uint32_t position) { std::vector ret; - MerkleComputation(leaves, NULL, NULL, position, &ret); + MerkleComputation(leaves, nullptr, nullptr, position, &ret); return ret; } diff --git a/src/consensus/merkle.h b/src/consensus/merkle.h index 8f4bf8a493895..65a039de24c76 100644 --- a/src/consensus/merkle.h +++ b/src/consensus/merkle.h @@ -12,7 +12,7 @@ #include "primitives/block.h" #include "uint256.h" -uint256 ComputeMerkleRoot(const std::vector& leaves, bool* mutated = NULL); +uint256 ComputeMerkleRoot(const std::vector& leaves, bool* mutated = nullptr); std::vector ComputeMerkleBranch(const std::vector& leaves, uint32_t position); uint256 ComputeMerkleRootFromBranch(const uint256& leaf, const std::vector& branch, uint32_t position); @@ -20,7 +20,7 @@ uint256 ComputeMerkleRootFromBranch(const uint256& leaf, const std::vectorsecond + "]"; diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index 31f1b1e655638..323ec025cc62e 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -54,7 +54,7 @@ static leveldb::Options GetOptions(size_t nCacheSize) CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bool fWipe) { - penv = NULL; + penv = nullptr; readoptions.verify_checksums = true; iteroptions.verify_checksums = true; iteroptions.fill_cache = false; @@ -81,13 +81,13 @@ CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bo CDBWrapper::~CDBWrapper() { delete pdb; - pdb = NULL; + pdb = nullptr; delete options.filter_policy; - options.filter_policy = NULL; + options.filter_policy = nullptr; delete options.block_cache; - options.block_cache = NULL; + options.block_cache = nullptr; delete penv; - options.env = NULL; + options.env = nullptr; } bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync) diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 30a561df67a65..dd21453299eb9 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -195,7 +195,7 @@ class CDBIterator class CDBWrapper { private: - //! custom environment this database is using (may be NULL in case of default environment) + //! custom environment this database is using (may be nullptr in case of default environment) leveldb::Env* penv; //! database options used diff --git a/src/hash.h b/src/hash.h index df9f11fbbe8c6..7d4df0ff5090e 100644 --- a/src/hash.h +++ b/src/hash.h @@ -306,9 +306,9 @@ class CBLAKE2bWriter CBLAKE2bWriter(int nTypeIn, int nVersionIn, const unsigned char* personal) : nType(nTypeIn), nVersion(nVersionIn) { assert(crypto_generichash_blake2b_init_salt_personal( &state, - NULL, 0, // No key. + nullptr, 0, // No key. 32, - NULL, // No salt. + nullptr, // No salt. personal) == 0); } diff --git a/src/httpserver.cpp b/src/httpserver.cpp index 0ce7d6f74d83e..6a796cbbbbe3a 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -278,7 +278,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg) static void http_reject_request_cb(struct evhttp_request* req, void*) { LogPrint(BCLog::HTTP, "Rejecting request while shutting down\n"); - evhttp_send_error(req, HTTP_SERVUNAVAIL, NULL); + evhttp_send_error(req, HTTP_SERVUNAVAIL, nullptr); } /** Event dispatcher thread */ static bool ThreadHTTP(struct event_base* base, struct evhttp* http) @@ -319,7 +319,7 @@ static bool HTTPBindAddresses(struct evhttp* http) // Bind addresses for (std::vector >::iterator i = endpoints.begin(); i != endpoints.end(); ++i) { LogPrint(BCLog::HTTP, "Binding RPC on address %s port %i\n", i->first, i->second); - evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? NULL : i->first.c_str(), i->second); + evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? nullptr : i->first.c_str(), i->second); if (bind_handle) { CNetAddr addr; if (i->first.empty() || (LookupHost(i->first, addr, false) && addr.IsBindAny())) { @@ -393,7 +393,7 @@ bool InitHTTPServer() evhttp_set_timeout(http, gArgs.GetArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT)); evhttp_set_max_headers_size(http, MAX_HEADERS_SIZE); evhttp_set_max_body_size(http, MAX_SIZE); - evhttp_set_gencb(http, http_request_cb, NULL); + evhttp_set_gencb(http, http_request_cb, nullptr); if (!HTTPBindAddresses(http)) { LogPrintf("Unable to bind any endpoint for RPC server\n"); @@ -451,7 +451,7 @@ void InterruptHTTPServer() for (evhttp_bound_socket *socket : boundSockets) { evhttp_del_accept_socket(eventHTTP, socket); } - evhttp_set_gencb(eventHTTP, http_reject_request_cb, NULL); + evhttp_set_gencb(eventHTTP, http_reject_request_cb, nullptr); } if (workQueue) workQueue->Interrupt(); @@ -521,7 +521,7 @@ HTTPEvent::~HTTPEvent() } void HTTPEvent::trigger(struct timeval* tv) { - if (tv == NULL) + if (tv == nullptr) event_active(ev, 0, 0); // immediately trigger event in main thread else evtimer_add(ev, tv); // trigger after timeval passed @@ -564,7 +564,7 @@ std::string HTTPRequest::ReadBody() * abstraction to consume the evbuffer on the fly in the parsing algorithm. */ const char* data = (const char*)evbuffer_pullup(buf, size); - if (!data) // returns NULL in case of empty buffer + if (!data) // returns nullptr in case of empty buffer return ""; std::string rv(data, size); evbuffer_drain(buf, size); @@ -673,7 +673,7 @@ void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch) std::string urlDecode(const std::string &urlEncoded) { std::string res; if (!urlEncoded.empty()) { - char *decoded = evhttp_uridecode(urlEncoded.c_str(), false, NULL); + char *decoded = evhttp_uridecode(urlEncoded.c_str(), false, nullptr); if (decoded) { res = std::string(decoded); free(decoded); diff --git a/src/init.cpp b/src/init.cpp index be7c8a1399cb4..cbe3a90a403e0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -91,7 +91,7 @@ std::unique_ptr g_connman; std::unique_ptr peerLogic; #if ENABLE_ZMQ -static CZMQNotificationInterface* pzmqNotificationInterface = NULL; +static CZMQNotificationInterface* pzmqNotificationInterface = nullptr; #endif #ifdef WIN32 @@ -219,7 +219,7 @@ void Shutdown() for (CWalletRef pwallet : vpwallets) { pwallet->Flush(false); } - GenerateBitcoins(false, NULL, 0); + GenerateBitcoins(false, nullptr, 0); #endif StopMapPort(); @@ -273,7 +273,7 @@ void Shutdown() { LOCK(cs_main); - if (pcoinsTip != NULL) { + if (pcoinsTip != nullptr) { FlushStateToDisk(); //record that client took the proper shutdown procedure @@ -802,7 +802,7 @@ bool AppInitBasicSetup() #ifdef _MSC_VER // Turn off Microsoft heap dump noise _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0)); + _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, 0)); #endif #if _MSC_VER >= 1400 // Disable confusing "helpful" text message on abort, Ctrl-C @@ -819,7 +819,7 @@ bool AppInitBasicSetup() #endif typedef BOOL(WINAPI * PSETPROCDEPPOL)(DWORD); PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy"); - if (setProcDEPPol != NULL) setProcDEPPol(PROCESS_DEP_ENABLE); + if (setProcDEPPol != nullptr) setProcDEPPol(PROCESS_DEP_ENABLE); #endif if (!SetupNetworking()) @@ -1065,7 +1065,7 @@ bool AppInitParameterInteraction() else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS) nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS; - setvbuf(stdout, NULL, _IOLBF, 0); /// ***TODO*** do we still need this after -printtoconsole is gone? + setvbuf(stdout, nullptr, _IOLBF, 0); /// ***TODO*** do we still need this after -printtoconsole is gone? #ifndef ENABLE_WALLET if (gArgs.SoftSetBoolArg("-staking", false)) diff --git a/src/libzerocoin/bignum.cpp b/src/libzerocoin/bignum.cpp index def638d367bf5..91f28e4b24c3d 100644 --- a/src/libzerocoin/bignum.cpp +++ b/src/libzerocoin/bignum.cpp @@ -116,7 +116,7 @@ arith_uint256 CBigNum::getuint256() const throw std::range_error("cannot convert to uint256, bignum longer than 256 bits"); } uint256 n = UINT256_ZERO; - mpz_export((unsigned char*)&n, NULL, -1, 1, 0, 0, bn); + mpz_export((unsigned char*)&n, nullptr, -1, 1, 0, 0, bn); return UintToArith256(n); } @@ -176,11 +176,11 @@ bool CBigNum::SetHexBool(const std::string& str) std::string CBigNum::ToString(int nBase) const { - char* c_str = mpz_get_str(NULL, nBase, bn); + char* c_str = mpz_get_str(nullptr, nBase, bn); std::string str(c_str); // Free c_str with the right free function: void (*freefunc)(void *, size_t); - mp_get_memory_functions (NULL, NULL, &freefunc); + mp_get_memory_functions (nullptr, nullptr, &freefunc); freefunc(c_str, strlen(c_str) + 1); return str; diff --git a/src/logging.cpp b/src/logging.cpp index bcf814fe41f3d..932155f5e14e0 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -258,7 +258,7 @@ void BCLog::Logger::ShrinkDebugFile() fwrite(vch.data(), 1, nBytes, file); fclose(file); } - } else if (file != NULL) + } else if (file != nullptr) fclose(file); } diff --git a/src/masternode.cpp b/src/masternode.cpp index caed438d081a5..3d131b2775eb1 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -445,7 +445,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) CMasternode* pmn = mnodeman.Find(vin.prevout); // no such masternode, nothing to update - if (pmn == NULL) return true; + if (pmn == nullptr) return true; // this broadcast is older or equal than the one that we already have - it's bad and should never happen // unless someone is doing something fishy diff --git a/src/masternodeconfig.cpp b/src/masternodeconfig.cpp index 8916269f64738..330d84e0c27f0 100644 --- a/src/masternodeconfig.cpp +++ b/src/masternodeconfig.cpp @@ -41,7 +41,7 @@ bool CMasternodeConfig::read(std::string& strErr) if (!streamConfig.good()) { FILE* configFile = fsbridge::fopen(pathMasternodeConfigFile, "a"); - if (configFile != NULL) { + if (configFile != nullptr) { std::string strHeader = "# Masternode config file\n" "# Format: alias IP:port masternodeprivkey collateral_output_txid collateral_output_index\n" "# Example: mn1 127.0.0.2:51472 93HaYBVUCYjEMeeH1Y4sBGLALQZE1Yc1K64xiqgX37tGBDQL8Xg 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0" diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 72d6ef96dbef3..e4248af9afbfd 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -872,7 +872,7 @@ int CMasternodeMan::ProcessMNPing(CNode* pfrom, CMasternodePing& mnp) // if nothing significant failed, search existing Masternode list CMasternode* pmn = Find(mnp.vin.prevout); // if it's known, don't ask for the mnb, just return - if (pmn != NULL) return 0; + if (pmn != nullptr) return 0; } // something significant is broken or mn is unknown, @@ -1035,7 +1035,7 @@ void CMasternodeMan::UpdateMasternodeList(CMasternodeBroadcast& mnb) LogPrint(BCLog::MASTERNODE,"%s -- masternode=%s\n", __func__, mnb.vin.prevout.ToString()); CMasternode* pmn = Find(mnb.vin.prevout); - if (pmn == NULL) { + if (pmn == nullptr) { CMasternode mn(mnb); Add(mn); } else { diff --git a/src/miner.cpp b/src/miner.cpp index c3e57dc326206..ce42f821a6721 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -284,13 +284,13 @@ void static ThreadBitcoinMiner(void* parg) void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads) { - static boost::thread_group* minerThreads = NULL; + static boost::thread_group* minerThreads = nullptr; fGenerateBitcoins = fGenerate; - if (minerThreads != NULL) { + if (minerThreads != nullptr) { minerThreads->interrupt_all(); delete minerThreads; - minerThreads = NULL; + minerThreads = nullptr; } if (nThreads == 0 || !fGenerate) diff --git a/src/net.cpp b/src/net.cpp index 30f55454f6321..e0671ecc42cbc 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -312,7 +312,7 @@ CNode* CConnman::FindNode(const std::string& addrName) return pnode; } } - return NULL; + return nullptr; } CNode* CConnman::FindNode(const CService& addr) @@ -2088,8 +2088,8 @@ void Discover() // Get local host ip struct ifaddrs* myaddrs; if (getifaddrs(&myaddrs) == 0) { - for (struct ifaddrs* ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) continue; + for (struct ifaddrs* ifa = myaddrs; ifa != nullptr; ifa = ifa->ifa_next) { + if (ifa->ifa_addr == nullptr) continue; if ((ifa->ifa_flags & IFF_UP) == 0) continue; if (strcmp(ifa->ifa_name, "lo") == 0) continue; if (strcmp(ifa->ifa_name, "lo0") == 0) continue; @@ -2236,7 +2236,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions) // Initialize random numbers. Even when rand() is only usable for trivial use-cases most nodes should have a different // seed after all the file-IO done at this point. Should be good enough even when nodes are started via scripts. - srand(time(NULL)); + srand(time(nullptr)); fAddressesInitialized = true; diff --git a/src/net.h b/src/net.h index 64053f8f724f5..21f450909722c 100644 --- a/src/net.h +++ b/src/net.h @@ -525,7 +525,7 @@ bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE); bool RemoveLocal(const CService& addr); bool SeenLocal(const CService& addr); bool IsLocal(const CService& addr); -bool GetLocal(CService& addr, const CNetAddr* paddrPeer = NULL); +bool GetLocal(CService& addr, const CNetAddr* paddrPeer = nullptr); CAddress GetLocalAddress(const CNetAddr* paddrPeer, ServiceFlags nLocalServices); bool validateMasternodeIP(const std::string& addrStr); // valid, reachable and routable address diff --git a/src/netbase.cpp b/src/netbase.cpp index 520f6142313f0..6d4fc8e126ed1 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -115,13 +115,13 @@ bool static LookupIntern(const std::string& name, std::vector& vIP, un #else aiHint.ai_flags = fAllowLookup ? AI_ADDRCONFIG : AI_NUMERICHOST; #endif - struct addrinfo* aiRes = NULL; - int nErr = getaddrinfo(name.c_str(), NULL, &aiHint, &aiRes); + struct addrinfo* aiRes = nullptr; + int nErr = getaddrinfo(name.c_str(), nullptr, &aiHint, &aiRes); if (nErr) return false; struct addrinfo* aiTrav = aiRes; - while (aiTrav != NULL && (nMaxSolutions == 0 || vIP.size() < nMaxSolutions)) { + while (aiTrav != nullptr && (nMaxSolutions == 0 || vIP.size() < nMaxSolutions)) { CNetAddr resolved; if (aiTrav->ai_family == AF_INET) { assert(aiTrav->ai_addrlen >= sizeof(sockaddr_in)); diff --git a/src/pivx-cli.cpp b/src/pivx-cli.cpp index 79bb3108aad6c..233eed3bd7cf0 100644 --- a/src/pivx-cli.cpp +++ b/src/pivx-cli.cpp @@ -163,8 +163,8 @@ static void http_request_done(struct evhttp_request *req, void *ctx) { HTTPReply *reply = static_cast(ctx); - if (req == NULL) { - /* If req is NULL, it means an error occurred while connecting: the + if (req == nullptr) { + /* If req is nullptr, it means an error occurred while connecting: the * error code will have been passed to http_error_cb. */ reply->status = 0; @@ -206,7 +206,7 @@ UniValue CallRPC(const std::string& strMethod, const UniValue& params) HTTPReply response; raii_evhttp_request req = obtain_evhttp_request(http_request_done, (void*)&response); - if (req == NULL) + if (req == nullptr) throw std::runtime_error("create http request failed"); #if LIBEVENT_VERSION_NUMBER >= 0x02010300 evhttp_request_set_error_cb(req.get(), http_error_cb); @@ -356,7 +356,7 @@ int CommandLineRPC(int argc, char* argv[]) strPrint = std::string("error: ") + e.what(); nRet = EXIT_FAILURE; } catch (...) { - PrintExceptionContinue(NULL, "CommandLineRPC()"); + PrintExceptionContinue(nullptr, "CommandLineRPC()"); throw; } @@ -386,7 +386,7 @@ int main(int argc, char* argv[]) PrintExceptionContinue(&e, "AppInitRPC()"); return EXIT_FAILURE; } catch (...) { - PrintExceptionContinue(NULL, "AppInitRPC()"); + PrintExceptionContinue(nullptr, "AppInitRPC()"); return EXIT_FAILURE; } @@ -396,7 +396,7 @@ int main(int argc, char* argv[]) } catch (const std::exception& e) { PrintExceptionContinue(&e, "CommandLineRPC()"); } catch (...) { - PrintExceptionContinue(NULL, "CommandLineRPC()"); + PrintExceptionContinue(nullptr, "CommandLineRPC()"); } return ret; } diff --git a/src/pivx-tx.cpp b/src/pivx-tx.cpp index 7e24c2905877e..3e1c933afc74a 100644 --- a/src/pivx-tx.cpp +++ b/src/pivx-tx.cpp @@ -725,7 +725,7 @@ static int CommandLineRawTx(int argc, char* argv[]) strPrint = std::string("error: ") + e.what(); nRet = EXIT_FAILURE; } catch (...) { - PrintExceptionContinue(NULL, "CommandLineRawTx()"); + PrintExceptionContinue(nullptr, "CommandLineRawTx()"); throw; } @@ -746,7 +746,7 @@ int main(int argc, char* argv[]) PrintExceptionContinue(&e, "AppInitRawTx()"); return EXIT_FAILURE; } catch (...) { - PrintExceptionContinue(NULL, "AppInitRawTx()"); + PrintExceptionContinue(nullptr, "AppInitRawTx()"); return EXIT_FAILURE; } @@ -756,7 +756,7 @@ int main(int argc, char* argv[]) } catch (const std::exception& e) { PrintExceptionContinue(&e, "CommandLineRawTx()"); } catch (...) { - PrintExceptionContinue(NULL, "CommandLineRawTx()"); + PrintExceptionContinue(nullptr, "CommandLineRawTx()"); } return ret; } diff --git a/src/pivxd.cpp b/src/pivxd.cpp index 972ed94ad1c64..b404a00af5cd1 100644 --- a/src/pivxd.cpp +++ b/src/pivxd.cpp @@ -145,7 +145,7 @@ bool AppInit(int argc, char* argv[]) } catch (const std::exception& e) { PrintExceptionContinue(&e, "AppInit()"); } catch (...) { - PrintExceptionContinue(NULL, "AppInit()"); + PrintExceptionContinue(nullptr, "AppInit()"); } if (!fRet) { diff --git a/src/pow.cpp b/src/pow.cpp index 7feb8e88d4bf5..1c9d3f42130a9 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -35,7 +35,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead arith_uint256 PastDifficultyAveragePrev; const arith_uint256& powLimit = UintToArith256(consensus.powLimit); - if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || BlockLastSolved->nHeight < PastBlocksMin) { + if (BlockLastSolved == nullptr || BlockLastSolved->nHeight == 0 || BlockLastSolved->nHeight < PastBlocksMin) { return powLimit.GetCompact(); } @@ -92,7 +92,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } LastBlockTime = BlockReading->GetBlockTime(); - if (BlockReading->pprev == NULL) { + if (BlockReading->pprev == nullptr) { assert(BlockReading); break; } diff --git a/src/prevector.h b/src/prevector.h index 190e63dcf9004..7ca7a4bdd6d44 100644 --- a/src/prevector.h +++ b/src/prevector.h @@ -467,7 +467,7 @@ class prevector { } if (!is_direct()) { free(_union.indirect); - _union.indirect = NULL; + _union.indirect = nullptr; } } diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index 9d51494bd8909..17bcf454876b5 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -261,7 +261,7 @@ void AddressBookPage::on_exportButton_clicked() // CSV is currently the only supported format QString filename = GUIUtil::getSaveFileName(this, tr("Export Address List"), QString(), - tr("Comma separated file (*.csv)"), NULL); + tr("Comma separated file (*.csv)"), nullptr); if (filename.isNull()) return; diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index 5e3edad6ff105..d8362a37f8ee7 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -103,7 +103,7 @@ bool PaymentServer::ipcSendCommandLine() socket->connectToServer(ipcServerName(), QIODevice::WriteOnly); if (!socket->waitForConnected(BITCOIN_IPC_CONNECT_TIMEOUT)) { delete socket; - socket = NULL; + socket = nullptr; return false; } @@ -119,7 +119,7 @@ bool PaymentServer::ipcSendCommandLine() socket->disconnectFromServer(); delete socket; - socket = NULL; + socket = nullptr; fResult = true; } diff --git a/src/qt/pivx/pivxgui.cpp b/src/qt/pivx/pivxgui.cpp index 960661ecaafd4..ff0b12b89b216 100644 --- a/src/qt/pivx/pivxgui.cpp +++ b/src/qt/pivx/pivxgui.cpp @@ -425,7 +425,7 @@ void PIVXGUI::message(const QString& title, const QString& message, unsigned int } else { r = openStandardDialog((title.isEmpty() ? strTitle : title), message, "OK"); } - if (ret != NULL) + if (ret != nullptr) *ret = r; } else if (style & CClientUIInterface::MSG_INFORMATION_SNACK) { messageInfo(message); diff --git a/src/qt/pivx/settings/settingsbackupwallet.cpp b/src/qt/pivx/settings/settingsbackupwallet.cpp index 155c9d191cb08..73a7d49da79d8 100644 --- a/src/qt/pivx/settings/settingsbackupwallet.cpp +++ b/src/qt/pivx/settings/settingsbackupwallet.cpp @@ -48,7 +48,7 @@ void SettingsBackupWallet::selectFileOutput() { QString filename = GUIUtil::getSaveFileName(this, tr("Backup Wallet"), QString(), - tr("Wallet Data (*.dat)"), NULL); + tr("Wallet Data (*.dat)"), nullptr); if (!filename.isEmpty() && walletModel) { ui->pushButtonDocuments->setText(filename); diff --git a/src/qt/pivx/settings/settingsconsolewidget.cpp b/src/qt/pivx/settings/settingsconsolewidget.cpp index af36db72afb5e..3e15497710d5e 100644 --- a/src/qt/pivx/settings/settingsconsolewidget.cpp +++ b/src/qt/pivx/settings/settingsconsolewidget.cpp @@ -45,7 +45,7 @@ const struct { {"cmd-reply", ":/icons/ic-transaction-sent"}, {"cmd-error", ":/icons/ic-transaction-sent"}, {"misc", ":/icons/ic-transaction-staked"}, - {NULL, NULL}}; + {nullptr, nullptr}}; SettingsConsoleWidget::SettingsConsoleWidget(PIVXGUI* _window, QWidget *parent) : PWidget(_window,parent), diff --git a/src/qt/pivx/topbar.cpp b/src/qt/pivx/topbar.cpp index 8129b325fee03..55b7f9f2301a6 100644 --- a/src/qt/pivx/topbar.cpp +++ b/src/qt/pivx/topbar.cpp @@ -725,7 +725,7 @@ void TopBar::updateHDState(const bool upgraded, const QString& upgradeError) // backup wallet QString filename = GUIUtil::getSaveFileName(this, tr("Backup Wallet"), QString(), - tr("Wallet Data (*.dat)"), NULL); + tr("Wallet Data (*.dat)"), nullptr); if (!filename.isEmpty()) { inform(walletModel->backupWallet(filename) ? tr("Backup created") : tr("Backup creation failed")); } else { diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 123227b1f01f9..7a031f350fdf3 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -55,7 +55,7 @@ const struct { {"cmd-reply", ":/icons/tx_output"}, {"cmd-error", ":/icons/tx_output"}, {"misc", ":/icons/tx_inout"}, - {NULL, NULL}}; + {nullptr, nullptr}}; RPCConsole::RPCConsole(QWidget* parent) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint), ui(new Ui::RPCConsole), @@ -652,7 +652,7 @@ void RPCConsole::peerLayoutChanged() if (!clientModel || !clientModel->getPeerTableModel()) return; - const CNodeCombinedStats* stats = NULL; + const CNodeCombinedStats* stats = nullptr; bool fUnselect = false; bool fReselect = false; diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 5721b8bbf170b..0ebd5b0ca121f 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -214,7 +214,7 @@ class WalletModel : public QObject const CWalletTx* getTx(uint256 id); // prepare transaction for getting txfee before sending coins - SendCoinsReturn prepareTransaction(WalletModelTransaction* transaction, const CCoinControl* coinControl = NULL, bool fIncludeDelegations = true); + SendCoinsReturn prepareTransaction(WalletModelTransaction* transaction, const CCoinControl* coinControl = nullptr, bool fIncludeDelegations = true); // Send coins to a list of recipients SendCoinsReturn sendCoins(WalletModelTransaction& transaction); diff --git a/src/qt/winshutdownmonitor.cpp b/src/qt/winshutdownmonitor.cpp index 4112b30055d68..3210730f18a3f 100644 --- a/src/qt/winshutdownmonitor.cpp +++ b/src/qt/winshutdownmonitor.cpp @@ -42,7 +42,7 @@ void WinShutdownMonitor::registerShutdownBlockReason(const QString& strReason, c { typedef BOOL(WINAPI * PSHUTDOWNBRCREATE)(HWND, LPCWSTR); PSHUTDOWNBRCREATE shutdownBRCreate = (PSHUTDOWNBRCREATE)GetProcAddress(GetModuleHandleA("User32.dll"), "ShutdownBlockReasonCreate"); - if (shutdownBRCreate == NULL) { + if (shutdownBRCreate == nullptr) { qWarning() << "registerShutdownBlockReason: GetProcAddress for ShutdownBlockReasonCreate failed"; return; } diff --git a/src/random.cpp b/src/random.cpp index 6a9feaed16a92..6a44b86f2b945 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -279,7 +279,7 @@ void GetOSRand(unsigned char *ent32) { #if defined(WIN32) HCRYPTPROV hProvider; - int ret = CryptAcquireContextW(&hProvider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); + int ret = CryptAcquireContextW(&hProvider, nullptr, nullptr, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); if (!ret) { RandFailure(); } @@ -318,7 +318,7 @@ void GetOSRand(unsigned char *ent32) } #elif defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) // We need a fallback for OSX < 10.12 - if (&getentropy != NULL) { + if (&getentropy != nullptr) { if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) { RandFailure(); } @@ -333,7 +333,7 @@ void GetOSRand(unsigned char *ent32) int have = 0; do { size_t len = NUM_OS_RANDOM_BYTES - have; - if (sysctl(name, ARRAYLEN(name), ent32 + have, &len, NULL, 0) != 0) { + if (sysctl(name, ARRAYLEN(name), ent32 + have, &len, nullptr, 0) != 0) { RandFailure(); } have += len; diff --git a/src/randomenv.cpp b/src/randomenv.cpp index f1c4dcd916872..fa45258d5a5a6 100644 --- a/src/randomenv.cpp +++ b/src/randomenv.cpp @@ -381,10 +381,10 @@ void RandAddStaticEnv(CSHA512& hasher) #if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS // Network interfaces - struct ifaddrs *ifad = NULL; + struct ifaddrs *ifad = nullptr; getifaddrs(&ifad); struct ifaddrs *ifit = ifad; - while (ifit != NULL) { + while (ifit != nullptr) { hasher.Write((const unsigned char*)&ifit, sizeof(ifit)); hasher.Write((const unsigned char*)ifit->ifa_name, strlen(ifit->ifa_name) + 1); hasher.Write((const unsigned char*)&ifit->ifa_flags, sizeof(ifit->ifa_flags)); diff --git a/src/rest.cpp b/src/rest.cpp index a17742397565a..d2d71e1a87307 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -118,7 +118,7 @@ static bool rest_headers(HTTPRequest* req, if (path.size() != 2) return RESTERR(req, HTTP_BAD_REQUEST, "No header count specified. Use /rest/headers//.."); - long count = strtol(path[0].c_str(), NULL, 10); + long count = strtol(path[0].c_str(), nullptr, 10); if (count < 1 || count > 2000) return RESTERR(req, HTTP_BAD_REQUEST, "Header count out of range: " + path[0]); @@ -134,7 +134,7 @@ static bool rest_headers(HTTPRequest* req, LOCK(cs_main); tip = chainActive.Tip(); CBlockIndex* pindex = LookupBlockIndex(hash); - while (pindex != NULL && chainActive.Contains(pindex)) { + while (pindex != nullptr && chainActive.Contains(pindex)) { headers.push_back(pindex); if (headers.size() == (unsigned long)count) break; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 5cdbd85724fde..bf63b9cfce8bc 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -65,7 +65,7 @@ double GetDifficulty(const CBlockIndex* blockindex) { // Floating point number that is a multiple of the minimum difficulty, // minimum difficulty = 1.0. - if (blockindex == NULL) { + if (blockindex == nullptr) { const CBlockIndex* pChainTip = GetChainTip(); if (!pChainTip) return 1.0; diff --git a/src/rpc/budget.cpp b/src/rpc/budget.cpp index 4f6c84f46e122..c1b2323871350 100644 --- a/src/rpc/budget.cpp +++ b/src/rpc/budget.cpp @@ -331,7 +331,7 @@ UniValue getbudgetvotes(const JSONRPCRequest& request) std::string strProposalName = SanitizeString(request.params[0].get_str()); const CBudgetProposal* pbudgetProposal = g_budgetman.FindProposalByName(strProposalName); - if (pbudgetProposal == NULL) throw std::runtime_error("Unknown proposal name"); + if (pbudgetProposal == nullptr) throw std::runtime_error("Unknown proposal name"); return pbudgetProposal->GetVotesArray(); } @@ -455,7 +455,7 @@ UniValue getbudgetinfo(const JSONRPCRequest& request) if (request.params.size() == 1) { std::string strProposalName = SanitizeString(request.params[0].get_str()); const CBudgetProposal* pbudgetProposal = g_budgetman.FindProposalByName(strProposalName); - if (pbudgetProposal == NULL) throw std::runtime_error("Unknown proposal name"); + if (pbudgetProposal == nullptr) throw std::runtime_error("Unknown proposal name"); UniValue bObj(UniValue::VOBJ); budgetToJSON(pbudgetProposal, bObj, nCurrentHeight); ret.push_back(bObj); @@ -704,7 +704,7 @@ UniValue mnfinalbudget(const JSONRPCRequest& request) LOCK(g_budgetman.cs_budgets); CFinalizedBudget* pfinalBudget = g_budgetman.FindFinalizedBudget(hash); - if (pfinalBudget == NULL) return "Unknown budget hash"; + if (pfinalBudget == nullptr) return "Unknown budget hash"; return pfinalBudget->GetVotesObject(); } diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 30ea019adab46..dbf02b067e5fb 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -357,7 +357,7 @@ bool StartMasternodeEntry(UniValue& statusObjRet, CMasternodeBroadcast& mnbRet, CTxIn vin = CTxIn(uint256S(mne.getTxHash()), uint32_t(nIndex)); CMasternode* pmn = mnodeman.Find(vin.prevout); - if (pmn != NULL) { + if (pmn != nullptr) { if (strCommand == "missing") return false; if (strCommand == "disabled" && pmn->IsEnabled()) return false; } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 061561072990d..4ce1dadd78227 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -211,7 +211,7 @@ UniValue GetNetworkHashPS(int lookup, int height) if (height >= 0 && height < chainActive.Height()) pb = chainActive[height]; - if (pb == NULL || !pb->nHeight) + if (pb == nullptr || !pb->nHeight) return 0; // If lookup is -1, then use blocks since last difficulty change. @@ -630,7 +630,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) if (pindexPrev != chainActive.Tip() || (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5)) { // Clear pindexPrev so future calls make a new block, despite any failures from here on - pindexPrev = NULL; + pindexPrev = nullptr; // Store the chainActive.Tip() used before CreateNewBlock, to avoid races nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); @@ -640,7 +640,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) // Create new block if (pblocktemplate) { pblocktemplate.release(); - pblocktemplate = NULL; + pblocktemplate = nullptr; } CScript scriptDummy = CScript() << OP_TRUE; pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptDummy, pwallet, false); diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 14098ff241ec1..52766bef8e5d1 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -87,7 +87,7 @@ UniValue getinfo(const JSONRPCRequest& request) HelpExampleCli("getinfo", "") + HelpExampleRpc("getinfo", "")); #ifdef ENABLE_WALLET - LOCK2(cs_main, pwallet ? &pwallet->cs_wallet : NULL); + LOCK2(cs_main, pwallet ? &pwallet->cs_wallet : nullptr); #else LOCK(cs_main); #endif diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 2c8e12a5d8d41..ff0b964b845c2 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -222,7 +222,7 @@ UniValue addnode(const JSONRPCRequest& request) if (strCommand == "onetry") { CAddress addr; - g_connman->OpenNetworkConnection(addr, false, NULL, strNode.c_str()); + g_connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str()); return NullUniValue; } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index cac51d7774507..ad6b399a15ac7 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -564,7 +564,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request) HelpExampleCli("signrawtransaction", "\"myhex\"") + HelpExampleRpc("signrawtransaction", "\"myhex\"")); #ifdef ENABLE_WALLET - LOCK2(cs_main, pwallet ? &pwallet->cs_wallet : NULL); + LOCK2(cs_main, pwallet ? &pwallet->cs_wallet : nullptr); #else LOCK(cs_main); #endif diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 5c8dcc8932d7e..af7e3aa6ce27a 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -34,7 +34,7 @@ static std::string rpcWarmupStatus("RPC server started"); static RecursiveMutex cs_rpcWarmup; /* Timer-creating functions */ -static RPCTimerInterface* timerInterface = NULL; +static RPCTimerInterface* timerInterface = nullptr; /* Map of name to timer. */ static std::map> deadlineTimers; @@ -301,7 +301,7 @@ const CRPCCommand *CRPCTable::operator[](const std::string &name) const { std::map::const_iterator it = mapCommands.find(name); if (it == mapCommands.end()) - return NULL; + return nullptr; return (*it).second; } @@ -544,7 +544,7 @@ void RPCSetTimerInterface(RPCTimerInterface *iface) void RPCUnsetTimerInterface(RPCTimerInterface *iface) { if (timerInterface == iface) - timerInterface = NULL; + timerInterface = nullptr; } void RPCRunLater(const std::string& name, std::function func, int64_t nSeconds) diff --git a/src/rpc/server.h b/src/rpc/server.h index acbb54e5effca..7bd59152bdcee 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -193,7 +193,7 @@ extern double ParseDoubleV(const UniValue& v, const std::string &strName); extern CAmount AmountFromValue(const UniValue& value); extern UniValue ValueFromAmount(const CAmount& amount); -extern double GetDifficulty(const CBlockIndex* blockindex = NULL); +extern double GetDifficulty(const CBlockIndex* blockindex = nullptr); extern std::string HelpExampleCli(std::string methodname, std::string args); extern std::string HelpExampleRpc(std::string methodname, std::string args); diff --git a/src/sapling/noteencryption.cpp b/src/sapling/noteencryption.cpp index 22994fa5455b9..5094317d4f15f 100644 --- a/src/sapling/noteencryption.cpp +++ b/src/sapling/noteencryption.cpp @@ -41,8 +41,8 @@ void PRF_ock( if (crypto_generichash_blake2b_salt_personal(K, NOTEENCRYPTION_CIPHER_KEYSIZE, block, 128, - NULL, 0, // No key. - NULL, // No salt. + nullptr, 0, // No key. + nullptr, // No salt. personalization ) != 0) { @@ -65,8 +65,8 @@ void KDF_Sapling( if (crypto_generichash_blake2b_salt_personal(K, NOTEENCRYPTION_CIPHER_KEYSIZE, block, 64, - NULL, 0, // No key. - NULL, // No salt. + nullptr, 0, // No key. + nullptr, // No salt. personalization ) != 0) { @@ -98,8 +98,8 @@ void KDF(unsigned char K[NOTEENCRYPTION_CIPHER_KEYSIZE], if (crypto_generichash_blake2b_salt_personal(K, NOTEENCRYPTION_CIPHER_KEYSIZE, block, 128, - NULL, 0, // No key. - NULL, // No salt. + nullptr, 0, // No key. + nullptr, // No salt. personalization ) != 0) { @@ -149,10 +149,10 @@ Optional SaplingNoteEncryption::encrypt_to_recipient( SaplingEncCiphertext ciphertext; crypto_aead_chacha20poly1305_ietf_encrypt( - ciphertext.begin(), NULL, + ciphertext.begin(), nullptr, message.begin(), ZC_SAPLING_ENCPLAINTEXT_SIZE, - NULL, 0, // no "additional data" - NULL, cipher_nonce, K + nullptr, 0, // no "additional data" + nullptr, cipher_nonce, K ); already_encrypted_enc = true; @@ -182,10 +182,10 @@ Optional AttemptSaplingEncDecryption( SaplingEncPlaintext plaintext; if (crypto_aead_chacha20poly1305_ietf_decrypt( - plaintext.begin(), NULL, - NULL, + plaintext.begin(), nullptr, + nullptr, ciphertext.begin(), ZC_SAPLING_ENCCIPHERTEXT_SIZE, - NULL, + nullptr, 0, cipher_nonce, K) != 0) { @@ -218,10 +218,10 @@ Optional AttemptSaplingEncDecryption ( SaplingEncPlaintext plaintext; if (crypto_aead_chacha20poly1305_ietf_decrypt( - plaintext.begin(), NULL, - NULL, + plaintext.begin(), nullptr, + nullptr, ciphertext.begin(), ZC_SAPLING_ENCCIPHERTEXT_SIZE, - NULL, + nullptr, 0, cipher_nonce, K) != 0) { @@ -253,10 +253,10 @@ SaplingOutCiphertext SaplingNoteEncryption::encrypt_to_ourselves( SaplingOutCiphertext ciphertext; crypto_aead_chacha20poly1305_ietf_encrypt( - ciphertext.begin(), NULL, + ciphertext.begin(), nullptr, message.begin(), ZC_SAPLING_OUTPLAINTEXT_SIZE, - NULL, 0, // no "additional data" - NULL, cipher_nonce, K + nullptr, 0, // no "additional data" + nullptr, cipher_nonce, K ); already_encrypted_out = true; @@ -282,10 +282,10 @@ Optional AttemptSaplingOutDecryption( SaplingOutPlaintext plaintext; if (crypto_aead_chacha20poly1305_ietf_decrypt( - plaintext.begin(), NULL, - NULL, + plaintext.begin(), nullptr, + nullptr, ciphertext.begin(), ZC_SAPLING_OUTCIPHERTEXT_SIZE, - NULL, + nullptr, 0, cipher_nonce, K) != 0) { diff --git a/src/sapling/zip32.cpp b/src/sapling/zip32.cpp index 6110098c0b97d..f53bc1738ff62 100644 --- a/src/sapling/zip32.cpp +++ b/src/sapling/zip32.cpp @@ -42,9 +42,9 @@ uint256 ovkForShieldingFromTaddr(HDSeed& seed) { crypto_generichash_blake2b_state state; assert(crypto_generichash_blake2b_init_salt_personal( &state, - NULL, 0, // No key. + nullptr, 0, // No key. 64, - NULL, // No salt. + nullptr, // No salt. PIVX_TADDR_OVK_PERSONAL) == 0); crypto_generichash_blake2b_update(&state, rawSeed.data(), rawSeed.size()); auto intermediate = std::array(); diff --git a/src/script/bitcoinconsensus.cpp b/src/script/bitcoinconsensus.cpp index 4cfd698b31361..1e64b82385b2c 100644 --- a/src/script/bitcoinconsensus.cpp +++ b/src/script/bitcoinconsensus.cpp @@ -28,10 +28,10 @@ class TxInputStream if (nSize > m_remaining) throw std::ios_base::failure(std::string(__func__) + ": end of data"); - if (pch == NULL) + if (pch == nullptr) throw std::ios_base::failure(std::string(__func__) + ": bad destination buffer"); - if (m_data == NULL) + if (m_data == nullptr) throw std::ios_base::failure(std::string(__func__) + ": bad source buffer"); memcpy(pch, m_data, nSize); @@ -88,7 +88,7 @@ int bitcoinconsensus_verify_script(const unsigned char *scriptPubKey, unsigned i set_error(err, bitcoinconsensus_ERR_OK); return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), - flags, TransactionSignatureChecker(&tx, nIn), tx.GetRequiredSigVersion(), NULL); + flags, TransactionSignatureChecker(&tx, nIn), tx.GetRequiredSigVersion(), nullptr); } catch (const std::exception&) { return set_error(err, bitcoinconsensus_ERR_TX_DESERIALIZE); // Error deserializing } diff --git a/src/script/bitcoinconsensus.h b/src/script/bitcoinconsensus.h index 8bfc23fb20e71..f7e34cf6787b1 100644 --- a/src/script/bitcoinconsensus.h +++ b/src/script/bitcoinconsensus.h @@ -52,7 +52,7 @@ enum /// Returns 1 if the input nIn of the serialized transaction pointed to by /// txTo correctly spends the scriptPubKey pointed to by scriptPubKey under /// the additional constraints specified by flags. -/// If not NULL, err will contain an error/success code for the operation +/// If not nullptr, err will contain an error/success code for the operation EXPORT_SYMBOL int bitcoinconsensus_verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, const unsigned char *txTo , unsigned int txToLen, unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err); diff --git a/src/script/interpreter.h b/src/script/interpreter.h index 2d53a30e0336e..b69b8ea9471fc 100644 --- a/src/script/interpreter.h +++ b/src/script/interpreter.h @@ -144,7 +144,7 @@ class MutableTransactionSignatureChecker : public TransactionSignatureChecker MutableTransactionSignatureChecker(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amount) : TransactionSignatureChecker(&txTo, nInIn, amount), txTo(*txToIn) {} }; -bool EvalScript(std::vector >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* error = NULL); -bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror = NULL); +bool EvalScript(std::vector >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* error = nullptr); +bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror = nullptr); #endif // BITCOIN_SCRIPT_INTERPRETER_H diff --git a/src/script/script.h b/src/script/script.h index 621281c18a8f5..85d1b32ad0f39 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -491,7 +491,7 @@ class CScript : public CScriptBase bool GetOp(iterator& pc, opcodetype& opcodeRet) { const_iterator pc2 = pc; - bool fRet = GetOp2(pc2, opcodeRet, NULL); + bool fRet = GetOp2(pc2, opcodeRet, nullptr); pc = begin() + (pc2 - begin()); return fRet; } @@ -503,7 +503,7 @@ class CScript : public CScriptBase bool GetOp(const_iterator& pc, opcodetype& opcodeRet) const { - return GetOp2(pc, opcodeRet, NULL); + return GetOp2(pc, opcodeRet, nullptr); } bool GetOp2(const_iterator& pc, opcodetype& opcodeRet, std::vector* pvchRet) const diff --git a/src/script/standard.cpp b/src/script/standard.cpp index 1502f2d58bc85..6352ee5258e33 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -27,7 +27,7 @@ const char* GetTxnOutputType(txnouttype t) case TX_COLDSTAKE: return "coldstake"; case TX_NULL_DATA: return "nulldata"; } - return NULL; + return nullptr; } static bool MatchPayToPubkey(const CScript& script, valtype& pubkey) diff --git a/src/streams.h b/src/streams.h index b5694d9191435..2a11aafacd9ea 100644 --- a/src/streams.h +++ b/src/streams.h @@ -475,7 +475,7 @@ class CAutoFile { if (file) { ::fclose(file); - file = NULL; + file = nullptr; } } @@ -486,7 +486,7 @@ class CAutoFile FILE* release() { FILE* ret = file; - file = NULL; + file = nullptr; return ret; } @@ -496,9 +496,9 @@ class CAutoFile */ FILE* Get() const { return file; } - /** Return true if the wrapped FILE* is NULL, false otherwise. + /** Return true if the wrapped FILE* is nullptr, false otherwise. */ - bool IsNull() const { return (file == NULL); } + bool IsNull() const { return (file == nullptr); } // // Stream subset @@ -509,7 +509,7 @@ class CAutoFile void read(char* pch, size_t nSize) { if (!file) - throw std::ios_base::failure("CAutoFile::read : file handle is NULL"); + throw std::ios_base::failure("CAutoFile::read : file handle is nullptr"); if (fread(pch, 1, nSize, file) != nSize) throw std::ios_base::failure(feof(file) ? "CAutoFile::read : end of file" : "CAutoFile::read : fread failed"); } @@ -517,7 +517,7 @@ class CAutoFile void ignore(size_t nSize) { if (!file) - throw std::ios_base::failure("CAutoFile::ignore: file handle is NULL"); + throw std::ios_base::failure("CAutoFile::ignore: file handle is nullptr"); unsigned char data[4096]; while (nSize > 0) { size_t nNow = std::min(nSize, sizeof(data)); @@ -531,7 +531,7 @@ class CAutoFile void write(const char* pch, size_t nSize) { if (!file) - throw std::ios_base::failure("CAutoFile::write : file handle is NULL"); + throw std::ios_base::failure("CAutoFile::write : file handle is nullptr"); if (fwrite(pch, 1, nSize, file) != nSize) throw std::ios_base::failure("CAutoFile::write : write failed"); } @@ -541,7 +541,7 @@ class CAutoFile { // Serialize to this stream if (!file) - throw std::ios_base::failure("CAutoFile::operator<< : file handle is NULL"); + throw std::ios_base::failure("CAutoFile::operator<< : file handle is nullptr"); ::Serialize(*this, obj); return (*this); } @@ -551,7 +551,7 @@ class CAutoFile { // Unserialize from this stream if (!file) - throw std::ios_base::failure("CAutoFile::operator>> : file handle is NULL"); + throw std::ios_base::failure("CAutoFile::operator>> : file handle is nullptr"); ::Unserialize(*this, obj); return (*this); } @@ -620,7 +620,7 @@ class CBufferedFile { if (src) { ::fclose(src); - src = NULL; + src = nullptr; } } diff --git a/src/support/events.h b/src/support/events.h index 90690876eee05..cc6d29aecdce6 100644 --- a/src/support/events.h +++ b/src/support/events.h @@ -47,7 +47,7 @@ inline raii_evhttp_request obtain_evhttp_request(void(*cb)(struct evhttp_request } inline raii_evhttp_connection obtain_evhttp_connection_base(struct event_base* base, std::string host, uint16_t port) { - auto result = raii_evhttp_connection(evhttp_connection_base_new(base, NULL, host.c_str(), port)); + auto result = raii_evhttp_connection(evhttp_connection_base_new(base, nullptr, host.c_str(), port)); if (!result.get()) throw std::runtime_error("create connection failed"); return result; diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp index 37ac92c809203..713f41029828a 100644 --- a/src/test/addrman_tests.cpp +++ b/src/test/addrman_tests.cpp @@ -379,7 +379,7 @@ BOOST_AUTO_TEST_CASE(addrman_delete) addrman.Delete(nId); BOOST_CHECK(addrman.size() == 0); CAddrInfo* info2 = addrman.Find(addr1); - BOOST_CHECK(info2 == NULL); + BOOST_CHECK(info2 == nullptr); } BOOST_AUTO_TEST_CASE(addrman_getaddr) diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp index df1c6de5b1c36..d00f0059a8301 100644 --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -18,7 +18,7 @@ UniValue -createArgs(int nRequired, const char* address1=NULL, const char* address2=NULL) +createArgs(int nRequired, const char* address1=nullptr, const char* address2=nullptr) { UniValue result(UniValue::VARR); result.push_back(nRequired); diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index e3fc8b61ed3df..2f2e0beffaaf7 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -151,7 +151,7 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, int flags, co #if defined(HAVE_CONSENSUS_LIB) CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); stream << tx2; - BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), 0, flags, NULL) == expect,message); + BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), 0, flags, nullptr) == expect,message); #endif } diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 26e8a26ec860a..d3c9856abe9db 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -758,7 +758,7 @@ BOOST_AUTO_TEST_CASE(test_ParseInt32) { int32_t n; // Valid values - BOOST_CHECK(ParseInt32("1234", NULL)); + BOOST_CHECK(ParseInt32("1234", nullptr)); BOOST_CHECK(ParseInt32("0", &n) && n == 0); BOOST_CHECK(ParseInt32("1234", &n) && n == 1234); BOOST_CHECK(ParseInt32("01234", &n) && n == 1234); // no octal @@ -777,17 +777,17 @@ BOOST_AUTO_TEST_CASE(test_ParseInt32) std::string teststr(test_bytes, sizeof(test_bytes)); BOOST_CHECK(!ParseInt32(teststr, &n)); // no embedded NULs // Overflow and underflow - BOOST_CHECK(!ParseInt32("-2147483649", NULL)); - BOOST_CHECK(!ParseInt32("2147483648", NULL)); - BOOST_CHECK(!ParseInt32("-32482348723847471234", NULL)); - BOOST_CHECK(!ParseInt32("32482348723847471234", NULL)); + BOOST_CHECK(!ParseInt32("-2147483649", nullptr)); + BOOST_CHECK(!ParseInt32("2147483648", nullptr)); + BOOST_CHECK(!ParseInt32("-32482348723847471234", nullptr)); + BOOST_CHECK(!ParseInt32("32482348723847471234", nullptr)); } BOOST_AUTO_TEST_CASE(test_ParseInt64) { int64_t n; // Valid values - BOOST_CHECK(ParseInt64("1234", NULL)); + BOOST_CHECK(ParseInt64("1234", nullptr)); BOOST_CHECK(ParseInt64("0", &n) && n == 0LL); BOOST_CHECK(ParseInt64("1234", &n) && n == 1234LL); BOOST_CHECK(ParseInt64("01234", &n) && n == 1234LL); // no octal @@ -807,17 +807,17 @@ BOOST_AUTO_TEST_CASE(test_ParseInt64) std::string teststr(test_bytes, sizeof(test_bytes)); BOOST_CHECK(!ParseInt64(teststr, &n)); // no embedded NULs // Overflow and underflow - BOOST_CHECK(!ParseInt64("-9223372036854775809", NULL)); - BOOST_CHECK(!ParseInt64("9223372036854775808", NULL)); - BOOST_CHECK(!ParseInt64("-32482348723847471234", NULL)); - BOOST_CHECK(!ParseInt64("32482348723847471234", NULL)); + BOOST_CHECK(!ParseInt64("-9223372036854775809", nullptr)); + BOOST_CHECK(!ParseInt64("9223372036854775808", nullptr)); + BOOST_CHECK(!ParseInt64("-32482348723847471234", nullptr)); + BOOST_CHECK(!ParseInt64("32482348723847471234", nullptr)); } BOOST_AUTO_TEST_CASE(test_ParseDouble) { double n; // Valid values - BOOST_CHECK(ParseDouble("1234", NULL)); + BOOST_CHECK(ParseDouble("1234", nullptr)); BOOST_CHECK(ParseDouble("0", &n) && n == 0.0); BOOST_CHECK(ParseDouble("1234", &n) && n == 1234.0); BOOST_CHECK(ParseDouble("01234", &n) && n == 1234.0); // no octal @@ -837,8 +837,8 @@ BOOST_AUTO_TEST_CASE(test_ParseDouble) std::string teststr(test_bytes, sizeof(test_bytes)); BOOST_CHECK(!ParseDouble(teststr, &n)); // no embedded NULs // Overflow and underflow - BOOST_CHECK(!ParseDouble("-1e10000", NULL)); - BOOST_CHECK(!ParseDouble("1e10000", NULL)); + BOOST_CHECK(!ParseDouble("-1e10000", nullptr)); + BOOST_CHECK(!ParseDouble("1e10000", nullptr)); } BOOST_AUTO_TEST_CASE(test_FormatParagraph) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 938c80a50d387..6da7cbebb2993 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -993,7 +993,7 @@ void CTxMemPool::check(const CCoinsViewCache* pcoins) const else { CValidationState state; PrecomputedTransactionData precomTxData(tx); - assert(CheckInputs(tx, state, mempoolDuplicate, false, 0, false, precomTxData, NULL)); + assert(CheckInputs(tx, state, mempoolDuplicate, false, 0, false, precomTxData, nullptr)); UpdateCoins(tx, mempoolDuplicate, 1000000); } } @@ -1009,7 +1009,7 @@ void CTxMemPool::check(const CCoinsViewCache* pcoins) const assert(stepsSinceLastRemove < waitingOnDependants.size()); } else { PrecomputedTransactionData precomTxData(entry->GetTx()); - assert(CheckInputs(entry->GetTx(), state, mempoolDuplicate, false, 0, false, precomTxData, NULL)); + assert(CheckInputs(entry->GetTx(), state, mempoolDuplicate, false, 0, false, precomTxData, nullptr)); UpdateCoins(entry->GetTx(), mempoolDuplicate, 1000000); stepsSinceLastRemove = 0; } diff --git a/src/txmempool.h b/src/txmempool.h index 65cc8e6b2d3cd..a7c9a4ec93e39 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -661,7 +661,7 @@ class CTxMemPool * If no answer can be given at nBlocks, return an estimate * at the lowest number of blocks where one can be given */ - CFeeRate estimateSmartFee(int nBlocks, int *answerFoundAtBlocks = NULL) const; + CFeeRate estimateSmartFee(int nBlocks, int *answerFoundAtBlocks = nullptr) const; /** Estimate fee rate needed to get into the next nBlocks */ CFeeRate estimateFee(int nBlocks) const; diff --git a/src/util/system.cpp b/src/util/system.cpp index 47b231f1804cc..67e9256eee07a 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -511,7 +511,7 @@ static std::string FormatException(const std::exception* pex, const char* pszThr { #ifdef WIN32 char pszModule[MAX_PATH] = ""; - GetModuleFileNameA(NULL, pszModule, sizeof(pszModule)); + GetModuleFileNameA(nullptr, pszModule, sizeof(pszModule)); #else const char* pszModule = "pivx"; #endif @@ -542,7 +542,7 @@ fs::path GetDefaultDataDir() #else fs::path pathRet; char* pszHome = getenv("HOME"); - if (pszHome == NULL || strlen(pszHome) == 0) + if (pszHome == nullptr || strlen(pszHome) == 0) pathRet = fs::path("/"); else pathRet = fs::path(pszHome); @@ -577,7 +577,7 @@ static fs::path ZC_GetBaseParamsDir() #else fs::path pathRet; char* pszHome = getenv("HOME"); - if (pszHome == NULL || strlen(pszHome) == 0) + if (pszHome == nullptr || strlen(pszHome) == 0) pathRet = fs::path("/"); else pathRet = fs::path(pszHome); diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index 84885f639b39f..567aaf54dc252 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -279,7 +279,7 @@ bool ParseInt32(const std::string& str, int32_t *out) { if (!ParsePrechecks(str)) return false; - char *endp = NULL; + char *endp = nullptr; errno = 0; // strtol will not set errno if valid long int n = strtol(str.c_str(), &endp, 10); if(out) *out = (int32_t)n; @@ -295,7 +295,7 @@ bool ParseInt64(const std::string& str, int64_t *out) { if (!ParsePrechecks(str)) return false; - char *endp = NULL; + char *endp = nullptr; errno = 0; // strtoll will not set errno if valid long long int n = strtoll(str.c_str(), &endp, 10); if(out) *out = (int64_t)n; @@ -396,7 +396,7 @@ int64_t atoi64(const char* psz) #ifdef _MSC_VER return _atoi64(psz); #else - return strtoll(psz, NULL, 10); + return strtoll(psz, nullptr, 10); #endif } @@ -405,7 +405,7 @@ int64_t atoi64(const std::string& str) #ifdef _MSC_VER return _atoi64(str.c_str()); #else - return strtoll(str.c_str(), NULL, 10); + return strtoll(str.c_str(), nullptr, 10); #endif } diff --git a/src/utilstrencodings.h b/src/utilstrencodings.h index 6300f20aa4800..344e32935bc32 100644 --- a/src/utilstrencodings.h +++ b/src/utilstrencodings.h @@ -56,11 +56,11 @@ std::vector ParseHex(const char* psz); std::vector ParseHex(const std::string& str); signed char HexDigit(char c); bool IsHex(const std::string& str); -std::vector DecodeBase64(const char* p, bool* pfInvalid = NULL); +std::vector DecodeBase64(const char* p, bool* pfInvalid = nullptr); std::string DecodeBase64(const std::string& str); std::string EncodeBase64(Span input); std::string EncodeBase64(const std::string& str); -std::vector DecodeBase32(const char* p, bool* pfInvalid = NULL); +std::vector DecodeBase32(const char* p, bool* pfInvalid = nullptr); std::string DecodeBase32(const std::string& str); /** diff --git a/src/validation.cpp b/src/validation.cpp index 20399aa5308f3..87d8a03379388 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -80,7 +80,7 @@ RecursiveMutex cs_main; BlockMap mapBlockIndex; CChain chainActive; -CBlockIndex* pindexBestHeader = NULL; +CBlockIndex* pindexBestHeader = nullptr; // Best block section Mutex g_best_block_mutex; @@ -873,7 +873,7 @@ bool IsInitialBlockDownload() return state; } -CBlockIndex *pindexBestForkTip = NULL, *pindexBestForkBase = NULL; +CBlockIndex *pindexBestForkTip = nullptr, *pindexBestForkBase = nullptr; static void AlertNotify(const std::string& strMessage) { @@ -1431,7 +1431,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd } // verify that the view's current state corresponds to the previous block - uint256 hashPrevBlock = pindex->pprev == NULL ? UINT256_ZERO : pindex->pprev->GetBlockHash(); + uint256 hashPrevBlock = pindex->pprev == nullptr ? UINT256_ZERO : pindex->pprev->GetBlockHash(); if (hashPrevBlock != view.GetBestBlock()) LogPrintf("%s: hashPrev=%s view=%s\n", __func__, hashPrevBlock.GetHex(), view.GetBestBlock().GetHex()); assert(hashPrevBlock == view.GetBestBlock()); @@ -1572,7 +1572,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; bool fCacheResults = fJustCheck; /* Don't cache results if we're actually connecting blocks (still consult the cache, though) */ - if (!CheckInputs(tx, state, view, fScriptChecks, flags, fCacheResults, precomTxData[i], nScriptCheckThreads ? &vChecks : NULL)) + if (!CheckInputs(tx, state, view, fScriptChecks, flags, fCacheResults, precomTxData[i], nScriptCheckThreads ? &vChecks : nullptr)) return error("%s: Check inputs on %s failed with %s", __func__, tx.GetHash().ToString(), FormatStateMessage(state)); control.Add(vChecks); } @@ -1864,7 +1864,7 @@ void static UpdateTip(CBlockIndex* pindexNew) if (!IsInitialBlockDownload() && !fWarned) { int nUpgraded = 0; const CBlockIndex* pindex = pChainTip; - for (int i = 0; i < 100 && pindex != NULL; i++) { + for (int i = 0; i < 100 && pindex != nullptr; i++) { if (pindex->nVersion > CBlock::CURRENT_VERSION) ++nUpgraded; pindex = pindex->pprev; @@ -1888,7 +1888,7 @@ void static UpdateTip(CBlockIndex* pindexNew) * should make the mempool consistent again by calling UpdateMempoolForReorg. * with cs_main held. * - * If disconnectpool is NULL, then no disconnected transactions are added to + * If disconnectpool is nullptr, then no disconnected transactions are added to * disconnectpool (note that the caller is responsible for mempool consistency * in any case). */ @@ -2007,7 +2007,7 @@ class ConnectTrace { }; /** - * Connect a new block to chainActive. pblock is either NULL or a pointer to a CBlock + * Connect a new block to chainActive. pblock is either nullptr or a pointer to a CBlock * corresponding to pindexNew, to bypass loading it again from disk. * * The block is added to connectTrace if connection succeeds. @@ -2098,13 +2098,13 @@ bool static ConnectTip(CValidationState& state, CBlockIndex* pindexNew, const st static CBlockIndex* FindMostWorkChain() { do { - CBlockIndex* pindexNew = NULL; + CBlockIndex* pindexNew = nullptr; // Find the best candidate header. { std::set::reverse_iterator it = setBlockIndexCandidates.rbegin(); if (it == setBlockIndexCandidates.rend()) - return NULL; + return nullptr; pindexNew = *it; } @@ -2123,7 +2123,7 @@ static CBlockIndex* FindMostWorkChain() bool fMissingData = !(pindexTest->nStatus & BLOCK_HAVE_DATA); if (fFailedChain || fMissingData) { // Candidate chain is not usable (either invalid or missing data) - if (fFailedChain && (pindexBestInvalid == NULL || pindexNew->nChainWork > pindexBestInvalid->nChainWork)) + if (fFailedChain && (pindexBestInvalid == nullptr || pindexNew->nChainWork > pindexBestInvalid->nChainWork)) pindexBestInvalid = pindexNew; CBlockIndex* pindexFailed = pindexNew; // Remove the entire chain from the set. @@ -2165,7 +2165,7 @@ static void PruneBlockIndexCandidates() /** * Try to make some progress towards making pindexMostWork the active block. - * pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork. + * pblock is either nullptr or a pointer to a CBlock corresponding to pindexMostWork. */ static bool ActivateBestChainStep(CValidationState& state, CBlockIndex* pindexMostWork, const std::shared_ptr& pblock, bool& fInvalidFound, ConnectTrace& connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { @@ -2256,7 +2256,7 @@ static bool ActivateBestChainStep(CValidationState& state, CBlockIndex* pindexMo /** * Make the best chain active, in multiple steps. The result is either failure - * or an activated best chain. pblock is either NULL or a pointer to a block + * or an activated best chain. pblock is either nullptr or a pointer to a block * that is already loaded (to avoid loading it again from disk). */ @@ -2416,14 +2416,14 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex* pindex) } if (it->second == pindexBestInvalid) { // Reset invalid block marker if it was pointing to one of those. - pindexBestInvalid = NULL; + pindexBestInvalid = nullptr; } } it++; } // Remove the invalidity flag from all ancestors too. - while (pindex != NULL) { + while (pindex != nullptr) { if (pindex->nStatus & BLOCK_FAILED_MASK) { pindex->nStatus &= ~BLOCK_FAILED_MASK; setDirtyBlockIndex.insert(pindex); @@ -2471,7 +2471,7 @@ static CBlockIndex* AddToBlockIndex(const CBlock& block) EXCLUSIVE_LOCKS_REQUIRE pindexNew->nTimeMax = (pindexNew->pprev ? std::max(pindexNew->pprev->nTimeMax, pindexNew->nTime) : pindexNew->nTime); pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew); pindexNew->RaiseValidity(BLOCK_VALID_TREE); - if (pindexBestHeader == NULL || pindexBestHeader->nChainWork < pindexNew->nChainWork) + if (pindexBestHeader == nullptr || pindexBestHeader->nChainWork < pindexNew->nChainWork) pindexBestHeader = pindexNew; setDirtyBlockIndex.insert(pindexNew); @@ -2508,7 +2508,7 @@ bool ReceivedBlockTransactions(const CBlock& block, CValidationState& state, CBl pindexNew->RaiseValidity(BLOCK_VALID_TRANSACTIONS); setDirtyBlockIndex.insert(pindexNew); - if (pindexNew->pprev == NULL || pindexNew->pprev->nChainTx) { + if (pindexNew->pprev == nullptr || pindexNew->pprev->nChainTx) { // If pindexNew is the genesis block or all parents are BLOCK_VALID_TRANSACTIONS. std::deque queue; queue.push_back(pindexNew); @@ -2526,7 +2526,7 @@ bool ReceivedBlockTransactions(const CBlock& block, CValidationState& state, CBl LOCK(cs_nBlockSequenceId); pindex->nSequenceId = nBlockSequenceId++; } - if (chainActive.Tip() == NULL || !setBlockIndexCandidates.value_comp()(pindex, chainActive.Tip())) { + if (chainActive.Tip() == nullptr || !setBlockIndexCandidates.value_comp()(pindex, chainActive.Tip())) { setBlockIndexCandidates.insert(pindex); } std::pair::iterator, std::multimap::iterator> range = mapBlocksUnlinked.equal_range(pindex); @@ -2811,7 +2811,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo bool CheckWork(const CBlock& block, const CBlockIndex* const pindexPrev) { - if (pindexPrev == NULL) + if (pindexPrev == nullptr) return error("%s : null pindexPrev for block %s", __func__, block.GetHash().GetHex()); unsigned int nBitsRequired = GetNextWorkRequired(pindexPrev, &block); @@ -3479,7 +3479,7 @@ CBlockIndex* InsertBlockIndex(const uint256& hash) AssertLockHeld(cs_main); if (hash.IsNull()) - return NULL; + return nullptr; // Return existing BlockMap::iterator mi = mapBlockIndex.find(hash); @@ -3540,13 +3540,13 @@ bool static LoadBlockIndexDB(std::string& strError) EXCLUSIVE_LOCKS_REQUIRED(cs_ pindex->nChainSaplingValue = pindex->nSaplingValue; } } - if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && (pindex->nChainTx || pindex->pprev == NULL)) + if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && (pindex->nChainTx || pindex->pprev == nullptr)) setBlockIndexCandidates.insert(pindex); if (pindex->nStatus & BLOCK_FAILED_MASK && (!pindexBestInvalid || pindex->nChainWork > pindexBestInvalid->nChainWork)) pindexBestInvalid = pindex; if (pindex->pprev) pindex->BuildSkip(); - if (pindex->IsValid(BLOCK_VALID_TREE) && (pindexBestHeader == NULL || CBlockIndexWorkComparator()(pindexBestHeader, pindex))) + if (pindex->IsValid(BLOCK_VALID_TREE) && (pindexBestHeader == nullptr || CBlockIndexWorkComparator()(pindexBestHeader, pindex))) pindexBestHeader = pindex; } @@ -3650,7 +3650,7 @@ CVerifyDB::~CVerifyDB() bool CVerifyDB::VerifyDB(CCoinsView* coinsview, int nCheckLevel, int nCheckDepth) { LOCK(cs_main); - if (chainActive.Tip() == NULL || chainActive.Tip()->pprev == NULL) + if (chainActive.Tip() == nullptr || chainActive.Tip()->pprev == nullptr) return true; const int chainHeight = chainActive.Height(); @@ -3667,7 +3667,7 @@ bool CVerifyDB::VerifyDB(CCoinsView* coinsview, int nCheckLevel, int nCheckDepth LogPrintf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel); CCoinsViewCache coins(coinsview); CBlockIndex* pindexState = chainActive.Tip(); - CBlockIndex* pindexFailure = NULL; + CBlockIndex* pindexFailure = nullptr; int nGoodTransactions = 0; int reportDone = 0; LogPrintf("[0%%]..."); @@ -3847,9 +3847,9 @@ void UnloadBlockIndex() { LOCK(cs_main); setBlockIndexCandidates.clear(); - chainActive.SetTip(NULL); - pindexBestInvalid = NULL; - pindexBestHeader = NULL; + chainActive.SetTip(nullptr); + pindexBestInvalid = nullptr; + pindexBestHeader = nullptr; mempool.clear(); mapBlocksUnlinked.clear(); vinfoBlockFile.clear(); @@ -4060,31 +4060,31 @@ void static CheckBlockIndex() assert(forward.size() == mapBlockIndex.size()); - std::pair::iterator, std::multimap::iterator> rangeGenesis = forward.equal_range(NULL); + std::pair::iterator, std::multimap::iterator> rangeGenesis = forward.equal_range(nullptr); CBlockIndex* pindex = rangeGenesis.first->second; rangeGenesis.first++; - assert(rangeGenesis.first == rangeGenesis.second); // There is only one index entry with parent NULL. + assert(rangeGenesis.first == rangeGenesis.second); // There is only one index entry with parent nullptr. // Iterate over the entire block tree, using depth-first search. // Along the way, remember whether there are blocks on the path from genesis // block being explored which are the first to have certain properties. size_t nNodes = 0; int nHeight = 0; - CBlockIndex* pindexFirstInvalid = NULL; // Oldest ancestor of pindex which is invalid. - CBlockIndex* pindexFirstMissing = NULL; // Oldest ancestor of pindex which does not have BLOCK_HAVE_DATA. - CBlockIndex* pindexFirstNotTreeValid = NULL; // Oldest ancestor of pindex which does not have BLOCK_VALID_TREE (regardless of being valid or not). - CBlockIndex* pindexFirstNotChainValid = NULL; // Oldest ancestor of pindex which does not have BLOCK_VALID_CHAIN (regardless of being valid or not). - CBlockIndex* pindexFirstNotScriptsValid = NULL; // Oldest ancestor of pindex which does not have BLOCK_VALID_SCRIPTS (regardless of being valid or not). - while (pindex != NULL) { + CBlockIndex* pindexFirstInvalid = nullptr; // Oldest ancestor of pindex which is invalid. + CBlockIndex* pindexFirstMissing = nullptr; // Oldest ancestor of pindex which does not have BLOCK_HAVE_DATA. + CBlockIndex* pindexFirstNotTreeValid = nullptr; // Oldest ancestor of pindex which does not have BLOCK_VALID_TREE (regardless of being valid or not). + CBlockIndex* pindexFirstNotChainValid = nullptr; // Oldest ancestor of pindex which does not have BLOCK_VALID_CHAIN (regardless of being valid or not). + CBlockIndex* pindexFirstNotScriptsValid = nullptr; // Oldest ancestor of pindex which does not have BLOCK_VALID_SCRIPTS (regardless of being valid or not). + while (pindex != nullptr) { nNodes++; - if (pindexFirstInvalid == NULL && pindex->nStatus & BLOCK_FAILED_VALID) pindexFirstInvalid = pindex; - if (pindexFirstMissing == NULL && !(pindex->nStatus & BLOCK_HAVE_DATA)) pindexFirstMissing = pindex; - if (pindex->pprev != NULL && pindexFirstNotTreeValid == NULL && (pindex->nStatus & BLOCK_VALID_MASK) < BLOCK_VALID_TREE) pindexFirstNotTreeValid = pindex; - if (pindex->pprev != NULL && pindexFirstNotChainValid == NULL && (pindex->nStatus & BLOCK_VALID_MASK) < BLOCK_VALID_CHAIN) pindexFirstNotChainValid = pindex; - if (pindex->pprev != NULL && pindexFirstNotScriptsValid == NULL && (pindex->nStatus & BLOCK_VALID_MASK) < BLOCK_VALID_SCRIPTS) pindexFirstNotScriptsValid = pindex; + if (pindexFirstInvalid == nullptr && pindex->nStatus & BLOCK_FAILED_VALID) pindexFirstInvalid = pindex; + if (pindexFirstMissing == nullptr && !(pindex->nStatus & BLOCK_HAVE_DATA)) pindexFirstMissing = pindex; + if (pindex->pprev != nullptr && pindexFirstNotTreeValid == nullptr && (pindex->nStatus & BLOCK_VALID_MASK) < BLOCK_VALID_TREE) pindexFirstNotTreeValid = pindex; + if (pindex->pprev != nullptr && pindexFirstNotChainValid == nullptr && (pindex->nStatus & BLOCK_VALID_MASK) < BLOCK_VALID_CHAIN) pindexFirstNotChainValid = pindex; + if (pindex->pprev != nullptr && pindexFirstNotScriptsValid == nullptr && (pindex->nStatus & BLOCK_VALID_MASK) < BLOCK_VALID_SCRIPTS) pindexFirstNotScriptsValid = pindex; // Begin: actual consistency checks. - if (pindex->pprev == NULL) { + if (pindex->pprev == nullptr) { // Genesis block checks. assert(pindex->GetBlockHash() == Params().GetConsensus().hashGenesisBlock); // Genesis block's hash must match. assert(pindex == chainActive.Genesis()); // The current active chain's genesis block must be this block. @@ -4094,20 +4094,20 @@ void static CheckBlockIndex() assert(((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_TRANSACTIONS) == (pindex->nTx > 0)); if (pindex->nChainTx == 0) assert(pindex->nSequenceId == 0); // nSequenceId can't be set for blocks that aren't linked // All parents having data is equivalent to all parents being VALID_TRANSACTIONS, which is equivalent to nChainTx being set. - assert((pindexFirstMissing != NULL) == (pindex->nChainTx == 0)); // nChainTx == 0 is used to signal that all parent block's transaction data is available. + assert((pindexFirstMissing != nullptr) == (pindex->nChainTx == 0)); // nChainTx == 0 is used to signal that all parent block's transaction data is available. assert(pindex->nHeight == nHeight); // nHeight must be consistent. - assert(pindex->pprev == NULL || pindex->nChainWork >= pindex->pprev->nChainWork); // For every block except the genesis block, the chainwork must be larger than the parent's. + assert(pindex->pprev == nullptr || pindex->nChainWork >= pindex->pprev->nChainWork); // For every block except the genesis block, the chainwork must be larger than the parent's. assert(nHeight < 2 || (pindex->pskip && (pindex->pskip->nHeight < nHeight))); // The pskip pointer must point back for all but the first 2 blocks. - assert(pindexFirstNotTreeValid == NULL); // All mapBlockIndex entries must at least be TREE valid - if ((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_TREE) assert(pindexFirstNotTreeValid == NULL); // TREE valid implies all parents are TREE valid - if ((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_CHAIN) assert(pindexFirstNotChainValid == NULL); // CHAIN valid implies all parents are CHAIN valid - if ((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_SCRIPTS) assert(pindexFirstNotScriptsValid == NULL); // SCRIPTS valid implies all parents are SCRIPTS valid - if (pindexFirstInvalid == NULL) { + assert(pindexFirstNotTreeValid == nullptr); // All mapBlockIndex entries must at least be TREE valid + if ((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_TREE) assert(pindexFirstNotTreeValid == nullptr); // TREE valid implies all parents are TREE valid + if ((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_CHAIN) assert(pindexFirstNotChainValid == nullptr); // CHAIN valid implies all parents are CHAIN valid + if ((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_SCRIPTS) assert(pindexFirstNotScriptsValid == nullptr); // SCRIPTS valid implies all parents are SCRIPTS valid + if (pindexFirstInvalid == nullptr) { // Checks for not-invalid blocks. assert((pindex->nStatus & BLOCK_FAILED_MASK) == 0); // The failed mask cannot be set for blocks without invalid parents. } - if (!CBlockIndexWorkComparator()(pindex, chainActive.Tip()) && pindexFirstMissing == NULL) { - if (pindexFirstInvalid == NULL) { // If this block sorts at least as good as the current tip and is valid, it must be in setBlockIndexCandidates. + if (!CBlockIndexWorkComparator()(pindex, chainActive.Tip()) && pindexFirstMissing == nullptr) { + if (pindexFirstInvalid == nullptr) { // If this block sorts at least as good as the current tip and is valid, it must be in setBlockIndexCandidates. assert(setBlockIndexCandidates.count(pindex)); } } else { // If this block sorts worse than the current tip, it cannot be in setBlockIndexCandidates. @@ -4124,8 +4124,8 @@ void static CheckBlockIndex() } rangeUnlinked.first++; } - if (pindex->pprev && pindex->nStatus & BLOCK_HAVE_DATA && pindexFirstMissing != NULL) { - if (pindexFirstInvalid == NULL) { // If this block has block data available, some parent doesn't, and has no invalid parents, it must be in mapBlocksUnlinked. + if (pindex->pprev && pindex->nStatus & BLOCK_HAVE_DATA && pindexFirstMissing != nullptr) { + if (pindexFirstInvalid == nullptr) { // If this block has block data available, some parent doesn't, and has no invalid parents, it must be in mapBlocksUnlinked. assert(foundInUnlinked); } } else { // If this block does not have block data available, or all parents do, it cannot be in mapBlocksUnlinked. @@ -4147,11 +4147,11 @@ void static CheckBlockIndex() while (pindex) { // We are going to either move to a parent or a sibling of pindex. // If pindex was the first with a certain property, unset the corresponding variable. - if (pindex == pindexFirstInvalid) pindexFirstInvalid = NULL; - if (pindex == pindexFirstMissing) pindexFirstMissing = NULL; - if (pindex == pindexFirstNotTreeValid) pindexFirstNotTreeValid = NULL; - if (pindex == pindexFirstNotChainValid) pindexFirstNotChainValid = NULL; - if (pindex == pindexFirstNotScriptsValid) pindexFirstNotScriptsValid = NULL; + if (pindex == pindexFirstInvalid) pindexFirstInvalid = nullptr; + if (pindex == pindexFirstMissing) pindexFirstMissing = nullptr; + if (pindex == pindexFirstNotTreeValid) pindexFirstNotTreeValid = nullptr; + if (pindex == pindexFirstNotChainValid) pindexFirstNotChainValid = nullptr; + if (pindex == pindexFirstNotScriptsValid) pindexFirstNotScriptsValid = nullptr; // Find our parent. CBlockIndex* pindexPar = pindex->pprev; // Find which child we just visited. @@ -4246,7 +4246,7 @@ bool LoadMempool(CTxMemPool& pool) CValidationState state; if (nTime + nExpiryTimeout > nNow) { LOCK(cs_main); - AcceptToMemoryPoolWithTime(pool, state, tx, true, NULL, nTime); + AcceptToMemoryPoolWithTime(pool, state, tx, true, nullptr, nTime); if (state.IsValid()) { ++count; } else { diff --git a/src/validation.h b/src/validation.h index fd40e1d324d42..871e9f3586ac9 100644 --- a/src/validation.h +++ b/src/validation.h @@ -180,7 +180,7 @@ FILE* OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false); /** Translation to a filesystem path */ fs::path GetBlockPosFilename(const FlatFilePos &pos); /** Import blocks from an external file */ -bool LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp = NULL); +bool LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp = nullptr); /** Ensures we have a genesis block in the block tree, possibly writing one to disk. */ bool LoadGenesisBlock(); /** Load the block tree and coins database from disk, @@ -246,10 +246,10 @@ CAmount GetShieldedTxMinFee(const CTransaction& tx); /** * Check whether all inputs of this transaction are valid (no double spends, scripts & sigs, amounts) - * This does not modify the UTXO set. If pvChecks is not NULL, script checks are pushed onto it + * This does not modify the UTXO set. If pvChecks is not nullptr, script checks are pushed onto it * instead of being performed inline. */ -bool CheckInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& view, bool fScriptChecks, unsigned int flags, bool cacheStore, PrecomputedTransactionData& precomTxData, std::vector* pvChecks = NULL); +bool CheckInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& view, bool fScriptChecks, unsigned int flags, bool cacheStore, PrecomputedTransactionData& precomTxData, std::vector* pvChecks = nullptr); /** Apply the effects of this transaction on the UTXO set represented by view */ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight, bool fSkipInvalid = false); diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index ea74c196900f8..38774102e97c2 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -218,7 +218,7 @@ void BerkeleyEnvironment::MakeMock() dbenv->set_lk_max_objects(10000); dbenv->set_flags(DB_AUTO_COMMIT, 1); dbenv->log_set_config(DB_LOG_IN_MEMORY, 1); - int ret = dbenv->open(NULL, + int ret = dbenv->open(nullptr, DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | @@ -546,8 +546,8 @@ void BerkeleyBatch::Close() return; if (activeTxn) activeTxn->abort(); - activeTxn = NULL; - pdb = NULL; + activeTxn = nullptr; + pdb = nullptr; if (fFlushOnClose) Flush(); @@ -563,12 +563,12 @@ void BerkeleyEnvironment::CloseDb(const std::string& strFile) { { LOCK(cs_db); - if (mapDb[strFile] != NULL) { + if (mapDb[strFile] != nullptr) { // Close the database handle Db* pdb = mapDb[strFile]; pdb->close(0); delete pdb; - mapDb[strFile] = NULL; + mapDb[strFile] = nullptr; } } } @@ -622,7 +622,7 @@ bool BerkeleyBatch::Rewrite(BerkeleyDatabase& database, const char* pszSkip) BerkeleyBatch db(database, "r"); std::unique_ptr pdbCopy = std::make_unique(env->dbenv.get(), 0); - int ret = pdbCopy->open(NULL, // Txn pointer + int ret = pdbCopy->open(nullptr, // Txn pointer strFileRes.c_str(), // Filename "main", // Logical db name DB_BTREE, // Database type @@ -657,7 +657,7 @@ bool BerkeleyBatch::Rewrite(BerkeleyDatabase& database, const char* pszSkip) } Dbt datKey(ssKey.data(), ssKey.size()); Dbt datValue(ssValue.data(), ssValue.size()); - int ret2 = pdbCopy->put(NULL, &datKey, &datValue, DB_NOOVERWRITE); + int ret2 = pdbCopy->put(nullptr, &datKey, &datValue, DB_NOOVERWRITE); if (ret2 > 0) fSuccess = false; } diff --git a/src/wallet/db.h b/src/wallet/db.h index aca7500f332ec..6bbc1e967d518 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -87,10 +87,10 @@ class BerkeleyEnvironment DbTxn* TxnBegin(int flags = DB_TXN_WRITE_NOSYNC) { - DbTxn* ptxn = NULL; - int ret = dbenv->txn_begin(NULL, &ptxn, flags); + DbTxn* ptxn = nullptr; + int ret = dbenv->txn_begin(nullptr, &ptxn, flags); if (!ptxn || ret != 0) - return NULL; + return nullptr; return ptxn; } }; @@ -224,7 +224,7 @@ class BerkeleyBatch int ret = pdb->get(activeTxn, &datKey, &datValue, 0); memory_cleanse(datKey.get_data(), datKey.get_size()); bool success = false; - if (datValue.get_data() != NULL) { + if (datValue.get_data() != nullptr) { // Unserialize value try { CDataStream ssValue((char*)datValue.get_data(), (char*)datValue.get_data() + datValue.get_size(), SER_DISK, CLIENT_VERSION); @@ -315,11 +315,11 @@ class BerkeleyBatch Dbc* GetCursor() { if (!pdb) - return NULL; - Dbc* pcursor = NULL; - int ret = pdb->cursor(NULL, &pcursor, 0); + return nullptr; + Dbc* pcursor = nullptr; + int ret = pdb->cursor(nullptr, &pcursor, 0); if (ret != 0) - return NULL; + return nullptr; return pcursor; } @@ -339,7 +339,7 @@ class BerkeleyBatch int ret = pcursor->get(&datKey, &datValue, fFlags); if (ret != 0) return ret; - else if (datKey.get_data() == NULL || datValue.get_data() == NULL) + else if (datKey.get_data() == nullptr || datValue.get_data() == nullptr) return 99999; // Convert to streams @@ -375,7 +375,7 @@ class BerkeleyBatch if (!pdb || !activeTxn) return false; int ret = activeTxn->commit(0); - activeTxn = NULL; + activeTxn = nullptr; return (ret == 0); } @@ -384,7 +384,7 @@ class BerkeleyBatch if (!pdb || !activeTxn) return false; int ret = activeTxn->abort(); - activeTxn = NULL; + activeTxn = nullptr; return (ret == 0); } @@ -399,7 +399,7 @@ class BerkeleyBatch return Write(std::string("version"), nVersion); } - bool static Rewrite(BerkeleyDatabase& database, const char* pszSkip = NULL); + bool static Rewrite(BerkeleyDatabase& database, const char* pszSkip = nullptr); }; #endif // BITCOIN_DB_H diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fa77b6cfaf00f..dad2cabb6d266 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3196,7 +3196,7 @@ UniValue listsinceblock(const JSONRPCRequest& request) LOCK2(cs_main, pwallet->cs_wallet); - CBlockIndex* pindex = NULL; + CBlockIndex* pindex = nullptr; int target_confirms = 1; isminefilter filter = ISMINE_SPENDABLE_ALL | ISMINE_COLD; diff --git a/src/wallet/rpcwallet.h b/src/wallet/rpcwallet.h index 9c3f9da51f7ab..05ba22e8fd077 100644 --- a/src/wallet/rpcwallet.h +++ b/src/wallet/rpcwallet.h @@ -17,7 +17,7 @@ void RegisterWalletRPCCommands(CRPCTable &tableRPC); * Figures out what wallet, if any, to use for a JSONRPCRequest. * * @param[in] request JSONRPCRequest that wishes to access a wallet - * @return NULL if no wallet should be used, or a pointer to the CWallet + * @return nullptr if no wallet should be used, or a pointer to the CWallet */ CWallet* GetWalletForJSONRPCRequest(const JSONRPCRequest& request); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b58df803c8fc3..3c48806b7fe0c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -799,7 +799,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) encrypted_batch = new WalletBatch(*database); if (!encrypted_batch->TxnBegin()) { delete encrypted_batch; - encrypted_batch = NULL; + encrypted_batch = nullptr; return false; } encrypted_batch->WriteMasterKey(nMasterKeyMaxID, kMasterKey); @@ -824,7 +824,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) } delete encrypted_batch; - encrypted_batch = NULL; + encrypted_batch = nullptr; Lock(); Unlock(strWalletPassphrase); @@ -1052,7 +1052,7 @@ void CWallet::AddExternalNotesDataToTx(CWalletTx& wtx) const /** * Add a transaction to the wallet, or update it. pIndex and posInBlock should * be set when the transaction was known to be included in a block. When - * pIndex == NULL, then wallet state is not updated in AddToWallet, but + * pIndex == nullptr, then wallet state is not updated in AddToWallet, but * notifications happen and cached balances are marked dirty. * * If fUpdate is true, existing transactions will be updated. @@ -2023,7 +2023,7 @@ void CWalletTx::RelayWalletTransaction(CConnman* connman) std::set CWalletTx::GetConflicts() const { std::set result; - if (pwallet != NULL) { + if (pwallet != nullptr) { uint256 myHash = GetHash(); result = pwallet->GetConflicts(myHash); result.erase(myHash); @@ -2703,7 +2703,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int // List of values less than target std::pair > coinLowestLarger; coinLowestLarger.first = std::numeric_limits::max(); - coinLowestLarger.second.first = NULL; + coinLowestLarger.second.first = nullptr; std::vector > > vValue; CAmount nTotalLower = 0; @@ -2749,7 +2749,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int } if (nTotalLower < nTargetValue) { - if (coinLowestLarger.second.first == NULL) + if (coinLowestLarger.second.first == nullptr) return false; setCoinsRet.insert(coinLowestLarger.second); nValueRet += coinLowestLarger.first; @@ -4457,7 +4457,7 @@ void CWallet::SetNull() nWalletVersion = FEATURE_BASE; nWalletMaxVersion = FEATURE_BASE; nMasterKeyMaxID = 0; - encrypted_batch = NULL; + encrypted_batch = nullptr; nOrderPosNext = 0; nNextResend = 0; nLastResend = 0; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index a1976db582fd2..3a17d5072d876 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1008,7 +1008,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface * Increment the next transaction order id * @return next transaction order id */ - int64_t IncOrderPosNext(WalletBatch* batch = NULL); + int64_t IncOrderPosNext(WalletBatch* batch = nullptr); void MarkDirty(); bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose = true); @@ -1171,7 +1171,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface unsigned int GetStakingKeyPoolSize(); //! signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower - bool SetMinVersion(enum WalletFeature, WalletBatch* batch_in = NULL, bool fExplicit = false); + bool SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr, bool fExplicit = false); //! change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format) bool SetMaxVersion(int nVersion); diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp index 97aef41ac31ba..efb172dc6d431 100644 --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -14,7 +14,7 @@ void zmqError(const char *str) LogPrint(BCLog::ZMQ, "Error: %s, errno=%s\n", str, zmq_strerror(errno)); } -CZMQNotificationInterface::CZMQNotificationInterface() : pcontext(NULL) +CZMQNotificationInterface::CZMQNotificationInterface() : pcontext(nullptr) { } @@ -30,7 +30,7 @@ CZMQNotificationInterface::~CZMQNotificationInterface() CZMQNotificationInterface* CZMQNotificationInterface::Create() { - CZMQNotificationInterface* notificationInterface = NULL; + CZMQNotificationInterface* notificationInterface = nullptr; std::map factories; std::list notifiers; @@ -61,7 +61,7 @@ CZMQNotificationInterface* CZMQNotificationInterface::Create() if (!notificationInterface->Initialize()) { delete notificationInterface; - notificationInterface = NULL; + notificationInterface = nullptr; } }