[前][次][番号順一覧][スレッド一覧]

ruby-changes:43479

From: ngoto <ko1@a...>
Date: Fri, 1 Jul 2016 13:50:43 +0900 (JST)
Subject: [ruby-changes:43479] ngoto:r55552 (trunk): * string.c (rb_str_subseq, str_substr): When RSTRING_EMBED_LEN_MAX

ngoto	2016-07-01 13:50:38 +0900 (Fri, 01 Jul 2016)

  New Revision: 55552

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55552

  Log:
    * string.c (rb_str_subseq, str_substr): When RSTRING_EMBED_LEN_MAX
      is used, TERM_LEN(str) should be considered with it because
      embedded strings are also processed by TERM_FILL.
      Additional fix for [Bug #12536] [ruby-dev:49699].

  Modified files:
    trunk/ChangeLog
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55551)
+++ ChangeLog	(revision 55552)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jul  1 13:26:39 2016  Naohisa Goto  <ngotogenome@g...>
+
+	* string.c (rb_str_subseq, str_substr): When RSTRING_EMBED_LEN_MAX
+	  is used, TERM_LEN(str) should be considered with it because
+	  embedded strings are also processed by TERM_FILL.
+	  Additional fix for [Bug #12536] [ruby-dev:49699].
+
 Fri Jul  1 12:11:01 2016  NARUSE, Yui  <naruse@r...>
 
 	* .gdbinit (rb_count_objects): added gdb version of count_objects().
Index: string.c
===================================================================
--- string.c	(revision 55551)
+++ string.c	(revision 55552)
@@ -2226,7 +2226,7 @@ rb_str_subseq(VALUE str, long beg, long https://github.com/ruby/ruby/blob/trunk/string.c#L2226
 {
     VALUE str2;
 
-    if (RSTRING_EMBED_LEN_MAX < len && SHARABLE_SUBSTRING_P(beg, len, RSTRING_LEN(str))) {
+    if ((RSTRING_EMBED_LEN_MAX + 1 - TERM_LEN(str)) < len && SHARABLE_SUBSTRING_P(beg, len, RSTRING_LEN(str))) {
 	long olen;
 	str2 = rb_str_new_shared(rb_str_new_frozen(str));
 	RSTRING(str2)->as.heap.ptr += beg;
@@ -2344,7 +2344,7 @@ str_substr(VALUE str, long beg, long len https://github.com/ruby/ruby/blob/trunk/string.c#L2344
     char *p = rb_str_subpos(str, beg, &len);
 
     if (!p) return Qnil;
-    if (len > RSTRING_EMBED_LEN_MAX && SHARABLE_SUBSTRING_P(p, len, RSTRING_END(str))) {
+    if (len > (RSTRING_EMBED_LEN_MAX + 1 - TERM_LEN(str)) && SHARABLE_SUBSTRING_P(p, len, RSTRING_END(str))) {
 	long ofs = p - RSTRING_PTR(str);
 	str2 = rb_str_new_frozen(str);
 	str2 = str_new_shared(rb_obj_class(str2), str2);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]