mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
1dabc36b8f
commit
a88589c7d1
2 changed files with 7 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
Sat Jul 11 02:37:37 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* random.c (limited_rand): expands to long before shift so tha
|
||||
the result does not overflow.
|
||||
|
||||
Sat Jul 11 00:16:27 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* random.c (rand_init): got rid of buffer overflow.
|
||||
|
|
4
random.c
4
random.c
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue