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

refactor: misc style changes #2177

Merged
merged 5 commits into from
Jun 19, 2021
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
16 changes: 8 additions & 8 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,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);
*pnId = it->second;
std::map<int, CAddrInfo>::iterator it2 = mapInfo.find(it->second);
if (it2 != mapInfo.end())
return &(*it2).second;
return NULL;
return &it2->second;
return nullptr;
}

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

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

Expand Down
10 changes: 5 additions & 5 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ class CAddrMan
protected:

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

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

// Swap two elements in vRandom.
void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2);
Expand Down Expand Up @@ -287,8 +287,8 @@ class CAddrMan
int nIds = 0;
for (std::map<int, CAddrInfo>::const_iterator it = mapInfo.begin(); it != mapInfo.end(); it++) {
if (nIds == nNew) break; // this means nNew was wrong, oh ow
mapUnkIds[(*it).first] = nIds;
const CAddrInfo &info = (*it).second;
mapUnkIds[it->first] = nIds;
const CAddrInfo& info = it->second;
if (info.nRefCount) {
s << info;
nIds++;
Expand All @@ -297,7 +297,7 @@ class CAddrMan
nIds = 0;
for (std::map<int, CAddrInfo>::const_iterator it = mapInfo.begin(); it != mapInfo.end(); it++) {
if (nIds == nTried) break; // this means nTried was wrong, oh ow
const CAddrInfo &info = (*it).second;
const CAddrInfo& info = it->second;
if (info.fInTried) {
s << info;
nIds++;
Expand Down
6 changes: 3 additions & 3 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,17 @@ bool CAlert::ProcessAlert(bool fThread)
// Cancel previous alerts
for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();)
{
const CAlert& alert = (*mi).second;
const CAlert& alert = mi->second;
if (Cancels(alert))
{
LogPrint(BCLog::LogFlags::VERBOSE, "cancelling alert %d", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
uiInterface.NotifyAlertChanged(mi->first, CT_DELETED);
mapAlerts.erase(mi++);
}
else if (!alert.IsInEffect())
{
LogPrint(BCLog::LogFlags::VERBOSE, "expiring alert %d", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
uiInterface.NotifyAlertChanged(mi->first, CT_DELETED);
mapAlerts.erase(mi++);
}
else
Expand Down
6 changes: 3 additions & 3 deletions src/banman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool BanMan::IsBanned(CSubNet sub_net)
LOCK(m_cs_banned);
banmap_t::iterator i = m_banned.find(sub_net);
if (i != m_banned.end()) {
CBanEntry ban_entry = (*i).second;
CBanEntry ban_entry = i->second;
if (current_time < ban_entry.nBanUntil) {
return true;
}
Expand Down Expand Up @@ -199,8 +199,8 @@ void BanMan::SweepBanned()
LOCK(m_cs_banned);
banmap_t::iterator it = m_banned.begin();
while (it != m_banned.end()) {
CSubNet sub_net = (*it).first;
CBanEntry ban_entry = (*it).second;
CSubNet sub_net = it->first;
CBanEntry ban_entry = it->second;
if (now > ban_entry.nBanUntil) {
m_banned.erase(it++);

Expand Down
3 changes: 1 addition & 2 deletions src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ inline bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet)
for (const char* p = psz; *p; p++)
{
const char* p1 = strchr(pszBase58, *p);
if (p1 == NULL)
{
if (p1 == nullptr) {
while (isspace(*p))
p++;
if (*p != '\0')
Expand Down
26 changes: 13 additions & 13 deletions src/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ class CAutoBN_CTX
CAutoBN_CTX()
{
pctx = BN_CTX_new();
if (pctx == NULL)
throw bignum_error("CAutoBN_CTX : BN_CTX_new() returned NULL");
if (pctx == nullptr)
throw bignum_error("CAutoBN_CTX : BN_CTX_new() returned nullptr");
}

~CAutoBN_CTX()
{
if (pctx != NULL)
if (pctx != nullptr)
BN_CTX_free(pctx);
}

operator BN_CTX*() { return pctx; }
BN_CTX& operator*() { return *pctx; }
BN_CTX** operator&() { return &pctx; }
bool operator!() { return (pctx == NULL); }
bool operator!() { return (pctx == nullptr); }
};

/* RAII wrapper for BIGNUM instance */
Expand All @@ -62,8 +62,8 @@ class CBigNumBase
CBigNumBase()
: pbn(BN_new())
{
if (pbn == NULL)
throw bignum_error("CBigNum : BN_new() returned NULL");
if (pbn == nullptr)
throw bignum_error("CBigNum : BN_new() returned nullptr");
}

~CBigNumBase()
Expand Down Expand Up @@ -214,7 +214,7 @@ class CBigNum : public CBigNumBase

uint64_t getuint64()
{
unsigned int nSize = BN_bn2mpi(pbn, NULL);
unsigned int nSize = BN_bn2mpi(pbn, nullptr);
if (nSize < 4)
return 0;
std::vector<unsigned char> vch(nSize);
Expand Down Expand Up @@ -284,7 +284,7 @@ class CBigNum : public CBigNumBase

uint256 getuint256() const
{
unsigned int nSize = BN_bn2mpi(pbn, NULL);
unsigned int nSize = BN_bn2mpi(pbn, nullptr);
if (nSize < 4)
return uint256();
std::vector<unsigned char> vch(nSize);
Expand Down Expand Up @@ -315,7 +315,7 @@ class CBigNum : public CBigNumBase

std::vector<unsigned char> getvch() const
{
unsigned int nSize = BN_bn2mpi(pbn, NULL);
unsigned int nSize = BN_bn2mpi(pbn, nullptr);
if (nSize <= 4)
return std::vector<unsigned char>();
std::vector<unsigned char> vch(nSize);
Expand All @@ -339,7 +339,7 @@ class CBigNum : public CBigNumBase

unsigned int GetCompact() const
{
unsigned int nSize = BN_bn2mpi(pbn, NULL);
unsigned int nSize = BN_bn2mpi(pbn, nullptr);
std::vector<unsigned char> vch(nSize);
nSize -= 4;
BN_bn2mpi(pbn, &vch[0]);
Expand Down Expand Up @@ -504,7 +504,7 @@ class CBigNum : public CBigNumBase
*/
static CBigNum generatePrime(const unsigned int numBits, bool safe = false) {
CBigNum ret;
if(!BN_generate_prime_ex(&ret, numBits, safe, NULL, NULL, NULL))
if (!BN_generate_prime_ex(&ret, numBits, safe, nullptr, nullptr, nullptr))
throw bignum_error("CBigNum::generatePrime*= :BN_generate_prime_ex");
return ret;
}
Expand All @@ -530,7 +530,7 @@ class CBigNum : public CBigNumBase
*/
bool isPrime(const int checks=BN_prime_checks) const {
CAutoBN_CTX pctx;
int ret = BN_is_prime_ex(pbn, checks, pctx, NULL);
int ret = BN_is_prime_ex(pbn, checks, pctx, nullptr);
if(ret < 0){
throw bignum_error("CBigNum::isPrime :BN_is_prime_ex");
}
Expand Down Expand Up @@ -688,7 +688,7 @@ inline const CBigNum operator/(const CBigNum& a, const CBigNum& b)
{
CAutoBN_CTX pctx;
CBigNum r;
if (!BN_div(&r, NULL, &a, &b, pctx))
if (!BN_div(&r, nullptr, &a, &b, pctx))
throw bignum_error("CBigNum::operator/ : BN_div failed");
return r;
}
Expand Down
4 changes: 2 additions & 2 deletions src/crypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector<unsigned
if(!ctx)
throw std::runtime_error("Error allocating cipher context");

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

if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, vchKey.data(), vchIV.data());
if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, vchKey.data(), vchIV.data());
if (fOk) fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen);
if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0])+nPLen, &nFLen);
EVP_CIPHER_CTX_free(ctx);
Expand Down
8 changes: 4 additions & 4 deletions src/gridcoin/scraper/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ std::string Http::GetEtag(
const std::string &url,
const std::string &userpass)
{
struct curl_slist* headers = NULL;
struct curl_slist* headers = nullptr;
headers = curl_slist_append(headers, "Accept: */*");
headers = curl_slist_append(headers, "User-Agent: curl/7.63.0");
std::string header;
Expand Down Expand Up @@ -272,7 +272,7 @@ std::string Http::GetLatestVersionResponse()
std::string header;
std::string url = gArgs.GetArg("-updatecheckurl", "https://api.github.com/repos/gridcoin-community/Gridcoin-Research/releases/latest");

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

Expand Down Expand Up @@ -318,7 +318,7 @@ void Http::DownloadSnapshot()
std::string buffer;
std::string header;

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/scraper/scraper_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ int CSplitBlob::addPartData(CDataStream&& vData)
/* missing data; use the supplied data */
/* prevent calling the Complete callback FIXME: make this look better */
cntPartsRcvd--;
CSplitBlob::RecvPart(0, vData);
CSplitBlob::RecvPart(nullptr, vData);
cntPartsRcvd++;
}
return n;
Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/staking/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static bool SelectBlockFromCandidates(
{
bool fSelected = false;
arith_uint256 hashBest = 0;
*pindexSelected = (const CBlockIndex*) 0;
*pindexSelected = nullptr;

for (auto const& item : vSortedByTimestamp)
{
Expand Down
4 changes: 2 additions & 2 deletions src/gridcoinresearchd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ bool AppInit(int argc, char* argv[])
} catch (...) {
LogPrintf("AppInit()Exception2");

PrintException(NULL, "AppInit()");
PrintException(nullptr, "AppInit()");
}
if(fRet)
{
while (!ShutdownRequested())
MilliSleep(500);
}

Shutdown(NULL);
Shutdown(nullptr);

// delete thread handler
threads->interruptAll();
Expand Down
10 changes: 5 additions & 5 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ bool AppInit2(ThreadHandlerPtr threads)
#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 @@ -746,7 +746,7 @@ bool AppInit2(ThreadHandlerPtr threads)
#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
#ifndef WIN32
umask(077);
Expand Down Expand Up @@ -1188,10 +1188,10 @@ bool AppInit2(ThreadHandlerPtr threads)
int nFound = 0;
for (BlockMap::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
{
uint256 hash = (*mi).first;
uint256 hash = mi->first;
if (strncmp(hash.ToString().c_str(), strMatch.c_str(), strMatch.size()) == 0)
{
CBlockIndex* pindex = (*mi).second;
CBlockIndex* pindex = mi->second;
CBlock block;
block.ReadFromDisk(pindex);
block.print();
Expand Down Expand Up @@ -1381,7 +1381,7 @@ bool AppInit2(ThreadHandlerPtr threads)
LogPrintf("mapAddressBook.size() = %" PRIszu, pwalletMain->mapAddressBook.size());
}

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

if (fServer) StartRPCThreads();
Expand Down
Loading