Skip to content

Commit

Permalink
Fetch arguments earlier to avoid a crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
clayton-shopify committed Feb 2, 2017
1 parent 6420951 commit a8ccda5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mrbgems/mruby-random/src/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ mrb_random_init(mrb_state *mrb, mrb_value self)
mrb_value seed;
mt_state *t;

seed = get_opt(mrb);

/* avoid memory leaks */
t = (mt_state*)DATA_PTR(self);
if (t) {
Expand All @@ -134,7 +136,6 @@ mrb_random_init(mrb_state *mrb, mrb_value self)
t = (mt_state *)mrb_malloc(mrb, sizeof(mt_state));
t->mti = N + 1;

seed = get_opt(mrb);
seed = mrb_random_mt_srand(mrb, t, seed);
if (mrb_nil_p(seed)) {
t->has_seed = FALSE;
Expand Down

0 comments on commit a8ccda5

Please sign in to comment.