1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-16 10:20:30 +00:00

Remove undefined behavior from sranddev() and

srandomdev(). This doesn't actually work
with any modern C compiler:

In particular, both clang and modern gcc
verisons silently elide any xor operation
with 'junk'.

Approved by:	secteam
MFC after:	3 days
This commit is contained in:
Eitan Adler 2012-10-09 14:25:14 +00:00
parent af2bdacafb
commit 6a762eb23e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=241373
2 changed files with 2 additions and 4 deletions

View File

@ -130,10 +130,9 @@ sranddev()
if (!done) {
struct timeval tv;
unsigned long junk;
gettimeofday(&tv, NULL);
srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk);
srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec);
}
}

View File

@ -312,10 +312,9 @@ srandomdev(void)
if (!done) {
struct timeval tv;
volatile unsigned long junk;
gettimeofday(&tv, NULL);
srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk);
srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec);
return;
}