system: improve handling around GetTotalRAM()
What changed, and why it matters
This is a minor code cleanup and portability improvement. It silences a compiler warning about an unused helper function and expands the list of operating systems where Bitcoin Core can query total system RAM. There is no security bug being fixed here.
No security action required. Treat as routine maintenance/portability patch.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit marks a lambda clamp as [[maybe_unused]] to suppress an unused-variable warning that occurs on platforms where the function body does not use it. It also reorders and expands the preprocessor guard for GetTotalRAM() to include FreeBSD, NetBSD, OpenBSD, and illumos alongside Apple and Linux. The implementation logic is unchanged.
Changed components
src/common/system.cpp::GetTotalRAM()Inspect captured patch +7 / −2
diff --git a/src/common/system.cpp b/src/common/system.cpp
index cf032adf..35a6f441 100644
--- a/src/common/system.cpp
+++ b/src/common/system.cpp
@@ -113,10 +113,15 @@ int GetNumCores()
std::optional<size_t> GetTotalRAM()
{
- auto clamp{[](uint64_t v) { return size_t(std::min(v, uint64_t{std::numeric_limits<size_t>::max()})); }};
+ [[maybe_unused]] auto clamp{[](uint64_t v) { return size_t(std::min(v, uint64_t{std::numeric_limits<size_t>::max()})); }};
#ifdef WIN32
if (MEMORYSTATUSEX m{}; (m.dwLength = sizeof(m), GlobalMemoryStatusEx(&m))) return clamp(m.ullTotalPhys);
-#elif defined(__linux__) || defined(__APPLE__)
+#elif defined(__APPLE__) || \
+ defined(__FreeBSD__) || \
+ defined(__NetBSD__) || \
+ defined(__OpenBSD__) || \
+ defined(__illumos__) || \
+ defined(__linux__)
if (long p{sysconf(_SC_PHYS_PAGES)}, s{sysconf(_SC_PAGESIZE)}; p > 0 && s > 0) return clamp(1ULL * p * s);
#endif
return std::nullopt;
Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.