diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-11-15 05:42:36 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-11-15 05:42:36 +0000 |
commit | 18f7059688854cc10f7212563d37bac828a1cbef (patch) | |
tree | da16301cf8cfb0808028258a868c975f29db80df /array.c | |
parent | b750e49434834b04735987a48d2f3b68d9e55ef5 (diff) |
* array.c (rb_ary_fill): should adjust array length correctly when
an array is expanded in the fill process. [ruby-core:06625]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -1088,6 +1088,7 @@ rb_ary_insert(argc, argv, ary) { long pos; + if (argc == 1) return ary; if (argc < 1) { rb_raise(rb_eArgError, "wrong number of arguments (at least 1)"); } @@ -1095,11 +1096,9 @@ rb_ary_insert(argc, argv, 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; } @@ -2265,7 +2264,6 @@ rb_ary_fill(argc, argv, 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) { @@ -2276,9 +2274,11 @@ rb_ary_fill(argc, argv, 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) { |