Skip to content

Commit 954ed72

Browse files
authored
Merge pull request #2177 from div72/misc
refactor: misc style changes
2 parents d0a85a6 + f18eda2 commit 954ed72

File tree

115 files changed

+760
-726
lines changed

Some content is hidden

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

115 files changed

+760
-726
lines changed

src/addrman.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int *pnId)
8282
{
8383
std::map<CNetAddr, int>::iterator it = mapAddr.find(addr);
8484
if (it == mapAddr.end())
85-
return NULL;
85+
return nullptr;
8686
if (pnId)
87-
*pnId = (*it).second;
88-
std::map<int, CAddrInfo>::iterator it2 = mapInfo.find((*it).second);
87+
*pnId = it->second;
88+
std::map<int, CAddrInfo>::iterator it2 = mapInfo.find(it->second);
8989
if (it2 != mapInfo.end())
90-
return &(*it2).second;
91-
return NULL;
90+
return &it2->second;
91+
return nullptr;
9292
}
9393

9494
CAddrInfo* CAddrMan::Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId)
@@ -208,7 +208,7 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId, int nOrigin)
208208
// remove the entry from all new buckets
209209
for (std::vector<std::set<int> >::iterator it = vvNew.begin(); it != vvNew.end(); it++)
210210
{
211-
if ((*it).erase(nId))
211+
if (it->erase(nId))
212212
info.nRefCount--;
213213
}
214214
nNew--;
@@ -438,8 +438,8 @@ int CAddrMan::Check_()
438438

439439
for (std::map<int, CAddrInfo>::iterator it = mapInfo.begin(); it != mapInfo.end(); it++)
440440
{
441-
int n = (*it).first;
442-
CAddrInfo &info = (*it).second;
441+
int n = it->first;
442+
CAddrInfo& info = it->second;
443443
if (info.fInTried)
444444
{
445445

src/addrman.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ class CAddrMan
201201
protected:
202202

203203
// Find an entry.
204-
CAddrInfo* Find(const CNetAddr& addr, int *pnId = NULL);
204+
CAddrInfo* Find(const CNetAddr& addr, int* pnId = nullptr);
205205

206206
// find an entry, creating it if necessary.
207207
// nTime and nServices of found node is updated, if necessary.
208-
CAddrInfo* Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId = NULL);
208+
CAddrInfo* Create(const CAddress& addr, const CNetAddr& addrSource, int* pnId = nullptr);
209209

210210
// Swap two elements in vRandom.
211211
void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2);
@@ -287,8 +287,8 @@ class CAddrMan
287287
int nIds = 0;
288288
for (std::map<int, CAddrInfo>::const_iterator it = mapInfo.begin(); it != mapInfo.end(); it++) {
289289
if (nIds == nNew) break; // this means nNew was wrong, oh ow
290-
mapUnkIds[(*it).first] = nIds;
291-
const CAddrInfo &info = (*it).second;
290+
mapUnkIds[it->first] = nIds;
291+
const CAddrInfo& info = it->second;
292292
if (info.nRefCount) {
293293
s << info;
294294
nIds++;
@@ -297,7 +297,7 @@ class CAddrMan
297297
nIds = 0;
298298
for (std::map<int, CAddrInfo>::const_iterator it = mapInfo.begin(); it != mapInfo.end(); it++) {
299299
if (nIds == nTried) break; // this means nTried was wrong, oh ow
300-
const CAddrInfo &info = (*it).second;
300+
const CAddrInfo& info = it->second;
301301
if (info.fInTried) {
302302
s << info;
303303
nIds++;

src/alert.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,17 @@ bool CAlert::ProcessAlert(bool fThread)
231231
// Cancel previous alerts
232232
for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();)
233233
{
234-
const CAlert& alert = (*mi).second;
234+
const CAlert& alert = mi->second;
235235
if (Cancels(alert))
236236
{
237237
LogPrint(BCLog::LogFlags::VERBOSE, "cancelling alert %d", alert.nID);
238-
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
238+
uiInterface.NotifyAlertChanged(mi->first, CT_DELETED);
239239
mapAlerts.erase(mi++);
240240
}
241241
else if (!alert.IsInEffect())
242242
{
243243
LogPrint(BCLog::LogFlags::VERBOSE, "expiring alert %d", alert.nID);
244-
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
244+
uiInterface.NotifyAlertChanged(mi->first, CT_DELETED);
245245
mapAlerts.erase(mi++);
246246
}
247247
else

src/banman.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ bool BanMan::IsBanned(CSubNet sub_net)
116116
LOCK(m_cs_banned);
117117
banmap_t::iterator i = m_banned.find(sub_net);
118118
if (i != m_banned.end()) {
119-
CBanEntry ban_entry = (*i).second;
119+
CBanEntry ban_entry = i->second;
120120
if (current_time < ban_entry.nBanUntil) {
121121
return true;
122122
}
@@ -199,8 +199,8 @@ void BanMan::SweepBanned()
199199
LOCK(m_cs_banned);
200200
banmap_t::iterator it = m_banned.begin();
201201
while (it != m_banned.end()) {
202-
CSubNet sub_net = (*it).first;
203-
CBanEntry ban_entry = (*it).second;
202+
CSubNet sub_net = it->first;
203+
CBanEntry ban_entry = it->second;
204204
if (now > ban_entry.nBanUntil) {
205205
m_banned.erase(it++);
206206

src/base58.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ inline bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet)
8888
for (const char* p = psz; *p; p++)
8989
{
9090
const char* p1 = strchr(pszBase58, *p);
91-
if (p1 == NULL)
92-
{
91+
if (p1 == nullptr) {
9392
while (isspace(*p))
9493
p++;
9594
if (*p != '\0')

src/bignum.h

+13-13
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ class CAutoBN_CTX
3636
CAutoBN_CTX()
3737
{
3838
pctx = BN_CTX_new();
39-
if (pctx == NULL)
40-
throw bignum_error("CAutoBN_CTX : BN_CTX_new() returned NULL");
39+
if (pctx == nullptr)
40+
throw bignum_error("CAutoBN_CTX : BN_CTX_new() returned nullptr");
4141
}
4242

4343
~CAutoBN_CTX()
4444
{
45-
if (pctx != NULL)
45+
if (pctx != nullptr)
4646
BN_CTX_free(pctx);
4747
}
4848

4949
operator BN_CTX*() { return pctx; }
5050
BN_CTX& operator*() { return *pctx; }
5151
BN_CTX** operator&() { return &pctx; }
52-
bool operator!() { return (pctx == NULL); }
52+
bool operator!() { return (pctx == nullptr); }
5353
};
5454

5555
/* RAII wrapper for BIGNUM instance */
@@ -62,8 +62,8 @@ class CBigNumBase
6262
CBigNumBase()
6363
: pbn(BN_new())
6464
{
65-
if (pbn == NULL)
66-
throw bignum_error("CBigNum : BN_new() returned NULL");
65+
if (pbn == nullptr)
66+
throw bignum_error("CBigNum : BN_new() returned nullptr");
6767
}
6868

6969
~CBigNumBase()
@@ -214,7 +214,7 @@ class CBigNum : public CBigNumBase
214214

215215
uint64_t getuint64()
216216
{
217-
unsigned int nSize = BN_bn2mpi(pbn, NULL);
217+
unsigned int nSize = BN_bn2mpi(pbn, nullptr);
218218
if (nSize < 4)
219219
return 0;
220220
std::vector<unsigned char> vch(nSize);
@@ -284,7 +284,7 @@ class CBigNum : public CBigNumBase
284284

285285
uint256 getuint256() const
286286
{
287-
unsigned int nSize = BN_bn2mpi(pbn, NULL);
287+
unsigned int nSize = BN_bn2mpi(pbn, nullptr);
288288
if (nSize < 4)
289289
return uint256();
290290
std::vector<unsigned char> vch(nSize);
@@ -315,7 +315,7 @@ class CBigNum : public CBigNumBase
315315

316316
std::vector<unsigned char> getvch() const
317317
{
318-
unsigned int nSize = BN_bn2mpi(pbn, NULL);
318+
unsigned int nSize = BN_bn2mpi(pbn, nullptr);
319319
if (nSize <= 4)
320320
return std::vector<unsigned char>();
321321
std::vector<unsigned char> vch(nSize);
@@ -339,7 +339,7 @@ class CBigNum : public CBigNumBase
339339

340340
unsigned int GetCompact() const
341341
{
342-
unsigned int nSize = BN_bn2mpi(pbn, NULL);
342+
unsigned int nSize = BN_bn2mpi(pbn, nullptr);
343343
std::vector<unsigned char> vch(nSize);
344344
nSize -= 4;
345345
BN_bn2mpi(pbn, &vch[0]);
@@ -504,7 +504,7 @@ class CBigNum : public CBigNumBase
504504
*/
505505
static CBigNum generatePrime(const unsigned int numBits, bool safe = false) {
506506
CBigNum ret;
507-
if(!BN_generate_prime_ex(&ret, numBits, safe, NULL, NULL, NULL))
507+
if (!BN_generate_prime_ex(&ret, numBits, safe, nullptr, nullptr, nullptr))
508508
throw bignum_error("CBigNum::generatePrime*= :BN_generate_prime_ex");
509509
return ret;
510510
}
@@ -530,7 +530,7 @@ class CBigNum : public CBigNumBase
530530
*/
531531
bool isPrime(const int checks=BN_prime_checks) const {
532532
CAutoBN_CTX pctx;
533-
int ret = BN_is_prime_ex(pbn, checks, pctx, NULL);
533+
int ret = BN_is_prime_ex(pbn, checks, pctx, nullptr);
534534
if(ret < 0){
535535
throw bignum_error("CBigNum::isPrime :BN_is_prime_ex");
536536
}
@@ -688,7 +688,7 @@ inline const CBigNum operator/(const CBigNum& a, const CBigNum& b)
688688
{
689689
CAutoBN_CTX pctx;
690690
CBigNum r;
691-
if (!BN_div(&r, NULL, &a, &b, pctx))
691+
if (!BN_div(&r, nullptr, &a, &b, pctx))
692692
throw bignum_error("CBigNum::operator/ : BN_div failed");
693693
return r;
694694
}

src/crypter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector<unsigned
7373
if(!ctx)
7474
throw std::runtime_error("Error allocating cipher context");
7575

76-
if (fOk) fOk = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, vchKey.data(), vchIV.data());
76+
if (fOk) fOk = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, vchKey.data(), vchIV.data());
7777
if (fOk) fOk = EVP_EncryptUpdate(ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen);
7878
if (fOk) fOk = EVP_EncryptFinal_ex(ctx, (&vchCiphertext[0])+nCLen, &nFLen);
7979
EVP_CIPHER_CTX_free(ctx);
@@ -101,7 +101,7 @@ bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingM
101101
if(!ctx)
102102
throw std::runtime_error("Error allocating cipher context");
103103

104-
if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, vchKey.data(), vchIV.data());
104+
if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, vchKey.data(), vchIV.data());
105105
if (fOk) fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen);
106106
if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0])+nPLen, &nFLen);
107107
EVP_CIPHER_CTX_free(ctx);

src/gridcoin/scraper/http.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ std::string Http::GetEtag(
224224
const std::string &url,
225225
const std::string &userpass)
226226
{
227-
struct curl_slist* headers = NULL;
227+
struct curl_slist* headers = nullptr;
228228
headers = curl_slist_append(headers, "Accept: */*");
229229
headers = curl_slist_append(headers, "User-Agent: curl/7.63.0");
230230
std::string header;
@@ -272,7 +272,7 @@ std::string Http::GetLatestVersionResponse()
272272
std::string header;
273273
std::string url = gArgs.GetArg("-updatecheckurl", "https://api.github.com/repos/gridcoin-community/Gridcoin-Research/releases/latest");
274274

275-
struct curl_slist* headers = NULL;
275+
struct curl_slist* headers = nullptr;
276276
headers = curl_slist_append(headers, "Accept: */*");
277277
headers = curl_slist_append(headers, "User-Agent: curl/7.63.0");
278278

@@ -318,7 +318,7 @@ void Http::DownloadSnapshot()
318318
std::string buffer;
319319
std::string header;
320320

321-
struct curl_slist* headers = NULL;
321+
struct curl_slist* headers = nullptr;
322322
headers = curl_slist_append(headers, "Accept: */*");
323323
headers = curl_slist_append(headers, "User-Agent: curl/7.63.0");
324324

@@ -385,7 +385,7 @@ std::string Http::GetSnapshotSHA256()
385385
std::string header;
386386
std::string url = gArgs.GetArg("-snapshotsha256url", "https://snapshot.gridcoin.us/snapshot.zip.sha256");
387387

388-
struct curl_slist* headers = NULL;
388+
struct curl_slist* headers = nullptr;
389389
headers = curl_slist_append(headers, "Accept: */*");
390390
headers = curl_slist_append(headers, "User-Agent: curl/7.63.0");
391391

src/gridcoin/scraper/scraper_net.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int CSplitBlob::addPartData(CDataStream&& vData)
126126
/* missing data; use the supplied data */
127127
/* prevent calling the Complete callback FIXME: make this look better */
128128
cntPartsRcvd--;
129-
CSplitBlob::RecvPart(0, vData);
129+
CSplitBlob::RecvPart(nullptr, vData);
130130
cntPartsRcvd++;
131131
}
132132
return n;

src/gridcoin/staking/kernel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static bool SelectBlockFromCandidates(
222222
{
223223
bool fSelected = false;
224224
arith_uint256 hashBest = 0;
225-
*pindexSelected = (const CBlockIndex*) 0;
225+
*pindexSelected = nullptr;
226226

227227
for (auto const& item : vSortedByTimestamp)
228228
{

src/gridcoinresearchd.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ bool AppInit(int argc, char* argv[])
209209
} catch (...) {
210210
LogPrintf("AppInit()Exception2");
211211

212-
PrintException(NULL, "AppInit()");
212+
PrintException(nullptr, "AppInit()");
213213
}
214214
if(fRet)
215215
{
216216
while (!ShutdownRequested())
217217
MilliSleep(500);
218218
}
219219

220-
Shutdown(NULL);
220+
Shutdown(nullptr);
221221

222222
// delete thread handler
223223
threads->interruptAll();

src/init.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ bool AppInit2(ThreadHandlerPtr threads)
729729
#ifdef _MSC_VER
730730
// Turn off Microsoft heap dump noise
731731
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
732-
_CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0));
732+
_CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, 0));
733733
#endif
734734
#if _MSC_VER >= 1400
735735
// Disable confusing "helpful" text message on abort, Ctrl-C
@@ -746,7 +746,7 @@ bool AppInit2(ThreadHandlerPtr threads)
746746
#endif
747747
typedef BOOL (WINAPI *PSETPROCDEPPOL)(DWORD);
748748
PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy");
749-
if (setProcDEPPol != NULL) setProcDEPPol(PROCESS_DEP_ENABLE);
749+
if (setProcDEPPol != nullptr) setProcDEPPol(PROCESS_DEP_ENABLE);
750750
#endif
751751
#ifndef WIN32
752752
umask(077);
@@ -1188,10 +1188,10 @@ bool AppInit2(ThreadHandlerPtr threads)
11881188
int nFound = 0;
11891189
for (BlockMap::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
11901190
{
1191-
uint256 hash = (*mi).first;
1191+
uint256 hash = mi->first;
11921192
if (strncmp(hash.ToString().c_str(), strMatch.c_str(), strMatch.size()) == 0)
11931193
{
1194-
CBlockIndex* pindex = (*mi).second;
1194+
CBlockIndex* pindex = mi->second;
11951195
CBlock block;
11961196
block.ReadFromDisk(pindex);
11971197
block.print();
@@ -1381,7 +1381,7 @@ bool AppInit2(ThreadHandlerPtr threads)
13811381
LogPrintf("mapAddressBook.size() = %" PRIszu, pwalletMain->mapAddressBook.size());
13821382
}
13831383

1384-
if (!threads->createThread(StartNode, NULL, "Start Thread"))
1384+
if (!threads->createThread(StartNode, nullptr, "Start Thread"))
13851385
InitError(_("Error: could not start node"));
13861386

13871387
if (fServer) StartRPCThreads();

0 commit comments

Comments
 (0)