summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-12-29 15:50:28 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-12-29 15:50:28 +0900
commit27d1e0132a0804581dca28df042e7047fd27eaa8 (patch)
tree11091a76f9add3bcc6c4e57c62a68fb07c998e6b /src
parent83f2e75d179e73be999da43ee586512807e03031 (diff)
downloadmruby-27d1e0132a0804581dca28df042e7047fd27eaa8.tar.gz
mruby-27d1e0132a0804581dca28df042e7047fd27eaa8.zip
array.c: fix `mrb_ary_shift_m` initialization bug.
The `ARY_PTR` and `ARY_LEN` may be modified in `mrb_get_args`.
Diffstat (limited to 'src')
-rw-r--r--src/array.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/array.c b/src/array.c
index c100591eb..1a95b75c9 100644
--- a/src/array.c
+++ b/src/array.c
@@ -581,14 +581,16 @@ mrb_ary_shift(mrb_state *mrb, mrb_value self)
static mrb_value
mrb_ary_shift_m(mrb_state *mrb, mrb_value self)
{
- struct RArray *a = mrb_ary_ptr(self);
- mrb_int len = ARY_LEN(a);
mrb_int n;
- mrb_value val;
if (mrb_get_args(mrb, "|i", &n) == 0) {
return mrb_ary_shift(mrb, self);
- };
+ }
+
+ struct RArray *a = mrb_ary_ptr(self);
+ mrb_int len = ARY_LEN(a);
+ mrb_value val;
+
ary_modify_check(mrb, a);
if (len == 0 || n == 0) return mrb_ary_new(mrb);
if (n < 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "negative array shift");