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

ruby-changes:43134

From: nobu <ko1@a...>
Date: Mon, 30 May 2016 14:41:07 +0900 (JST)
Subject: [ruby-changes:43134] nobu:r55208 (trunk): string.c: check in the order

nobu	2016-05-30 14:41:02 +0900 (Mon, 30 May 2016)

  New Revision: 55208

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

  Log:
    string.c: check in the order
    
    * string.c (rb_str_aref_m, rb_str_byteslice): check arguments in
      the left-to-right order.

  Modified files:
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 55207)
+++ string.c	(revision 55208)
@@ -4121,7 +4121,11 @@ rb_str_aref_m(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/string.c#L4121
 	if (RB_TYPE_P(argv[0], T_REGEXP)) {
 	    return rb_str_subpat(str, argv[0], argv[1]);
 	}
-	return rb_str_substr(str, NUM2LONG(argv[0]), NUM2LONG(argv[1]));
+	{
+	    long beg = NUM2LONG(argv[0]);
+	    long len = NUM2LONG(argv[1]);
+	    return rb_str_substr(str, beg, len);
+	}
     }
     rb_check_arity(argc, 1, 2);
     return rb_str_aref(str, argv[0]);
@@ -5135,7 +5139,9 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L5139
 rb_str_byteslice(int argc, VALUE *argv, VALUE str)
 {
     if (argc == 2) {
-	return str_byte_substr(str, NUM2LONG(argv[0]), NUM2LONG(argv[1]));
+	long beg = NUM2LONG(argv[0]);
+	long end = NUM2LONG(argv[1]);
+	return str_byte_substr(str, beg, end);
     }
     rb_check_arity(argc, 1, 2);
     return str_byte_aref(str, argv[0]);

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

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