aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2013-07-03 21:21:54 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2013-07-03 21:21:54 +0000
commit476d9314d6247b8386926960081689e8f395594c (patch)
tree1741a11f1eb25d7ff1fecb14fab8e90d942fec2b /include
parent6f691f7ee120963869451caeb2f48444e10bbd08 (diff)
downloadsrc-476d9314d6247b8386926960081689e8f395594c.tar.gz
src-476d9314d6247b8386926960081689e8f395594c.zip
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. Reviewed by: bde [1] MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=252608
Diffstat (limited to 'include')
-rw-r--r--include/stdlib.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/include/stdlib.h b/include/stdlib.h
index b73a54fa891c..cc922734a829 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -69,7 +69,7 @@ typedef struct {
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
-#define RAND_MAX 0x7fffffff
+#define RAND_MAX 0x7ffffffd
__BEGIN_DECLS
#ifdef _XLOCALE_H_