Skip to content

Commit ce74799

Browse files
committed
Merge #10483: scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal instead of the macro NULL
90d4d89 scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal instead of the macro NULL (practicalswift) Pull request description: Since C++11 the macro `NULL` may be: * an integer literal with value zero, or * a prvalue of type `std::nullptr_t` By using the C++11 keyword `nullptr` we are guaranteed a prvalue of type `std::nullptr_t`. For a more thorough discussion, see "A name for the null pointer: nullptr" (Sutter & Stroustrup), http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2431.pdf With this patch applied there are no `NULL` macro usages left in the repo: ``` $ git grep NULL -- "*.cpp" "*.h" | egrep -v '(/univalue/|/secp256k1/|/leveldb/|_NULL|NULLDUMMY|torcontrol.*NULL|NULL cert)' | wc -l 0 ``` The road towards `nullptr` (C++11) is split into two PRs: * `NULL` → `nullptr` is handled in PR #10483 (scripted, this PR) * `0` → `nullptr` is handled in PR #10645 (manual) Tree-SHA512: 3c395d66f2ad724a8e6fed74b93634de8bfc0c0eafac94e64e5194c939499fefd6e68f047de3083ad0b4eff37df9a8a3a76349aa17d55eabbd8e0412f140a297
2 parents 0e5cff6 + 90d4d89 commit ce74799

File tree

104 files changed

+563
-563
lines changed

Some content is hidden

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

104 files changed

+563
-563
lines changed

src/addrman.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
6969
{
7070
std::map<CNetAddr, int>::iterator it = mapAddr.find(addr);
7171
if (it == mapAddr.end())
72-
return NULL;
72+
return nullptr;
7373
if (pnId)
7474
*pnId = (*it).second;
7575
std::map<int, CAddrInfo>::iterator it2 = mapInfo.find((*it).second);
7676
if (it2 != mapInfo.end())
7777
return &(*it2).second;
78-
return NULL;
78+
return nullptr;
7979
}
8080

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

src/addrman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ class CAddrMan
220220
FastRandomContext insecure_rand;
221221

222222
//! Find an entry.
223-
CAddrInfo* Find(const CNetAddr& addr, int *pnId = NULL);
223+
CAddrInfo* Find(const CNetAddr& addr, int *pnId = nullptr);
224224

225225
//! find an entry, creating it if necessary.
226226
//! nTime and nServices of the found node are updated, if necessary.
227-
CAddrInfo* Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId = NULL);
227+
CAddrInfo* Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId = nullptr);
228228

229229
//! Swap two elements in vRandom.
230230
void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2);

src/arith_uint256.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class arith_uint256 : public base_uint<256> {
283283
* complexities of the sign bit and using base 256 are probably an
284284
* implementation accident.
285285
*/
286-
arith_uint256& SetCompact(uint32_t nCompact, bool *pfNegative = NULL, bool *pfOverflow = NULL);
286+
arith_uint256& SetCompact(uint32_t nCompact, bool *pfNegative = nullptr, bool *pfOverflow = nullptr);
287287
uint32_t GetCompact(bool fNegative = false) const;
288288

289289
friend uint256 ArithToUint256(const arith_uint256 &);

src/base58.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool DecodeBase58(const char* psz, std::vector<unsigned char>& vch)
3737
while (*psz && !isspace(*psz)) {
3838
// Decode base58 character
3939
const char* ch = strchr(pszBase58, *psz);
40-
if (ch == NULL)
40+
if (ch == nullptr)
4141
return false;
4242
// Apply "b256 = b256 * 58 + ch".
4343
int carry = ch - pszBase58;

src/base58.h

Lines changed: 2 additions & 2 deletions
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
bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet);
4444

src/bench/bench.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ benchmark::BenchRunner::BenchmarkMap &benchmark::BenchRunner::benchmarks() {
1717

1818
static double gettimedouble(void) {
1919
struct timeval tv;
20-
gettimeofday(&tv, NULL);
20+
gettimeofday(&tv, nullptr);
2121
return tv.tv_usec * 0.000001 + tv.tv_sec;
2222
}
2323

src/bitcoin-cli.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ static void http_request_done(struct evhttp_request *req, void *ctx)
161161
{
162162
HTTPReply *reply = static_cast<HTTPReply*>(ctx);
163163

164-
if (req == NULL) {
165-
/* If req is NULL, it means an error occurred while connecting: the
164+
if (req == nullptr) {
165+
/* If req is nullptr, it means an error occurred while connecting: the
166166
* error code will have been passed to http_error_cb.
167167
*/
168168
reply->status = 0;
@@ -210,7 +210,7 @@ UniValue CallRPC(const std::string& strMethod, const UniValue& params)
210210

211211
HTTPReply response;
212212
raii_evhttp_request req = obtain_evhttp_request(http_request_done, (void*)&response);
213-
if (req == NULL)
213+
if (req == nullptr)
214214
throw std::runtime_error("create http request failed");
215215
#if LIBEVENT_VERSION_NUMBER >= 0x02010300
216216
evhttp_request_set_error_cb(req.get(), http_error_cb);
@@ -370,7 +370,7 @@ int CommandLineRPC(int argc, char *argv[])
370370
nRet = EXIT_FAILURE;
371371
}
372372
catch (...) {
373-
PrintExceptionContinue(NULL, "CommandLineRPC()");
373+
PrintExceptionContinue(nullptr, "CommandLineRPC()");
374374
throw;
375375
}
376376

@@ -397,7 +397,7 @@ int main(int argc, char* argv[])
397397
PrintExceptionContinue(&e, "AppInitRPC()");
398398
return EXIT_FAILURE;
399399
} catch (...) {
400-
PrintExceptionContinue(NULL, "AppInitRPC()");
400+
PrintExceptionContinue(nullptr, "AppInitRPC()");
401401
return EXIT_FAILURE;
402402
}
403403

@@ -408,7 +408,7 @@ int main(int argc, char* argv[])
408408
catch (const std::exception& e) {
409409
PrintExceptionContinue(&e, "CommandLineRPC()");
410410
} catch (...) {
411-
PrintExceptionContinue(NULL, "CommandLineRPC()");
411+
PrintExceptionContinue(nullptr, "CommandLineRPC()");
412412
}
413413
return ret;
414414
}

src/bitcoin-tx.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ static int CommandLineRawTx(int argc, char* argv[])
822822
nRet = EXIT_FAILURE;
823823
}
824824
catch (...) {
825-
PrintExceptionContinue(NULL, "CommandLineRawTx()");
825+
PrintExceptionContinue(nullptr, "CommandLineRawTx()");
826826
throw;
827827
}
828828

@@ -845,7 +845,7 @@ int main(int argc, char* argv[])
845845
PrintExceptionContinue(&e, "AppInitRawTx()");
846846
return EXIT_FAILURE;
847847
} catch (...) {
848-
PrintExceptionContinue(NULL, "AppInitRawTx()");
848+
PrintExceptionContinue(nullptr, "AppInitRawTx()");
849849
return EXIT_FAILURE;
850850
}
851851

@@ -856,7 +856,7 @@ int main(int argc, char* argv[])
856856
catch (const std::exception& e) {
857857
PrintExceptionContinue(&e, "CommandLineRawTx()");
858858
} catch (...) {
859-
PrintExceptionContinue(NULL, "CommandLineRawTx()");
859+
PrintExceptionContinue(nullptr, "CommandLineRawTx()");
860860
}
861861
return ret;
862862
}

src/bitcoind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ bool AppInit(int argc, char* argv[])
170170
catch (const std::exception& e) {
171171
PrintExceptionContinue(&e, "AppInit()");
172172
} catch (...) {
173-
PrintExceptionContinue(NULL, "AppInit()");
173+
PrintExceptionContinue(nullptr, "AppInit()");
174174
}
175175

176176
if (!fRet)

src/chain.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* CChain implementation
1010
*/
1111
void CChain::SetTip(CBlockIndex *pindex) {
12-
if (pindex == NULL) {
12+
if (pindex == nullptr) {
1313
vChain.clear();
1414
return;
1515
}
@@ -49,8 +49,8 @@ CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const {
4949
}
5050

5151
const CBlockIndex *CChain::FindFork(const CBlockIndex *pindex) const {
52-
if (pindex == NULL) {
53-
return NULL;
52+
if (pindex == nullptr) {
53+
return nullptr;
5454
}
5555
if (pindex->nHeight > Height())
5656
pindex = pindex->GetAncestor(Height());
@@ -63,7 +63,7 @@ CBlockIndex* CChain::FindEarliestAtLeast(int64_t nTime) const
6363
{
6464
std::vector<CBlockIndex*>::const_iterator lower = std::lower_bound(vChain.begin(), vChain.end(), nTime,
6565
[](CBlockIndex* pBlock, const int64_t& time) -> bool { return pBlock->GetBlockTimeMax() < time; });
66-
return (lower == vChain.end() ? NULL : *lower);
66+
return (lower == vChain.end() ? nullptr : *lower);
6767
}
6868

6969
/** Turn the lowest '1' bit in the binary representation of a number into a '0'. */
@@ -83,14 +83,14 @@ int static inline GetSkipHeight(int height) {
8383
CBlockIndex* CBlockIndex::GetAncestor(int height)
8484
{
8585
if (height > nHeight || height < 0)
86-
return NULL;
86+
return nullptr;
8787

8888
CBlockIndex* pindexWalk = this;
8989
int heightWalk = nHeight;
9090
while (heightWalk > height) {
9191
int heightSkip = GetSkipHeight(heightWalk);
9292
int heightSkipPrev = GetSkipHeight(heightWalk - 1);
93-
if (pindexWalk->pskip != NULL &&
93+
if (pindexWalk->pskip != nullptr &&
9494
(heightSkip == height ||
9595
(heightSkip > height && !(heightSkipPrev < heightSkip - 2 &&
9696
heightSkipPrev >= height)))) {
@@ -150,7 +150,7 @@ int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& fr
150150
}
151151

152152
/** Find the last common ancestor two blocks have.
153-
* Both pa and pb must be non-NULL. */
153+
* Both pa and pb must be non-nullptr. */
154154
const CBlockIndex* LastCommonAncestor(const CBlockIndex* pa, const CBlockIndex* pb) {
155155
if (pa->nHeight > pb->nHeight) {
156156
pa = pa->GetAncestor(pb->nHeight);

0 commit comments

Comments
 (0)