Fix an error in the secureRandomString function (#1816)

This commit is contained in:
An Tao 2023-10-19 19:38:17 +08:00 committed by GitHub
parent 645c2d8aaf
commit 9ffe1b267b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1229,11 +1229,11 @@ std::string secureRandomString(size_t size)
"+-";
assert(chars.size() == 64);
trantor::utils::Hash256 hash;
// batch up to 32 bytes of random data for efficiency. Calling
// secureRandomBytes can be expensive.
auto randByte = [&hash]() {
static size_t i = 0;
auto randByte = []() {
thread_local trantor::utils::Hash256 hash;
thread_local size_t i = 0;
if (i == 0)
{
bool ok = trantor::utils::secureRandomBytes(&hash, sizeof(hash));