summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-09-07 06:59:46 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-09-07 06:59:46 +0000
commit6fc752bf7da30898ff8e570f9354cab9419cf3cf (patch)
tree69ef1c65eafc080502ce7cb838a7d8a34904980e /string.c
parenta509e67c5a690ad83bde66299d73bcf967f84dc1 (diff)
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/string.c b/string.c
index 6343a2af5f..5eb5d248ed 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 */
}