From 1f67a30e8374951997af924293c60eff56ae39ed Mon Sep 17 00:00:00 2001 From: Ethan Heilman Date: Sun, 4 Oct 2020 21:07:51 -0400 Subject: random: fixes read buffer resizing in RandAddSeedPerfmon + Replaces std::max with std::min to resize buffer in RandAddSeedPerfmon + Documents behavior of RandAddSeedPerfmon Github-Pull: #20082 Rebased-From: bd5215103eb3985c1622eddea45a040e6173829c --- src/randomenv.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/randomenv.cpp b/src/randomenv.cpp index 8b3d478529..d04f80d06a 100644 --- a/src/randomenv.cpp +++ b/src/randomenv.cpp @@ -67,7 +67,8 @@ void RandAddSeedPerfmon(CSHA512& hasher) #ifdef WIN32 // Seed with the entire set of perfmon data - // This can take up to 2 seconds, so only do it every 10 minutes + // This can take up to 2 seconds, so only do it every 10 minutes. + // Initialize last_perfmon to 0 seconds, we don't skip the first call. static std::atomic last_perfmon{std::chrono::seconds{0}}; auto last_time = last_perfmon.load(); auto current_time = GetTime(); @@ -83,7 +84,7 @@ void RandAddSeedPerfmon(CSHA512& hasher) ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", nullptr, nullptr, vData.data(), &nSize); if (ret != ERROR_MORE_DATA || vData.size() >= nMaxSize) break; - vData.resize(std::max((vData.size() * 3) / 2, nMaxSize)); // Grow size of buffer exponentially + vData.resize(std::min((vData.size() * 3) / 2, nMaxSize)); // Grow size of buffer exponentially } RegCloseKey(HKEY_PERFORMANCE_DATA); if (ret == ERROR_SUCCESS) { -- cgit v1.2.3