aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/string.c b/string.c
index 95c4e0c440..189cc1b751 100644
--- a/string.c
+++ b/string.c
@@ -1166,7 +1166,13 @@ rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *ptr_enc)
VALUE
rb_str_buf_append(VALUE str, VALUE str2)
{
- int str2_cr = ENC_CODERANGE(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),
ENCODING_GET(str2), str2_cr, &str2_cr);