Skip to content

Commit f63cf49

Browse files
committed
Remove thread_local in dllexported function
1 parent 294035b commit f63cf49

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

lib/src/Utilities.cc

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,24 +1272,20 @@ std::string secureRandomString(size_t size)
12721272

12731273
// batch up to 32 bytes of random data for efficiency. Calling
12741274
// secureRandomBytes can be expensive.
1275-
auto randByte = []() {
1276-
thread_local trantor::utils::Hash256 hash;
1277-
thread_local size_t i = 0;
1278-
if (i == 0)
1275+
trantor::utils::Hash256 hash;
1276+
for (size_t i = 0; i < size; ++i)
1277+
{
1278+
auto j = i % sizeof(hash);
1279+
if (j == 0)
12791280
{
12801281
bool ok = trantor::utils::secureRandomBytes(&hash, sizeof(hash));
12811282
if (!ok)
12821283
throw std::runtime_error(
12831284
"Failed to generate random bytes for secureRandomString");
12841285
}
12851286
unsigned char *hashBytes = reinterpret_cast<unsigned char *>(&hash);
1286-
auto ret = hashBytes[i];
1287-
i = (i + 1) % sizeof(hash);
1288-
return ret;
1289-
};
1290-
1291-
for (size_t i = 0; i < size; ++i)
1292-
ret[i] = chars[randByte() % 64];
1287+
ret[i] = chars[hashBytes[j] % 64];
1288+
}
12931289
return ret;
12941290
}
12951291

0 commit comments

Comments
 (0)