ruby/ruby-1.8.6.230-string-str_buf_cat.patch
2008-06-25 08:32:24 +00:00

29 lines
936 B
Diff

diff -pruN ruby-1.8.6-p230.orig/string.c ruby-1.8.6-p230/string.c
--- ruby-1.8.6-p230.orig/string.c 2008-06-20 18:24:53.000000000 +0900
+++ ruby-1.8.6-p230/string.c 2008-06-25 16:10:17.000000000 +0900
@@ -693,9 +693,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;
@@ -717,6 +721,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 */