Skip to content

Commit

Permalink
Fix an off by one in rb_ary_resize
Browse files Browse the repository at this point in the history
When setting len to X we only need to grow the array
if len is bigger than capa. If they're equal we don't need to
increase capacity.
  • Loading branch information
byroot committed Dec 4, 2024
1 parent 1c4dbb1 commit bf225fe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion array.c
Original file line number Diff line number Diff line change
Expand Up @@ -2304,7 +2304,7 @@ rb_ary_resize(VALUE ary, long len)
rb_raise(rb_eIndexError, "index %ld too big", len);
}
if (len > olen) {
if (len >= ARY_CAPA(ary)) {
if (len > ARY_CAPA(ary)) {
ary_double_capa(ary, len);
}
ary_mem_clear(ary, olen, len - olen);
Expand Down

0 comments on commit bf225fe

Please sign in to comment.