1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

Use random() and srandom() if available.

Reported-by: Coverity scanner
This commit is contained in:
Tim Rühsen 2014-11-19 14:35:40 +01:00
parent 18fe274e1c
commit 7a7a241e5b
4 changed files with 23 additions and 3 deletions

View File

@ -1,3 +1,7 @@
2014-11-19 Tim Ruehsen <tim.ruehsen@gmx.de>
* configure.ac: Check for random()
2014-11-17 Tim Ruehsen <tim.ruehsen@gmx.de>
* bootstrap.conf (gnulib_modules): Add module c-strcase

View File

@ -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])

View File

@ -1,3 +1,10 @@
2014-11-19 Tim Ruehsen <tim.ruehsen@gmx.de>
* utils.c (random_float, random_number): Use random() and
srandom() if available.
Reported-by: Coverity scanner
2014-11-19 Tim Ruehsen <tim.ruehsen@gmx.de>
* ftp-basic.c (ftp_epsv): Fix loop check

View File

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