aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2015-12-22 11:08:38 +0100
committerAlexey Kardashevskiy <aik@ozlabs.ru>2015-12-23 13:01:04 +1100
commit1487399da6fc4987de761c583d1aeb68951bc75b (patch)
tree61b1ee8c7930d343b85c79e13c98c90398098e27 /lib
parent7e31382cca5fb988ba754fab6073c5ffb8a4feec (diff)
downloadSLOF-1487399da6fc4987de761c583d1aeb68951bc75b.zip
SLOF-1487399da6fc4987de761c583d1aeb68951bc75b.tar.gz
SLOF-1487399da6fc4987de761c583d1aeb68951bc75b.tar.bz2
libc: Fix the rand() function to return non-zero values
The rand() function in SLOF's libc has a bug which caused the function to always return zero: The _rand value was shifted left by 16, and then ANDed with 0x7fff. Obviously, the shift operation should be ">>" instead of "<<". And while we're at it, also increase the constant for the multiplaction in there so that more upper bits are affected. Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdlib/rand.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/libc/stdlib/rand.c b/lib/libc/stdlib/rand.c
index 87e3efd..98c7e6d 100644
--- a/lib/libc/stdlib/rand.c
+++ b/lib/libc/stdlib/rand.c
@@ -18,7 +18,7 @@ static unsigned long _rand = 1;
int
rand(void)
{
- _rand = _rand * 25364735 + 34563;
+ _rand = _rand * 1237732973 + 34563;
- return ((unsigned int) (_rand << 16) & RAND_MAX);
+ return ((unsigned int) (_rand >> 16) & RAND_MAX);
}