mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Zero width unshift should not touch memory; ref #3780
This commit is contained in:
+4
-1
@@ -562,6 +562,10 @@ mrb_ary_unshift_m(mrb_state *mrb, mrb_value self)
|
||||
mrb_int alen, len;
|
||||
|
||||
mrb_get_args(mrb, "*!", &vals, &alen);
|
||||
if (alen == 0) {
|
||||
ary_modify_check(mrb, a);
|
||||
return self;
|
||||
}
|
||||
len = ARY_LEN(a);
|
||||
if (alen > ARY_MAX_SIZE - len) {
|
||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
|
||||
@@ -575,7 +579,6 @@ mrb_ary_unshift_m(mrb_state *mrb, mrb_value self)
|
||||
}
|
||||
else {
|
||||
ary_modify(mrb, a);
|
||||
if (alen == 0) return self;
|
||||
if (ARY_CAPA(a) < len + alen)
|
||||
ary_expand_capa(mrb, a, len + alen);
|
||||
ptr = ARY_PTR(a);
|
||||
|
||||
Reference in New Issue
Block a user