diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-30 11:36:43 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-30 11:36:43 +0000 |
commit | cea5e4cbda65f3e37d3c75dc29cbef7126d2a8a4 (patch) | |
tree | 537b08c5e87aa6683e66aa13a5661b429a80b2fb /string.c | |
parent | 313a909418fa6694f865e1f6720bdfb567a67f12 (diff) |
merge revision(s) 17530:
* string.c (str_buf_cat): check for self concatenation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@17735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -708,9 +708,13 @@ str_buf_cat(str, ptr, len) const char *ptr; long len; { - long capa, total; + long capa, total, off = -1;; rb_str_modify(str); + if (ptr >= RSTRING(str)->ptr && ptr <= RSTRING(str)->ptr + RSTRING(str)->len) { + off = ptr - RSTRING(str)->ptr; + } + if (len == 0) return 0; if (FL_TEST(str, STR_ASSOC)) { FL_UNSET(str, STR_ASSOC); capa = RSTRING(str)->aux.capa = RSTRING(str)->len; @@ -732,6 +736,9 @@ str_buf_cat(str, ptr, len) } RESIZE_CAPA(str, capa); } + if (off != -1) { + ptr = RSTRING(str)->ptr + off; + } memcpy(RSTRING(str)->ptr + RSTRING(str)->len, ptr, len); RSTRING(str)->len = total; RSTRING(str)->ptr[total] = '\0'; /* sentinel */ |