Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cleanup] Use C++11 nullptr instead of NULL #2266

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
{
std::map<CNetAddr, int>::iterator it = mapAddr.find(addr);
if (it == mapAddr.end())
return NULL;
return nullptr;
if (pnId)
*pnId = (*it).second;
std::map<int, CAddrInfo>::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)
Expand Down
2 changes: 1 addition & 1 deletion src/arith_uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]; }

Expand Down
2 changes: 1 addition & 1 deletion src/base58.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool DecodeBase58(const char* psz, std::vector<unsigned char>& 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;
Expand Down
4 changes: 2 additions & 2 deletions src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -38,7 +38,7 @@ std::string EncodeBase58(const std::vector<unsigned char>& 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<unsigned char>& vchRet, int max_ret_len);

Expand Down
2 changes: 1 addition & 1 deletion src/budget/budgetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
void CChain::SetTip(CBlockIndex* pindex)
{
if (pindex == NULL) {
if (pindex == nullptr) {
vChain.clear();
return;
}
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,17 +395,17 @@ class CChain
std::vector<CBlockIndex*> 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];

Expand All @@ -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];
}

Expand All @@ -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. */
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/checkqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,16 @@ class CCheckQueueControl
public:
CCheckQueueControl(CCheckQueue<T>* 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);
}
}

bool Wait()
{
if (pqueue == NULL)
if (pqueue == nullptr)
return true;
bool fRet = pqueue->Wait();
fDone = true;
Expand All @@ -195,7 +195,7 @@ class CCheckQueueControl

void Add(std::vector<T>& vChecks)
{
if (pqueue != NULL)
if (pqueue != nullptr)
pqueue->Add(vChecks);
}

Expand Down
4 changes: 2 additions & 2 deletions src/consensus/merkle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot

uint256 ComputeMerkleRoot(const std::vector<uint256>& leaves, bool* mutated) {
uint256 hash;
MerkleComputation(leaves, &hash, mutated, -1, NULL);
MerkleComputation(leaves, &hash, mutated, -1, nullptr);
return hash;
}

std::vector<uint256> ComputeMerkleBranch(const std::vector<uint256>& leaves, uint32_t position) {
std::vector<uint256> ret;
MerkleComputation(leaves, NULL, NULL, position, &ret);
MerkleComputation(leaves, nullptr, nullptr, position, &ret);
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions src/consensus/merkle.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
#include "primitives/block.h"
#include "uint256.h"

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

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

/*
* Compute the Merkle branch for the tree of transactions in a block, for a
Expand Down
2 changes: 1 addition & 1 deletion src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDeco
// this won't decode correctly formatted public keys in Pubkey or Multisig scripts due to
// the restrictions on the pubkey formats (see IsCompressedOrUncompressedPubKey) being incongruous with the
// checks in CheckSignatureEncoding.
if (CheckSignatureEncoding(vch, SCRIPT_VERIFY_STRICTENC, NULL)) {
if (CheckSignatureEncoding(vch, SCRIPT_VERIFY_STRICTENC, nullptr)) {
const unsigned char chSigHashType = vch.back();
if (mapSigHashTypes.count(chSigHashType)) {
strSigHashDecode = "[" + mapSigHashTypes.find(chSigHashType)->second + "]";
Expand Down
10 changes: 5 additions & 5 deletions src/dbwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/dbwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -319,7 +319,7 @@ static bool HTTPBindAddresses(struct evhttp* http)
// Bind addresses
for (std::vector<std::pair<std::string, uint16_t> >::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())) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ std::unique_ptr<CConnman> g_connman;
std::unique_ptr<PeerLogicValidation> peerLogic;

#if ENABLE_ZMQ
static CZMQNotificationInterface* pzmqNotificationInterface = NULL;
static CZMQNotificationInterface* pzmqNotificationInterface = nullptr;
#endif

#ifdef WIN32
Expand Down Expand Up @@ -219,7 +219,7 @@ void Shutdown()
for (CWalletRef pwallet : vpwallets) {
pwallet->Flush(false);
}
GenerateBitcoins(false, NULL, 0);
GenerateBitcoins(false, nullptr, 0);
#endif
StopMapPort();

Expand Down Expand Up @@ -273,7 +273,7 @@ void Shutdown()

{
LOCK(cs_main);
if (pcoinsTip != NULL) {
if (pcoinsTip != nullptr) {
FlushStateToDisk();

//record that client took the proper shutdown procedure
Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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))
Expand Down
Loading