From 0b826dda97acd2b542c28811266864abefa69fa1 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 10 Dec 2007 07:52:19 +0000 Subject: * string.c (rb_str_insert): should not add length in bytes to index in chars. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 9ed5dfa05..9eba3b884 100644 --- a/string.c +++ b/string.c @@ -2247,7 +2247,7 @@ rb_str_insert(VALUE str, VALUE idx, VALUE str2) long pos = NUM2LONG(idx); if (pos == -1) { - pos = RSTRING_LEN(str); + return rb_str_append(str, str2); } else if (pos < 0) { pos++; @@ -2655,9 +2655,9 @@ rb_str_replace(VALUE str, VALUE str2) STR_SET_NOEMBED(str); RSTRING(str)->as.heap.ptr = ALLOC_N(char,len+1); memcpy(RSTRING_PTR(str), RSTRING_PTR(str2), len+1); - FL_SET(str, STR_ASSOC); + FL_SET(str, STR_ASSOC); RSTRING(str)->as.heap.aux.shared = RSTRING(str2)->as.heap.aux.shared; - } + } else { rb_str_modify(str); rb_str_resize(str, len); -- cgit