Skip to content

Commit

Permalink
should adjust array size
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Sep 27, 2012
1 parent 7171e5a commit 5adbbe6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,7 @@ mrb_value
mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_value rpl)
{
struct RArray *a = mrb_ary_ptr(ary);
mrb_int tail;
int size;
int tail, size;
mrb_value *argv;
int i, argc;

Expand All @@ -600,6 +599,9 @@ mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_val
mrb_raise(mrb, E_INDEX_ERROR, "index is out of array");
}
}
if (a->len < len || a->len < head + len) {
len = a->len - head;
}
tail = head + len;

/* size check */
Expand All @@ -614,7 +616,6 @@ mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_val
size = head + argc;

if (tail < a->len) size += a->len - tail;

if (size > a->aux.capa)
ary_expand_capa(mrb, a, size);

Expand Down

0 comments on commit 5adbbe6

Please sign in to comment.