aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-09 05:52:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-09 05:52:20 +0000
commit9874fdbc866f8b504296cdfa75177f01b077f079 (patch)
treed838d80a5915c28b00c7c15f03ac38543b4fa25a /string.c
parent3f2d1892dfe608722870cec8ee9ef0fda1f315ce (diff)
downloadruby-9874fdbc866f8b504296cdfa75177f01b077f079.tar.gz
* 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
Diffstat (limited to 'string.c')
-rw-r--r--string.c12
1 files changed, 7 insertions, 5 deletions
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),