diff --git a/ChangeLog b/ChangeLog index 15580c43..0be7e9ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-11-19 Tim Ruehsen + + * configure.ac: Check for random() + 2014-11-17 Tim Ruehsen * bootstrap.conf (gnulib_modules): Add module c-strcase diff --git a/configure.ac b/configure.ac index 298aede3..e589b93b 100644 --- a/configure.ac +++ b/configure.ac @@ -241,7 +241,7 @@ AC_FUNC_MMAP AC_FUNC_FSEEKO AC_CHECK_FUNCS(strptime timegm vsnprintf vasprintf drand48 pathconf) AC_CHECK_FUNCS(strtoll usleep ftello sigblock sigsetjmp memrchr wcwidth mbtowc) -AC_CHECK_FUNCS(sleep symlink utime strlcpy) +AC_CHECK_FUNCS(sleep symlink utime strlcpy random) if test x"$ENABLE_OPIE" = xyes; then AC_LIBOBJ([ftp-opie]) diff --git a/src/ChangeLog b/src/ChangeLog index 17d0817b..20844f7c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2014-11-19 Tim Ruehsen + + * utils.c (random_float, random_number): Use random() and + srandom() if available. + + Reported-by: Coverity scanner + 2014-11-19 Tim Ruehsen * ftp-basic.c (ftp_epsv): Fix loop check diff --git a/src/utils.c b/src/utils.c index 3280294f..f40480f6 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1846,7 +1846,14 @@ static int rnd_seeded; int random_number (int max) { -#ifdef HAVE_DRAND48 +#ifdef HAVE_RANDOM + if (!rnd_seeded) + { + srandom ((long) time (NULL) ^ (long) getpid ()); + rnd_seeded = 1; + } + return random () % max; +#elif defined HAVE_DRAND48 if (!rnd_seeded) { srand48 ((long) time (NULL) ^ (long) getpid ()); @@ -1881,7 +1888,9 @@ random_number (int max) double random_float (void) { -#ifdef HAVE_DRAND48 +#ifdef HAVE_RANDOM + return ((double) random_number (RAND_MAX)) / RAND_MAX; +#elif defined HAVE_DRAND48 if (!rnd_seeded) { srand48 ((long) time (NULL) ^ (long) getpid ());