Skip to content

Commit bd52151

Browse files
committed
random: fixes read buffer resizing in RandAddSeedPerfmon
+ Replaces std::max with std::min to resize buffer in RandAddSeedPerfmon + Documents behavior of RandAddSeedPerfmon
1 parent cce1513 commit bd52151

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/randomenv.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ void RandAddSeedPerfmon(CSHA512& hasher)
6767
#ifdef WIN32
6868
// Seed with the entire set of perfmon data
6969

70-
// This can take up to 2 seconds, so only do it every 10 minutes
70+
// This can take up to 2 seconds, so only do it every 10 minutes.
71+
// Initialize last_perfmon to 0 seconds, we don't skip the first call.
7172
static std::atomic<std::chrono::seconds> last_perfmon{std::chrono::seconds{0}};
7273
auto last_time = last_perfmon.load();
7374
auto current_time = GetTime<std::chrono::seconds>();
@@ -83,7 +84,7 @@ void RandAddSeedPerfmon(CSHA512& hasher)
8384
ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", nullptr, nullptr, vData.data(), &nSize);
8485
if (ret != ERROR_MORE_DATA || vData.size() >= nMaxSize)
8586
break;
86-
vData.resize(std::max((vData.size() * 3) / 2, nMaxSize)); // Grow size of buffer exponentially
87+
vData.resize(std::min((vData.size() * 3) / 2, nMaxSize)); // Grow size of buffer exponentially
8788
}
8889
RegCloseKey(HKEY_PERFORMANCE_DATA);
8990
if (ret == ERROR_SUCCESS) {

0 commit comments

Comments
 (0)