Skip to content

Commit 27d1e01

Browse files
committed
array.c: fix mrb_ary_shift_m initialization bug.
The `ARY_PTR` and `ARY_LEN` may be modified in `mrb_get_args`.
1 parent 83f2e75 commit 27d1e01

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/array.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,14 +581,16 @@ mrb_ary_shift(mrb_state *mrb, mrb_value self)
581581
static mrb_value
582582
mrb_ary_shift_m(mrb_state *mrb, mrb_value self)
583583
{
584-
struct RArray *a = mrb_ary_ptr(self);
585-
mrb_int len = ARY_LEN(a);
586584
mrb_int n;
587-
mrb_value val;
588585

589586
if (mrb_get_args(mrb, "|i", &n) == 0) {
590587
return mrb_ary_shift(mrb, self);
591-
};
588+
}
589+
590+
struct RArray *a = mrb_ary_ptr(self);
591+
mrb_int len = ARY_LEN(a);
592+
mrb_value val;
593+
592594
ary_modify_check(mrb, a);
593595
if (len == 0 || n == 0) return mrb_ary_new(mrb);
594596
if (n < 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "negative array shift");

0 commit comments

Comments
 (0)