Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 09 Oct 2012 20:33:34 +0400
From:      Andrey Chernov <ache@freebsd.org>
To:        Eitan Adler <eadler@FreeBSD.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r241373 - head/lib/libc/stdlib
Message-ID:  <507451DE.9060909@freebsd.org>
In-Reply-To: <201210091425.q99EPFS6020787@svn.freebsd.org>
References:  <201210091425.q99EPFS6020787@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Do you check assembler output for _both_ cases?
In my testing clang and gcc xor's 'junk' properly in case it have
'volatile' keyword (as in srandomdev()) and elide it without 'volatile'.
IMHO this change should be backed out for srandomdev() and adding
'volatile' for sranddev() instead.

On 09.10.2012 18:25, Eitan Adler wrote:
> Author: eadler
> Date: Tue Oct  9 14:25:14 2012
> New Revision: 241373
> URL: http://svn.freebsd.org/changeset/base/241373
> 
> Log:
>   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
> 
> Modified:
>   head/lib/libc/stdlib/rand.c
>   head/lib/libc/stdlib/random.c
> 
> Modified: head/lib/libc/stdlib/rand.c
> ==============================================================================
> --- head/lib/libc/stdlib/rand.c	Tue Oct  9 13:21:08 2012	(r241372)
> +++ head/lib/libc/stdlib/rand.c	Tue Oct  9 14:25:14 2012	(r241373)
> @@ -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: head/lib/libc/stdlib/random.c
> ==============================================================================
> --- head/lib/libc/stdlib/random.c	Tue Oct  9 13:21:08 2012	(r241372)
> +++ head/lib/libc/stdlib/random.c	Tue Oct  9 14:25:14 2012	(r241373)
> @@ -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;
>  	}
>  
> 




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