summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
Diffstat (limited to 'random.c')
-rw-r--r--random.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/random.c b/random.c
index 02d081c51f..de047995d5 100644
--- a/random.c
+++ b/random.c
@@ -367,6 +367,7 @@ rand_init(struct MT *mt, VALUE vseed)
{
volatile VALUE seed;
long blen = 0;
+ long fixnum_seed;
int i, j, len;
unsigned int buf0[SIZEOF_LONG / SIZEOF_INT32 * 4], *buf = buf0;
@@ -374,9 +375,12 @@ rand_init(struct MT *mt, VALUE vseed)
switch (TYPE(seed)) {
case T_FIXNUM:
len = 1;
- buf[0] = (unsigned int)(FIX2ULONG(seed) & 0xffffffff);
+ fixnum_seed = FIX2LONG(seed);
+ buf[0] = (unsigned int)(fixnum_seed & 0xffffffff);
#if SIZEOF_LONG > SIZEOF_INT32
- if ((buf[1] = (unsigned int)(FIX2ULONG(seed) >> 32)) != 0) ++len;
+ if ((long)(int)fixnum_seed != fixnum_seed) {
+ if ((buf[1] = (unsigned int)(fixnum_seed >> 32)) != 0) ++len;
+ }
#endif
break;
case T_BIGNUM: