summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-random
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-08-26 20:23:46 +0900
committerKOBAYASHI Shuji <[email protected]>2019-08-26 20:23:46 +0900
commit7178a5e7d3056407448006ae86d81b88f16bb489 (patch)
treea13d9d3b9644e45c4a954d66b885a7cca846e9b8 /mrbgems/mruby-random
parent4aabf91ee22d599c127cac176b58d0f68428aa93 (diff)
downloadmruby-7178a5e7d3056407448006ae86d81b88f16bb489.tar.gz
mruby-7178a5e7d3056407448006ae86d81b88f16bb489.zip
Fix `Array#sample` with `MRB_INT32`
Array index became potentially negative because `uint32_t` is cast to `mrb_int`.
Diffstat (limited to 'mrbgems/mruby-random')
-rw-r--r--mrbgems/mruby-random/src/random.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/mrbgems/mruby-random/src/random.c b/mrbgems/mruby-random/src/random.c
index a970e65a3..15f96934a 100644
--- a/mrbgems/mruby-random/src/random.c
+++ b/mrbgems/mruby-random/src/random.c
@@ -70,7 +70,7 @@ rand_uint32(rand_state *state)
uint32_t x = seed[0];
uint32_t y = seed[1];
uint32_t z = seed[2];
- uint32_t w = seed[3];
+ uint32_t w = seed[3];
uint32_t t;
t = x ^ (x << 11);
@@ -317,7 +317,7 @@ mrb_ary_sample(mrb_state *mrb, mrb_value ary)
for (;;) {
retry:
- r = (mrb_int)rand_uint32(random) % len;
+ r = (mrb_int)(rand_uint32(random) % len);
for (j=0; j<i; j++) {
if (mrb_fixnum(RARRAY_PTR(result)[j]) == r) {