mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-06 02:15:32 +00:00
[Server] Fix memory issues with script functions used for hashing
This commit is contained in:
parent
a01c874613
commit
de78b65eb0
1 changed files with 10 additions and 10 deletions
|
@ -9,31 +9,31 @@
|
|||
#include <iostream>
|
||||
#include <random>
|
||||
|
||||
const char *MiscellaneousFunctions::GenerateRandomString(unsigned int length) noexcept
|
||||
static std::string tempRandomString;
|
||||
static std::string tempHashString;
|
||||
|
||||
const char* MiscellaneousFunctions::GenerateRandomString(unsigned int length) noexcept
|
||||
{
|
||||
const std::string characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
std::random_device randomDevice;
|
||||
std::mt19937 generator(randomDevice());
|
||||
std::uniform_int_distribution<std::mt19937::result_type> distribution(0, characters.size() - 1);
|
||||
|
||||
/* WARNING: this function is no longer reentrant with a static variable */
|
||||
static std::string randomString;
|
||||
std::string randomString = "";
|
||||
|
||||
for (std::size_t i = 0; i < length; ++i)
|
||||
{
|
||||
randomString += characters[distribution(generator)];
|
||||
}
|
||||
|
||||
return randomString.c_str();
|
||||
tempRandomString = randomString;
|
||||
return tempRandomString.c_str();
|
||||
}
|
||||
|
||||
const char *MiscellaneousFunctions::GetSHA256Hash(const char* inputString) noexcept
|
||||
const char* MiscellaneousFunctions::GetSHA256Hash(const char* inputString) noexcept
|
||||
{
|
||||
/* WARNING: this function is no longer reentrant with a static variable */
|
||||
static std::string hashString = picosha2::hash256_hex_string(std::string{inputString});
|
||||
|
||||
return hashString.c_str();
|
||||
tempHashString = picosha2::hash256_hex_string(std::string{inputString});
|
||||
return tempHashString.c_str();
|
||||
}
|
||||
|
||||
unsigned int MiscellaneousFunctions::GetLastPlayerId() noexcept
|
||||
|
|
Loading…
Reference in a new issue