aboutsummaryrefslogtreecommitdiff
path: root/src/randomenv.cpp
diff options
context:
space:
mode:
authorEthan Heilman <ethan.r.heilman@gmail.com>2020-10-04 21:07:51 -0400
committerEthan Heilman <ethan.r.heilman@gmail.com>2020-10-07 20:46:49 -0400
commitbd5215103eb3985c1622eddea45a040e6173829c (patch)
tree6563c6c006ebb5033b4ed0f37346da1c0b94fdd5 /src/randomenv.cpp
parentcce151317909ab8eb56d3e5da522f43c7d7db077 (diff)
downloadbitcoin-bd5215103eb3985c1622eddea45a040e6173829c.tar.xz
random: fixes read buffer resizing in RandAddSeedPerfmon
+ Replaces std::max with std::min to resize buffer in RandAddSeedPerfmon + Documents behavior of RandAddSeedPerfmon
Diffstat (limited to 'src/randomenv.cpp')
-rw-r--r--src/randomenv.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/randomenv.cpp b/src/randomenv.cpp
index 073d82b491..07122b7f6d 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<std::chrono::seconds> last_perfmon{std::chrono::seconds{0}};
auto last_time = last_perfmon.load();
auto current_time = GetTime<std::chrono::seconds>();
@@ -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) {