C++20 modernization: nullptr, constexpr, smart pointers, thread safety, enum class

- Replace ~320 NULL occurrences with nullptr across 47 files (-184 net lines)
- static const -> constexpr for version, coin, utility constants
- Collapse 9 PushMessage overloads into 1 variadic template with fold expressions
- Convert boost::array -> std::array, boost::type_traits -> std:: equivalents
- pwalletMain, pScriptCheckQueue, pScriptCheckThreads -> unique_ptr
- mapOrphanBlocks values: raw CBlock* -> unique_ptr<CBlock>
- Fix data races: add locks to wallet registration, pindexBest reads, mempool exists
- pwalletdbEncryption: raw new/delete -> local unique_ptr, remove exit() calls
- PoS reward overflow: CBigNum intermediate for nCoinAge * nRewardCoinYear
- memset -> OPENSSL_cleanse for secure zeroing
- Fix const-cast UB in SetMerkleBranch
- Log silent catch(...) blocks instead of silently swallowing
- Enum class: GetMinFeeMode, WalletFeature
- std::string_view for 8 utility function parameters
- Range-for with structured bindings: 63 iterator loops modernized
- std::make_pair -> brace init: 35 sites
- Delegating constructors: CWallet, CBlockIndex
- Merkle tree caching, std::array for GetMedianTimePast
- CScript copy ctor -> = default, operator!= -> = default
This commit is contained in:
2026-05-08 21:34:24 -07:00
parent 47e358dc18
commit 150828b806
47 changed files with 747 additions and 931 deletions
+12 -12
View File
@@ -44,7 +44,7 @@ static std::string strRPCUserColonPass;
const Object emptyobj;
CNotificationQueue* pNotificationQueue = NULL;
CNotificationQueue* pNotificationQueue = nullptr;
void ThreadRPCServer3(void* parg);
@@ -367,7 +367,7 @@ const CRPCCommand *CRPCTable::operator[](string name) const
{
map<string, const CRPCCommand*>::const_iterator it = mapCommands.find(name);
if (it == mapCommands.end())
return NULL;
return nullptr;
return (*it).second;
}
@@ -401,7 +401,7 @@ string rfc1123Time()
time_t now;
time(&now);
struct tm* now_gmt = gmtime(&now);
string locale(setlocale(LC_TIME, NULL));
string locale(setlocale(LC_TIME, nullptr));
setlocale(LC_TIME, "C"); // we want POSIX (aka "C") weekday/month strings
strftime(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S +0000", now_gmt);
setlocale(LC_TIME, locale.c_str());
@@ -466,7 +466,7 @@ int ReadHTTPStatus(std::basic_istream<char>& stream, int &proto,
return HTTP_INTERNAL_SERVER_ERROR;
proto = 0;
const char *ver = strstr(str.c_str(), "HTTP/1.");
if (ver != NULL)
if (ver != nullptr)
proto = atoi(ver+7);
// Detect request line (GET/POST/...) vs response line (HTTP/1.x ...)
@@ -741,7 +741,7 @@ void ThreadRPCServer(void* parg)
PrintException(&e, "ThreadRPCServer()");
} catch (...) {
vnThreadsRunning[THREAD_RPCLISTENER]--;
PrintException(NULL, "ThreadRPCServer()");
PrintException(nullptr, "ThreadRPCServer()");
}
printf("ThreadRPCServer exited\n");
}
@@ -1483,7 +1483,7 @@ int CommandLineRPC(int argc, char *argv[])
}
catch (...)
{
PrintException(NULL, "CommandLineRPC()");
PrintException(nullptr, "CommandLineRPC()");
}
if (strPrint != "")
@@ -1502,18 +1502,18 @@ int main(int argc, char *argv[])
#ifdef _MSC_VER
// Turn off Microsoft heap dump noise
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, CreateFile("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0));
_CrtSetReportFile(_CRT_WARN, CreateFile("NUL", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, 0));
#endif
setbuf(stdin, NULL);
setbuf(stdout, NULL);
setbuf(stderr, NULL);
setbuf(stdin, nullptr);
setbuf(stdout, nullptr);
setbuf(stderr, nullptr);
try
{
if (argc >= 2 && string(argv[1]) == "-server")
{
printf("server ready\n");
ThreadRPCServer(NULL);
ThreadRPCServer(nullptr);
}
else
{
@@ -1523,7 +1523,7 @@ int main(int argc, char *argv[])
catch (std::exception& e) {
PrintException(&e, "main()");
} catch (...) {
PrintException(NULL, "main()");
PrintException(nullptr, "main()");
}
return 0;
}