diff --git a/ChangeLog b/ChangeLog index bc9526ccb7..5d03153dd3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Nov 15 14:39:16 2005 Yukihiro Matsumoto + + * array.c (rb_ary_fill): should adjust array length correctly when + an array is expanded in the fill process. [ruby-core:06625] + Mon Nov 14 23:49:57 2005 Nobuyoshi Nakada * file.c (rb_file_s_readlink): ERANGE will occur only on GPFS. diff --git a/array.c b/array.c index 54ccd8f49f..abf3ab7218 100644 --- a/array.c +++ b/array.c @@ -1100,6 +1100,7 @@ rb_ary_insert(int argc, VALUE *argv, VALUE ary) { long pos; + if (argc == 1) return ary; if (argc < 1) { rb_raise(rb_eArgError, "wrong number of arguments (at least 1)"); } @@ -1107,11 +1108,9 @@ rb_ary_insert(int argc, VALUE *argv, VALUE ary) if (pos == -1) { pos = RARRAY(ary)->len; } - else if (pos < 0) { + if (pos < 0) { pos++; } - - if (argc == 1) return ary; rb_ary_splice(ary, pos, 0, rb_ary_new4(argc - 1, argv + 1)); return ary; } @@ -2141,7 +2140,6 @@ rb_ary_fill(int argc, VALUE *argv, VALUE ary) if (beg > RARRAY(ary)->len) { rb_mem_clear(RARRAY(ary)->ptr + RARRAY(ary)->len, end - RARRAY(ary)->len); } - RARRAY(ary)->len = end; } if (block_p) { @@ -2152,9 +2150,11 @@ rb_ary_fill(int argc, VALUE *argv, VALUE ary) v = rb_yield(LONG2NUM(i)); if (i>=RARRAY(ary)->len) break; RARRAY(ary)->ptr[i] = v; + RARRAY(ary)->len = i+1; } } else { + RARRAY(ary)->len = end; p = RARRAY(ary)->ptr + beg; pend = p + len; while (p < pend) {