aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-01-12 17:52:07 +0000
committerJakub Jelinek <jakub@redhat.com>2007-01-12 17:52:07 +0000
commit0bba79a9a4555f55af152ed6090b2f93fd347d23 (patch)
tree8ff5583b84bed7a087609c8165c53363bb27ca5a /stdlib
parentb1d424b6b00bf95f65e77a720af2d89f52201759 (diff)
downloadglibc-0bba79a9a4555f55af152ed6090b2f93fd347d23.tar
glibc-0bba79a9a4555f55af152ed6090b2f93fd347d23.tar.gz
glibc-0bba79a9a4555f55af152ed6090b2f93fd347d23.tar.bz2
glibc-0bba79a9a4555f55af152ed6090b2f93fd347d23.zip
[BZ #3747]
* stdlib/jrand48_r.c (__jrand48_r): Make sure result is in the [-231 .. 231) range. * stdlib/tst-rand48.c (main): Fix expected values for 64-bit targets. * stdlib/tst-rand48-2.c: New test. * stdlib/Makefile (tests): Add tst-rand48-2.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/Makefile3
-rw-r--r--stdlib/jrand48_r.c4
-rw-r--r--stdlib/tst-rand48.c28
3 files changed, 18 insertions, 17 deletions
diff --git a/stdlib/Makefile b/stdlib/Makefile
index e632d3523b..4b802e2ed5 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -66,7 +66,8 @@ tests := tst-strtol tst-strtod testmb testrand testsort testdiv \
test-canon test-canon2 tst-strtoll tst-environ \
tst-xpg-basename tst-random tst-random2 tst-bsearch \
tst-limits tst-rand48 bug-strtod tst-setcontext \
- test-a64l tst-qsort tst-system testmb2 bug-strtod2
+ test-a64l tst-qsort tst-system testmb2 bug-strtod2 \
+ tst-rand48-2
include ../Makeconfig
diff --git a/stdlib/jrand48_r.c b/stdlib/jrand48_r.c
index 2383ae129e..39e8d090a6 100644
--- a/stdlib/jrand48_r.c
+++ b/stdlib/jrand48_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1997, 1998, 2001, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@@ -30,7 +30,7 @@ __jrand48_r (xsubi, buffer, result)
return -1;
/* Store the result. */
- *result = ((xsubi[2] << 16) | xsubi[1]) & 0xffffffffl;
+ *result = (int32_t) ((xsubi[2] << 16) | xsubi[1]);
return 0;
}
diff --git a/stdlib/tst-rand48.c b/stdlib/tst-rand48.c
index fd2c4c1955..52e1b96afe 100644
--- a/stdlib/tst-rand48.c
+++ b/stdlib/tst-rand48.c
@@ -44,10 +44,10 @@ main (void)
}
l = mrand48 ();
- if (l != 0xa28c1003l)
+ if (l != -0x5d73effdl)
{
printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0xa28c1003l, l);
+ __LINE__ - 4, -0x5d73effdl, l);
result = 1;
}
@@ -60,10 +60,10 @@ main (void)
}
l = mrand48 ();
- if (l != 0x9e88f474l)
+ if (l != -0x61770b8cl)
{
printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0x9e88f474l, l);
+ __LINE__ - 4, -0x61770b8cl, l);
result = 1;
}
@@ -92,10 +92,10 @@ main (void)
}
l = mrand48 ();
- if (l != 0xeb7a1fa3l)
+ if (l != -0x1485e05dl)
{
printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0xeb7a1fa3l, l);
+ __LINE__ - 4, -0x1485e05dl, l);
result = 1;
}
@@ -171,10 +171,10 @@ main (void)
}
l = mrand48 ();
- if (l != 0xa28c1003l)
+ if (l != -0x5d73effdl)
{
printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0xa28c1003l, l);
+ __LINE__ - 4, -0x5d73effdl, l);
result = 1;
}
@@ -187,10 +187,10 @@ main (void)
}
l = mrand48 ();
- if (l != 0x9e88f474l)
+ if (l != -0x61770b8cl)
{
printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0x9e88f474l, l);
+ __LINE__ - 4, -0x61770b8cl, l);
result = 1;
}
@@ -231,10 +231,10 @@ main (void)
}
l = mrand48 ();
- if (l != 0xeb7a1fa3l)
+ if (l != -0x1485e05dl)
{
printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0xeb7a1fa3l, l);
+ __LINE__ - 4, -0x1485e05dl, l);
result = 1;
}
@@ -287,10 +287,10 @@ main (void)
}
l = jrand48 (xs);
- if (l != 0xf568c7a0l)
+ if (l != -0xa973860l)
{
printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0xf568c7a0l, l);
+ __LINE__ - 4, -0xa973860l, l);
result = 1;
}