- Fixed bug whereby the UUID generated by the custom generator was not terminated.

- Fixed bug whereby random numbers were used by the custom UUID generator, but srandom/srand was not called first.
This commit is contained in:
Paul Beckingham
2008-06-04 21:00:23 -04:00
parent f3de5c0711
commit 08f4ead97e
5 changed files with 20 additions and 6 deletions

View File

@@ -207,6 +207,13 @@ int main (int argc, char** argv)
// TODO Find out what this is, and either promote it to live code, or remove it.
// std::set_terminate (__gnu_cxx::__verbose_terminate_handler);
// Set up randomness.
#ifdef HAVE_SRANDOM
srandom (time (NULL));
#else
srand (time (NULL));
#endif
try
{
// Load the config file from the home directory. If the file cannot be

View File

@@ -182,14 +182,18 @@ const std::string uuid ()
static char randomHexDigit ()
{
static char digits[] = "0123456789abcdef";
#ifdef HAVE_RANDOM
return digits[random () % 16];
#else
return digits[rand () % 16];
#endif
}
////////////////////////////////////////////////////////////////////////////////
const std::string uuid ()
{
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
char id [37];
char id [48] = {0};
id[0] = randomHexDigit ();
id[1] = randomHexDigit ();
id[2] = randomHexDigit ();