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

ruby-changes:5968

From: shyouhei <ko1@a...>
Date: Fri, 20 Jun 2008 15:53:39 +0900 (JST)
Subject: [ruby-changes:5968] Ruby:r17475 (ruby_1_8_6): merge revision(s) 17470:17472:

shyouhei	2008-06-20 15:53:16 +0900 (Fri, 20 Jun 2008)

  New Revision: 17475

  Modified files:
    branches/ruby_1_8_6/ChangeLog
    branches/ruby_1_8_6/array.c
    branches/ruby_1_8_6/string.c
    branches/ruby_1_8_6/version.h

  Log:
    merge revision(s) 17470:17472:
    * array.c (rb_ary_store, rb_ary_splice): not depend on unspecified
      behavior at integer overflow.
    * string.c (str_buf_cat): ditto.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_6/ChangeLog?r1=17475&r2=17474&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_6/version.h?r1=17475&r2=17474&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_6/string.c?r1=17475&r2=17474&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_6/array.c?r1=17475&r2=17474&diff_format=u

Index: ruby_1_8_6/array.c
===================================================================
--- ruby_1_8_6/array.c	(revision 17474)
+++ ruby_1_8_6/array.c	(revision 17475)
@@ -370,7 +370,7 @@
 	if (new_capa < ARY_DEFAULT_SIZE) {
 	    new_capa = ARY_DEFAULT_SIZE;
 	}
-	else if (new_capa >= ARY_MAX_SIZE - idx) {
+	if (new_capa >= ARY_MAX_SIZE - idx) {
 	    new_capa = (ARY_MAX_SIZE - idx) / 2;
 	}
 	new_capa += idx;
@@ -979,10 +979,10 @@
     rb_ary_modify(ary);
 
     if (beg >= RARRAY(ary)->len) {
-	len = beg + rlen;
-	if (len < 0 || len > ARY_MAX_SIZE) {
+	if (beg > ARY_MAX_SIZE - rlen) {
 	    rb_raise(rb_eIndexError, "index %ld too big", beg);
 	}
+	len = beg + rlen;
 	if (len >= RARRAY(ary)->aux.capa) {
 	    REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
 	    RARRAY(ary)->aux.capa = len;
Index: ruby_1_8_6/ChangeLog
===================================================================
--- ruby_1_8_6/ChangeLog	(revision 17474)
+++ ruby_1_8_6/ChangeLog	(revision 17475)
@@ -1,3 +1,10 @@
+Fri Jun 20 15:52:30 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* array.c (rb_ary_store, rb_ary_splice): not depend on unspecified
+	  behavior at integer overflow.
+
+	* string.c (str_buf_cat): ditto.
+
 Wed Jun 18 22:25:10 2008  URABE Shyouhei  <shyouhei@r...>
 
 	* array.c (ary_new, rb_ary_initialize, rb_ary_store,
Index: ruby_1_8_6/version.h
===================================================================
--- ruby_1_8_6/version.h	(revision 17474)
+++ ruby_1_8_6/version.h	(revision 17475)
@@ -2,7 +2,7 @@
 #define RUBY_RELEASE_DATE "2008-06-20"
 #define RUBY_VERSION_CODE 186
 #define RUBY_RELEASE_CODE 20080620
-#define RUBY_PATCHLEVEL 228
+#define RUBY_PATCHLEVEL 229
 
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 8
Index: ruby_1_8_6/string.c
===================================================================
--- ruby_1_8_6/string.c	(revision 17474)
+++ ruby_1_8_6/string.c	(revision 17475)
@@ -687,18 +687,14 @@
     return str;
 }
 
-VALUE
-rb_str_buf_cat(str, ptr, len)
+static VALUE
+str_buf_cat(str, ptr, len)
     VALUE str;
     const char *ptr;
     long len;
 {
     long capa, total;
 
-    if (len == 0) return str;
-    if (len < 0) {
-	rb_raise(rb_eArgError, "negative string size (or size too big)");
-    }
     rb_str_modify(str);
     if (FL_TEST(str, STR_ASSOC)) {
 	FL_UNSET(str, STR_ASSOC);
@@ -707,9 +703,16 @@
     else {
 	capa = RSTRING(str)->aux.capa;
     }
+    if (RSTRING(str)->len >= LONG_MAX - len) {
+	rb_raise(rb_eArgError, "string sizes too big");
+    }
     total = RSTRING(str)->len+len;
     if (capa <= total) {
 	while (total > capa) {
+	    if (capa + 1 >= LONG_MAX / 2) {
+		capa = total;
+		break;
+	    }
 	    capa = (capa + 1) * 2;
 	}
 	RESIZE_CAPA(str, capa);
@@ -722,6 +725,19 @@
 }
 
 VALUE
+rb_str_buf_cat(str, ptr, len)
+    VALUE str;
+    const char *ptr;
+    long len;
+{
+    if (len == 0) return str;
+    if (len < 0) {
+	rb_raise(rb_eArgError, "negative string size (or size too big)");
+    }
+    return str_buf_cat(str, ptr, len);
+}
+
+VALUE
 rb_str_buf_cat2(str, ptr)
     VALUE str;
     const char *ptr;
@@ -762,33 +778,7 @@
 rb_str_buf_append(str, str2)
     VALUE str, str2;
 {
-    long capa, len;
-
-    rb_str_modify(str);
-    if (FL_TEST(str, STR_ASSOC)) {
-	FL_UNSET(str, STR_ASSOC);
-	capa = RSTRING(str)->aux.capa = RSTRING(str)->len;
-    }
-    else {
-	capa = RSTRING(str)->aux.capa;
-    }
-    len = RSTRING(str)->len+RSTRING(str2)->len;
-    if (len < 0 || (capa+1) > LONG_MAX / 2) {
-	rb_raise(rb_eArgError, "string sizes too big");
-    }
-    if (capa <= len) {
-	while (len > capa) {
-	    capa = (capa + 1) * 2;
-	}
-	RESIZE_CAPA(str, capa);
-    }
-    memcpy(RSTRING(str)->ptr + RSTRING(str)->len,
-	   RSTRING(str2)->ptr, RSTRING(str2)->len);
-    RSTRING(str)->len += RSTRING(str2)->len;
-    RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; /* sentinel */
-    OBJ_INFECT(str, str2);
-
-    return str;
+    return str_buf_cat(str, RSTRING(str2)->ptr, RSTRING(str2)->len);
 }
 
 VALUE

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

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