From f23f4f6e63b16d443855dde1fd19ed8c5a18960e Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 7 Sep 2000 06:59:46 +0000 Subject: matz git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'string.c') diff --git a/string.c b/string.c index 6343a2af5..5eb5d248e 100644 --- a/string.c +++ b/string.c @@ -427,10 +427,18 @@ rb_str_cat(str, ptr, len) long len; { if (len > 0) { + int poffset = -1; + rb_str_modify(str); + if (RSTRING(str)->ptr <= ptr && + ptr < RSTRING(str)->ptr + RSTRING(str)->len) { + poffset = ptr - RSTRING(str)->ptr; + } REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len + len + 1); - if (ptr) + if (ptr) { + if (poffset >= 0) ptr = RSTRING(str)->ptr + poffset; memcpy(RSTRING(str)->ptr + RSTRING(str)->len, ptr, len); + } RSTRING(str)->len += len; RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; /* sentinel */ } -- cgit