diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-10 17:37:52 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-10 17:37:52 +0000 |
commit | a88589c7d18c5004bb8b9f8191cb0d3aa3e5a705 (patch) | |
tree | 795eb1b9f5e6386f1d78282c09c3db52a9948f3c /random.c | |
parent | 1dabc36b8f3545611b00c7161e535246951c5866 (diff) | |
download | ruby-a88589c7d18c5004bb8b9f8191cb0d3aa3e5a705.tar.gz |
* random.c (limited_rand): expands to long before shift so that
the result does not overflow.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r-- | random.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -414,8 +414,8 @@ limited_rand(struct MT *mt, unsigned long limit) retry: val = 0; for (i = SIZEOF_LONG/4-1; 0 <= i; i--) { - if (mask >> (i * 32)) { - val |= genrand_int32(mt) << (i * 32); + if ((mask >> (i * 32)) & 0xffffffff) { + val |= (unsigned long)genrand_int32(mt) << (i * 32); val &= mask; if (limit < val) goto retry; |