Date: Wed, 24 Jul 2013 14:14:26 +0400 From: Andrey Chernov <ache@freebsd.org> To: "Andrey A. Chernov" <ache@FreeBSD.org> Cc: svn-src-stable@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, svn-src-stable-9@freebsd.org Subject: Re: svn commit: r253607 - in stable/9: include lib/libc/stdlib Message-ID: <51EFA902.10408@freebsd.org> In-Reply-To: <201307241012.r6OACoqb011294@svn.freebsd.org> References: <201307241012.r6OACoqb011294@svn.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?51EFA902.10408>