1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* random.c (rand_init): array length of random seed was broken, which

causes memory error with srand(2**1000000-1).

* test/ruby/test_rand.c: test for above.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2009-07-21 14:51:17 +00:00
parent 7203e59f27
commit 4516f623b8
3 changed files with 14 additions and 4 deletions

View file

@ -1,3 +1,10 @@
Tue Jul 21 23:47:38 2009 Yusuke Endoh <mame@tsg.ne.jp>
* random.c (rand_init): array length of random seed was broken, which
causes memory error with srand(2**1000000-1).
* test/ruby/test_rand.c: test for above.
Tue Jul 21 21:37:19 2009 Keiju Ishitsuka <keiju@emperor2.pendome>
* lib/irb/cmd/help.rb: fixed irb's "help" command. [ruby-core:22310].

View file

@ -304,11 +304,9 @@ rand_init(struct MT *mt, VALUE vseed)
if (blen == 0) {
len = 1;
}
else if (blen > MT_MAX_STATE * SIZEOF_INT32 / SIZEOF_BDIGITS) {
blen = (len = MT_MAX_STATE) * SIZEOF_INT32 / SIZEOF_BDIGITS;
len = roomof(len, SIZEOF_INT32);
}
else {
if (blen > MT_MAX_STATE * SIZEOF_INT32 / SIZEOF_BDIGITS)
blen = (len = MT_MAX_STATE) * SIZEOF_INT32 / SIZEOF_BDIGITS;
len = roomof((int)blen * SIZEOF_BDIGITS, SIZEOF_INT32);
}
/* allocate ints for init_by_array */

View file

@ -164,4 +164,9 @@ class TestRand < Test::Unit::TestCase
srand(0)
assert_equal([1,4,2,5,3], [1,2,3,4,5].shuffle)
end
def test_big_seed
srand(2**1000000-1)
assert_equal(1143843490, rand(0x100000000))
end
end