Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 Oct 2012 02:12:53 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r241476 - stable/9/lib/libc/stdlib
Message-ID:  <201210120212.q9C2Crst023978@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Fri Oct 12 02:12:53 2012
New Revision: 241476
URL: http://svn.freebsd.org/changeset/base/241476

Log:
  MFC r241373:
  	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:	cperciva (implicit)

Modified:
  stable/9/lib/libc/stdlib/rand.c
  stable/9/lib/libc/stdlib/random.c
Directory Properties:
  stable/9/lib/libc/   (props changed)

Modified: stable/9/lib/libc/stdlib/rand.c
==============================================================================
--- stable/9/lib/libc/stdlib/rand.c	Fri Oct 12 02:12:52 2012	(r241475)
+++ stable/9/lib/libc/stdlib/rand.c	Fri Oct 12 02:12:53 2012	(r241476)
@@ -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);
 	}
 }
 

Modified: stable/9/lib/libc/stdlib/random.c
==============================================================================
--- stable/9/lib/libc/stdlib/random.c	Fri Oct 12 02:12:52 2012	(r241475)
+++ stable/9/lib/libc/stdlib/random.c	Fri Oct 12 02:12:53 2012	(r241476)
@@ -315,10 +315,9 @@ srandomdev()
 
 	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;
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201210120212.q9C2Crst023978>