Index: ChangeLog =================================================================== --- ChangeLog (revision 17550) +++ ChangeLog (working copy) @@ -1,3 +1,7 @@ +Sun Jun 22 07:16:42 2008 Nobuyoshi Nakada + + * string.c (str_buf_cat): check for self concatenation. + Fri Jun 20 18:24:18 2008 Nobuyoshi Nakada * string.c (rb_str_buf_append): should infect. Index: string.c =================================================================== --- string.c (revision 17550) +++ string.c (working copy) @@ -693,9 +693,13 @@ 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; @@ -717,6 +721,9 @@ } 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 */