- 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

@ -1,6 +1,7 @@
Principal Author
Principal Author:
Paul Beckingham, paul@beckingham.net
Contributing Authors
With thanks to:
Eugene Kramer
SK

View file

@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.61)
AC_INIT(task, 1.0.0, bugs@beckingham.net)
AC_INIT(task, 1.0.1, bugs@beckingham.net)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/task.cpp])
AC_CONFIG_HEADER([auto.h])
@ -35,6 +35,8 @@ AC_FUNC_SELECT_ARGTYPES
AC_CHECK_FUNCS([select])
AC_CHECK_FUNC(flock, [AC_DEFINE([HAVE_FLOCK], [1], [Found flock])])
AC_CHECK_FUNC(uuid_unparse_lower, [AC_DEFINE([HAVE_UUID], [1], [Found uuid_unparse_lower])])
AC_CHECK_FUNC(random, [AC_DEFINE([HAVE_RANDOM], [1], [Found random])])
AC_CHECK_FUNC(srandom, [AC_DEFINE([HAVE_SRANDOM], [1], [Found srandom])])
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT

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 ();

View file

@ -5,7 +5,7 @@
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
Download latest task <a href="http://www.beckingham.net/task-1.0.0.tar.gz">task-1.0.0.tar.gz (6/3/2008)</a>.
Download the latest task source code <a href="http://www.beckingham.net/task-1.0.0.tar.gz">task-1.0.0.tar.gz</a> (6/3/2008).
<body>
</html>