array.c: check for negative shift size.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-05-27 08:13:49 +09:00
parent c019d8d34d
commit 9a72869043
+1
View File
@@ -591,6 +591,7 @@ mrb_ary_shift_m(mrb_state *mrb, mrb_value self)
};
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");
if (n > len) n = len;
val = mrb_ary_new_from_values(mrb, n, ARY_PTR(a));
if (ARY_SHARED_P(a)) {