diff options
| author | Bouke van der Bijl <[email protected]> | 2016-11-23 11:21:14 -0500 |
|---|---|---|
| committer | Bouke van der Bijl <[email protected]> | 2016-11-23 11:21:14 -0500 |
| commit | c7262be0aeaf55b5c92b26db82c08f2fe6b95412 (patch) | |
| tree | cdd1806ffc3caed8d83973fa04fc71629c4ce5fa /mrbgems/mruby-random/src | |
| parent | 669bbc70b0553b68483c8d7eff8c31a602f283e9 (diff) | |
| download | mruby-c7262be0aeaf55b5c92b26db82c08f2fe6b95412.tar.gz mruby-c7262be0aeaf55b5c92b26db82c08f2fe6b95412.zip | |
Fix segfault in Array#sample
Diffstat (limited to 'mrbgems/mruby-random/src')
| -rw-r--r-- | mrbgems/mruby-random/src/random.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/mrbgems/mruby-random/src/random.c b/mrbgems/mruby-random/src/random.c index 3b8d0dd2f..587e6c01a 100644 --- a/mrbgems/mruby-random/src/random.c +++ b/mrbgems/mruby-random/src/random.c @@ -266,7 +266,7 @@ mrb_ary_sample(mrb_state *mrb, mrb_value ary) mrb_int n = 0; mrb_bool given; mt_state *random = NULL; - mrb_int len = RARRAY_LEN(ary); + mrb_int len; mrb_get_args(mrb, "|i?d", &n, &given, &random, &mt_state_type); if (random == NULL) { @@ -274,6 +274,7 @@ mrb_ary_sample(mrb_state *mrb, mrb_value ary) } mrb_random_rand_seed(mrb, random); mt_rand(random); + len = RARRAY_LEN(ary); if (!given) { /* pick one element */ switch (len) { case 0: |
