svn commit: r253607 - in stable/9: include lib/libc/stdlib

Andrey Chernov ache at freebsd.org
Wed Jul 24 10:14:36 UTC 2013


Forget to mention, it was MFC r252608,252648,252668,252698

On 24.07.2013 14:12, Andrey A. Chernov wrote:
> Author: ache
> Date: Wed Jul 24 10:12:50 2013
> New Revision: 253607
> URL: http://svnweb.freebsd.org/changeset/base/253607
> 
> Log:
>   1) POSIX requires rand(3) return values to be in the [0, RAND_MAX]
>   range, but ACM formula we use have internal state (and return value) in
>   the [1, 0x7ffffffe] range, so our RAND_MAX (0x7fffffff) is never reached
>   because it is off by one, zero is not reached too.
>   
>   Correct both RAND_MAX and rand(3) return value, shifting last one
>   to the 0 by 1 subtracted, resulting POSIXed [0, 0x7ffffffd(=new
>   RAND_MAX)] range.
>   
>   2) Add a checks for not overflowing on too big seeds. It may happens on
>   the machines, where sizeof(unsigned int) > 32 bits.
>   
>   This change is binary compatible because range is reduced, not expanded,
>   so no bump is needed.
>   
>   Reviewed by:    bde
>   Approved by:    re (glebius)
> 
> Modified:
>   stable/9/include/stdlib.h
>   stable/9/lib/libc/stdlib/rand.c
> Directory Properties:
>   stable/9/include/   (props changed)
>   stable/9/lib/libc/   (props changed)

-- 
http://ache.vniz.net/
bitcoin:1G6ugdNY6e5jx1GVnAU2ntj2NEfmjKG85r


More information about the svn-src-stable-9 mailing list