Skip to content

Commit 58e254e

Browse files
committed
scripted-diff: Use C++11 nullptr instead of NULL
-BEGIN VERIFY SCRIPT- sed -i 's/\<NULL\>/nullptr/g' src/*.cpp src/*.h src/*/*.cpp src/*/*.h src/qt/*/*.cpp src/qt/*/*.h src/qt/pivx/*/*.cpp src/qt/pivx/*/*.h src/wallet/*/*.cpp src/test/*/*.cpp src/wallet/*/*.h sed -i 's/Prefer nullptr, otherwise SAFECOOKIE./Prefer NULL, otherwise SAFECOOKIE./g' src/torcontrol.cpp sed -i 's/tor: Using nullptr authentication/tor: Using NULL authentication/g' src/torcontrol.cpp sed -i 's/METHODS=nullptr/METHODS=NULL/g' src/test/torcontrol_tests.cpp src/torcontrol.cpp sed -i 's/nullptr certificates/NULL certificates/g' src/qt/paymentserver.cpp sed -i 's/"nullptr"/"NULL"/g' src/torcontrol.cpp src/test/torcontrol_tests.cpp -END VERIFY SCRIPT-
1 parent 3e2eb99 commit 58e254e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+279
-279
lines changed

src/addrman.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
8080
{
8181
std::map<CNetAddr, int>::iterator it = mapAddr.find(addr);
8282
if (it == mapAddr.end())
83-
return NULL;
83+
return nullptr;
8484
if (pnId)
8585
*pnId = (*it).second;
8686
std::map<int, CAddrInfo>::iterator it2 = mapInfo.find((*it).second);
8787
if (it2 != mapInfo.end())
8888
return &(*it2).second;
89-
return NULL;
89+
return nullptr;
9090
}
9191

9292
CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, int* pnId)

src/arith_uint256.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ class arith_uint256 : public base_uint<256> {
353353
* complexities of the sign bit and using base 256 are probably an
354354
* implementation accident.
355355
*/
356-
arith_uint256& SetCompact(uint32_t nCompact, bool *pfNegative = NULL, bool *pfOverflow = NULL);
356+
arith_uint256& SetCompact(uint32_t nCompact, bool *pfNegative = nullptr, bool *pfOverflow = nullptr);
357357
uint32_t GetCompact(bool fNegative = false) const;
358358
uint32_t Get32(int n = 0) const { return pn[2 * n]; }
359359

src/base58.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bool DecodeBase58(const char* psz, std::vector<unsigned char>& vch, int max_ret_
4040
while (*psz && !isspace(*psz)) {
4141
// Decode base58 character
4242
const char* ch = strchr(pszBase58, *psz);
43-
if (ch == NULL)
43+
if (ch == nullptr)
4444
return false;
4545
// Apply "b256 = b256 * 58 + ch".
4646
int carry = ch - pszBase58;

src/base58.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
/**
2828
* Encode a byte sequence as a base58-encoded string.
29-
* pbegin and pend cannot be NULL, unless both are.
29+
* pbegin and pend cannot be nullptr, unless both are.
3030
*/
3131
std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend);
3232

@@ -38,7 +38,7 @@ std::string EncodeBase58(const std::vector<unsigned char>& vch);
3838
/**
3939
* Decode a base58-encoded string (psz) into a byte vector (vchRet).
4040
* return true if decoding is successful.
41-
* psz cannot be NULL.
41+
* psz cannot be nullptr.
4242
*/
4343
NODISCARD bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet, int max_ret_len);
4444

src/budget/budgetmanager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ void CBudgetManager::VoteOnFinalizedBudgets()
624624
}
625625
}
626626
std::string strError = "";
627-
if (!UpdateFinalizedBudget(vote, NULL, strError)) {
627+
if (!UpdateFinalizedBudget(vote, nullptr, strError)) {
628628
LogPrintf("%s: Error submitting vote - %s\n", __func__, strError);
629629
continue;
630630
}

src/chain.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
void CChain::SetTip(CBlockIndex* pindex)
1515
{
16-
if (pindex == NULL) {
16+
if (pindex == nullptr) {
1717
vChain.clear();
1818
return;
1919
}
@@ -333,7 +333,7 @@ bool CBlockIndex::RaiseValidity(enum BlockStatus nUpTo)
333333
}
334334

335335
/** Find the last common ancestor two blocks have.
336-
* Both pa and pb must be non-NULL. */
336+
* Both pa and pb must be non-nullptr. */
337337
const CBlockIndex* LastCommonAncestor(const CBlockIndex* pa, const CBlockIndex* pb)
338338
{
339339
if (pa->nHeight > pb->nHeight) {

src/chain.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -395,17 +395,17 @@ class CChain
395395
std::vector<CBlockIndex*> vChain;
396396

397397
public:
398-
/** Returns the index entry for the genesis block of this chain, or NULL if none. */
398+
/** Returns the index entry for the genesis block of this chain, or nullptr if none. */
399399
CBlockIndex* Genesis() const
400400
{
401-
return vChain.size() > 0 ? vChain[0] : NULL;
401+
return vChain.size() > 0 ? vChain[0] : nullptr;
402402
}
403403

404-
/** Returns the index entry for the tip of this chain, or NULL if none. */
404+
/** Returns the index entry for the tip of this chain, or nullptr if none. */
405405
CBlockIndex* Tip(bool fProofOfStake = false) const
406406
{
407407
if (vChain.size() < 1)
408-
return NULL;
408+
return nullptr;
409409

410410
CBlockIndex* pindex = vChain[vChain.size() - 1];
411411

@@ -416,11 +416,11 @@ class CChain
416416
return pindex;
417417
}
418418

419-
/** Returns the index entry at a particular height in this chain, or NULL if no such height exists. */
419+
/** Returns the index entry at a particular height in this chain, or nullptr if no such height exists. */
420420
CBlockIndex* operator[](int nHeight) const
421421
{
422422
if (nHeight < 0 || nHeight >= (int)vChain.size())
423-
return NULL;
423+
return nullptr;
424424
return vChain[nHeight];
425425
}
426426

@@ -437,13 +437,13 @@ class CChain
437437
return (*this)[pindex->nHeight] == pindex;
438438
}
439439

440-
/** Find the successor of a block in this chain, or NULL if the given index is not found or is the tip. */
440+
/** Find the successor of a block in this chain, or nullptr if the given index is not found or is the tip. */
441441
CBlockIndex* Next(const CBlockIndex* pindex) const
442442
{
443443
if (Contains(pindex))
444444
return (*this)[pindex->nHeight + 1];
445445
else
446-
return NULL;
446+
return nullptr;
447447
}
448448

449449
/** Return the maximal height in the chain. Is equal to chain.Tip() ? chain.Tip()->nHeight : -1. */
@@ -456,7 +456,7 @@ class CChain
456456
void SetTip(CBlockIndex* pindex);
457457

458458
/** Return a CBlockLocator that refers to a block in this chain (by default the tip). */
459-
CBlockLocator GetLocator(const CBlockIndex* pindex = NULL) const;
459+
CBlockLocator GetLocator(const CBlockIndex* pindex = nullptr) const;
460460

461461
/** Find the last common block between this chain and a block index entry. */
462462
const CBlockIndex* FindFork(const CBlockIndex* pindex) const;

src/checkpoints.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ bool CheckBlock(int nHeight, const uint256& hash, bool fMatchesCheckpoint)
4242
//! Guess how far we are in the verification process at the given block index
4343
double GuessVerificationProgress(const CBlockIndex* pindex, bool fSigchecks)
4444
{
45-
if (pindex == NULL)
45+
if (pindex == nullptr)
4646
return 0.0;
4747

48-
int64_t nNow = time(NULL);
48+
int64_t nNow = time(nullptr);
4949

5050
double fSigcheckVerificationFactor = fSigchecks ? SIGCHECK_VERIFICATION_FACTOR : 1.0;
5151
double fWorkBefore = 0.0; // Amount of work done before pindex

src/checkqueue.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,16 @@ class CCheckQueueControl
177177
public:
178178
CCheckQueueControl(CCheckQueue<T>* pqueueIn) : pqueue(pqueueIn), fDone(false)
179179
{
180-
// passed queue is supposed to be unused, or NULL
181-
if (pqueue != NULL) {
180+
// passed queue is supposed to be unused, or nullptr
181+
if (pqueue != nullptr) {
182182
bool isIdle = pqueue->IsIdle();
183183
assert(isIdle);
184184
}
185185
}
186186

187187
bool Wait()
188188
{
189-
if (pqueue == NULL)
189+
if (pqueue == nullptr)
190190
return true;
191191
bool fRet = pqueue->Wait();
192192
fDone = true;
@@ -195,7 +195,7 @@ class CCheckQueueControl
195195

196196
void Add(std::vector<T>& vChecks)
197197
{
198-
if (pqueue != NULL)
198+
if (pqueue != nullptr)
199199
pqueue->Add(vChecks);
200200
}
201201

src/consensus/merkle.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
128128

129129
uint256 ComputeMerkleRoot(const std::vector<uint256>& leaves, bool* mutated) {
130130
uint256 hash;
131-
MerkleComputation(leaves, &hash, mutated, -1, NULL);
131+
MerkleComputation(leaves, &hash, mutated, -1, nullptr);
132132
return hash;
133133
}
134134

135135
std::vector<uint256> ComputeMerkleBranch(const std::vector<uint256>& leaves, uint32_t position) {
136136
std::vector<uint256> ret;
137-
MerkleComputation(leaves, NULL, NULL, position, &ret);
137+
MerkleComputation(leaves, nullptr, nullptr, position, &ret);
138138
return ret;
139139
}
140140

src/consensus/merkle.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
#include "primitives/block.h"
1313
#include "uint256.h"
1414

15-
uint256 ComputeMerkleRoot(const std::vector<uint256>& leaves, bool* mutated = NULL);
15+
uint256 ComputeMerkleRoot(const std::vector<uint256>& leaves, bool* mutated = nullptr);
1616
std::vector<uint256> ComputeMerkleBranch(const std::vector<uint256>& leaves, uint32_t position);
1717
uint256 ComputeMerkleRootFromBranch(const uint256& leaf, const std::vector<uint256>& branch, uint32_t position);
1818

1919
/*
2020
* Compute the Merkle root of the transactions in a block.
2121
* *mutated is set to true if a duplicated subtree was found.
2222
*/
23-
uint256 BlockMerkleRoot(const CBlock& block, bool* mutated = NULL);
23+
uint256 BlockMerkleRoot(const CBlock& block, bool* mutated = nullptr);
2424

2525
/*
2626
* Compute the Merkle branch for the tree of transactions in a block, for a

src/core_write.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDeco
9494
// this won't decode correctly formatted public keys in Pubkey or Multisig scripts due to
9595
// the restrictions on the pubkey formats (see IsCompressedOrUncompressedPubKey) being incongruous with the
9696
// checks in CheckSignatureEncoding.
97-
if (CheckSignatureEncoding(vch, SCRIPT_VERIFY_STRICTENC, NULL)) {
97+
if (CheckSignatureEncoding(vch, SCRIPT_VERIFY_STRICTENC, nullptr)) {
9898
const unsigned char chSigHashType = vch.back();
9999
if (mapSigHashTypes.count(chSigHashType)) {
100100
strSigHashDecode = "[" + mapSigHashTypes.find(chSigHashType)->second + "]";

src/dbwrapper.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static leveldb::Options GetOptions(size_t nCacheSize)
5454

5555
CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bool fWipe)
5656
{
57-
penv = NULL;
57+
penv = nullptr;
5858
readoptions.verify_checksums = true;
5959
iteroptions.verify_checksums = true;
6060
iteroptions.fill_cache = false;
@@ -81,13 +81,13 @@ CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bo
8181
CDBWrapper::~CDBWrapper()
8282
{
8383
delete pdb;
84-
pdb = NULL;
84+
pdb = nullptr;
8585
delete options.filter_policy;
86-
options.filter_policy = NULL;
86+
options.filter_policy = nullptr;
8787
delete options.block_cache;
88-
options.block_cache = NULL;
88+
options.block_cache = nullptr;
8989
delete penv;
90-
options.env = NULL;
90+
options.env = nullptr;
9191
}
9292

9393
bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync)

src/dbwrapper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class CDBIterator
195195
class CDBWrapper
196196
{
197197
private:
198-
//! custom environment this database is using (may be NULL in case of default environment)
198+
//! custom environment this database is using (may be nullptr in case of default environment)
199199
leveldb::Env* penv;
200200

201201
//! database options used

src/hash.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ class CBLAKE2bWriter
306306
CBLAKE2bWriter(int nTypeIn, int nVersionIn, const unsigned char* personal) : nType(nTypeIn), nVersion(nVersionIn) {
307307
assert(crypto_generichash_blake2b_init_salt_personal(
308308
&state,
309-
NULL, 0, // No key.
309+
nullptr, 0, // No key.
310310
32,
311-
NULL, // No salt.
311+
nullptr, // No salt.
312312
personal) == 0);
313313
}
314314

src/httpserver.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
278278
static void http_reject_request_cb(struct evhttp_request* req, void*)
279279
{
280280
LogPrint(BCLog::HTTP, "Rejecting request while shutting down\n");
281-
evhttp_send_error(req, HTTP_SERVUNAVAIL, NULL);
281+
evhttp_send_error(req, HTTP_SERVUNAVAIL, nullptr);
282282
}
283283
/** Event dispatcher thread */
284284
static bool ThreadHTTP(struct event_base* base, struct evhttp* http)
@@ -319,7 +319,7 @@ static bool HTTPBindAddresses(struct evhttp* http)
319319
// Bind addresses
320320
for (std::vector<std::pair<std::string, uint16_t> >::iterator i = endpoints.begin(); i != endpoints.end(); ++i) {
321321
LogPrint(BCLog::HTTP, "Binding RPC on address %s port %i\n", i->first, i->second);
322-
evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? NULL : i->first.c_str(), i->second);
322+
evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? nullptr : i->first.c_str(), i->second);
323323
if (bind_handle) {
324324
CNetAddr addr;
325325
if (i->first.empty() || (LookupHost(i->first, addr, false) && addr.IsBindAny())) {
@@ -393,7 +393,7 @@ bool InitHTTPServer()
393393
evhttp_set_timeout(http, gArgs.GetArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT));
394394
evhttp_set_max_headers_size(http, MAX_HEADERS_SIZE);
395395
evhttp_set_max_body_size(http, MAX_SIZE);
396-
evhttp_set_gencb(http, http_request_cb, NULL);
396+
evhttp_set_gencb(http, http_request_cb, nullptr);
397397

398398
if (!HTTPBindAddresses(http)) {
399399
LogPrintf("Unable to bind any endpoint for RPC server\n");
@@ -451,7 +451,7 @@ void InterruptHTTPServer()
451451
for (evhttp_bound_socket *socket : boundSockets) {
452452
evhttp_del_accept_socket(eventHTTP, socket);
453453
}
454-
evhttp_set_gencb(eventHTTP, http_reject_request_cb, NULL);
454+
evhttp_set_gencb(eventHTTP, http_reject_request_cb, nullptr);
455455
}
456456
if (workQueue)
457457
workQueue->Interrupt();
@@ -521,7 +521,7 @@ HTTPEvent::~HTTPEvent()
521521
}
522522
void HTTPEvent::trigger(struct timeval* tv)
523523
{
524-
if (tv == NULL)
524+
if (tv == nullptr)
525525
event_active(ev, 0, 0); // immediately trigger event in main thread
526526
else
527527
evtimer_add(ev, tv); // trigger after timeval passed
@@ -564,7 +564,7 @@ std::string HTTPRequest::ReadBody()
564564
* abstraction to consume the evbuffer on the fly in the parsing algorithm.
565565
*/
566566
const char* data = (const char*)evbuffer_pullup(buf, size);
567-
if (!data) // returns NULL in case of empty buffer
567+
if (!data) // returns nullptr in case of empty buffer
568568
return "";
569569
std::string rv(data, size);
570570
evbuffer_drain(buf, size);
@@ -673,7 +673,7 @@ void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
673673
std::string urlDecode(const std::string &urlEncoded) {
674674
std::string res;
675675
if (!urlEncoded.empty()) {
676-
char *decoded = evhttp_uridecode(urlEncoded.c_str(), false, NULL);
676+
char *decoded = evhttp_uridecode(urlEncoded.c_str(), false, nullptr);
677677
if (decoded) {
678678
res = std::string(decoded);
679679
free(decoded);

src/init.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ std::unique_ptr<CConnman> g_connman;
9191
std::unique_ptr<PeerLogicValidation> peerLogic;
9292

9393
#if ENABLE_ZMQ
94-
static CZMQNotificationInterface* pzmqNotificationInterface = NULL;
94+
static CZMQNotificationInterface* pzmqNotificationInterface = nullptr;
9595
#endif
9696

9797
#ifdef WIN32
@@ -219,7 +219,7 @@ void Shutdown()
219219
for (CWalletRef pwallet : vpwallets) {
220220
pwallet->Flush(false);
221221
}
222-
GenerateBitcoins(false, NULL, 0);
222+
GenerateBitcoins(false, nullptr, 0);
223223
#endif
224224
StopMapPort();
225225

@@ -273,7 +273,7 @@ void Shutdown()
273273

274274
{
275275
LOCK(cs_main);
276-
if (pcoinsTip != NULL) {
276+
if (pcoinsTip != nullptr) {
277277
FlushStateToDisk();
278278

279279
//record that client took the proper shutdown procedure
@@ -802,7 +802,7 @@ bool AppInitBasicSetup()
802802
#ifdef _MSC_VER
803803
// Turn off Microsoft heap dump noise
804804
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
805-
_CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0));
805+
_CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, 0));
806806
#endif
807807
#if _MSC_VER >= 1400
808808
// Disable confusing "helpful" text message on abort, Ctrl-C
@@ -819,7 +819,7 @@ bool AppInitBasicSetup()
819819
#endif
820820
typedef BOOL(WINAPI * PSETPROCDEPPOL)(DWORD);
821821
PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy");
822-
if (setProcDEPPol != NULL) setProcDEPPol(PROCESS_DEP_ENABLE);
822+
if (setProcDEPPol != nullptr) setProcDEPPol(PROCESS_DEP_ENABLE);
823823
#endif
824824

825825
if (!SetupNetworking())
@@ -1065,7 +1065,7 @@ bool AppInitParameterInteraction()
10651065
else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS)
10661066
nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS;
10671067

1068-
setvbuf(stdout, NULL, _IOLBF, 0); /// ***TODO*** do we still need this after -printtoconsole is gone?
1068+
setvbuf(stdout, nullptr, _IOLBF, 0); /// ***TODO*** do we still need this after -printtoconsole is gone?
10691069

10701070
#ifndef ENABLE_WALLET
10711071
if (gArgs.SoftSetBoolArg("-staking", false))

0 commit comments

Comments
 (0)