From 9874fdbc866f8b504296cdfa75177f01b077f079 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 9 Jan 2008 05:52:20 +0000 Subject: * string.c (rb_enc_cr_str_buf_cat, rb_str_buf_append): deal with self appending. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 57b5cd837b..f2371dcf01 100644 --- a/string.c +++ b/string.c @@ -1061,7 +1061,7 @@ static VALUE rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len, int ptr_encindex, int ptr_cr, int *ptr_cr_ret) { - long capa, total; + long capa, total, off = -1; int str_encindex = ENCODING_GET(str); int res_encindex; @@ -1128,7 +1128,13 @@ rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len, if (len < 0) { rb_raise(rb_eArgError, "negative string size (or size too big)"); } + if (ptr >= RSTRING_PTR(str) && ptr <= RSTRING_END(str)) { + off = ptr - RSTRING_PTR(str); + } rb_str_modify(str); + if (off != -1) { + ptr = RSTRING_PTR(str) + off; + } if (len == 0) { ENCODING_CODERANGE_SET(str, res_encindex, res_cr); return str; @@ -1170,10 +1176,6 @@ rb_str_buf_append(VALUE str, VALUE str2) { int str2_cr; - if (str == str2) { - str2 = rb_str_dup(str2); - } - str2_cr = ENC_CODERANGE(str2); rb_enc_cr_str_buf_cat(str, RSTRING_PTR(str2), RSTRING_LEN(str2), -- cgit v1.2.3