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

ruby-changes:1683

From: ko1@a...
Date: 22 Aug 2007 10:13:46 +0900
Subject: [ruby-changes:1683] shyouhei - Ruby:r13174 (ruby_1_8_6): * bignum.c (rb_cstr_to_inum): check leading non-digits.

shyouhei	2007-08-22 10:13:26 +0900 (Wed, 22 Aug 2007)

  New Revision: 13174

  Modified files:
    branches/ruby_1_8_6/ChangeLog
    branches/ruby_1_8_6/bignum.c
    branches/ruby_1_8_6/version.h

  Log:
    * bignum.c (rb_cstr_to_inum): check leading non-digits.
      [ruby-core:11691]


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_6/ChangeLog?r1=13174&r2=13173
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_6/version.h?r1=13174&r2=13173
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_6/bignum.c?r1=13174&r2=13173

Index: ruby_1_8_6/ChangeLog
===================================================================
--- ruby_1_8_6/ChangeLog	(revision 13173)
+++ ruby_1_8_6/ChangeLog	(revision 13174)
@@ -1,3 +1,8 @@
+Wed Aug 22 10:11:59 2007  Nobuyoshi Nakada  <nobu@r...>
+
+	* bignum.c (rb_cstr_to_inum): check leading non-digits.
+	  [ruby-core:11691]
+
 Wed Aug 22 10:07:48 2007  Nobuyoshi Nakada  <nobu@r...>
 
 	* bignum.c (rb_big_neg): SIGNED_VALUE isn't in 1.8.
Index: ruby_1_8_6/version.h
===================================================================
--- ruby_1_8_6/version.h	(revision 13173)
+++ ruby_1_8_6/version.h	(revision 13174)
@@ -2,7 +2,7 @@
 #define RUBY_RELEASE_DATE "2007-08-22"
 #define RUBY_VERSION_CODE 186
 #define RUBY_RELEASE_CODE 20070822
-#define RUBY_PATCHLEVEL 63
+#define RUBY_PATCHLEVEL 64
 
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 8
Index: ruby_1_8_6/bignum.c
===================================================================
--- ruby_1_8_6/bignum.c	(revision 13173)
+++ ruby_1_8_6/bignum.c	(revision 13174)
@@ -346,6 +346,13 @@
     VALUE z;
     BDIGIT *zds;
 
+#define conv_digit(c) \
+    (!ISASCII(c) ? -1 : \
+     isdigit(c) ? ((c) - '0') : \
+     islower(c) ? ((c) - 'a' + 10) : \
+     isupper(c) ? ((c) - 'A' + 10) : \
+     -1)
+
     if (!str) {
 	if (badcheck) goto bad;
 	return INT2FIX(0);
@@ -438,8 +445,14 @@
     }
     if (*str == '0') {		/* squeeze preceeding 0s */
 	while (*++str == '0');
-	--str;
+	if (!*str) --str;
     }
+    c = *str;
+    c = conv_digit(c);
+    if (c < 0 || c >= base) {
+	if (badcheck) goto bad;
+	return INT2FIX(0);
+    }
     len *= strlen(str)*sizeof(char);
 
     if (len <= (sizeof(VALUE)*CHAR_BIT)) {
@@ -472,7 +485,7 @@
     z = bignew(len, sign);
     zds = BDIGITS(z);
     for (i=len;i--;) zds[i]=0;
-    while (c = *str++) {
+    while ((c = *str++) != 0) {
 	if (c == '_') {
 	    if (badcheck) {
 		if (nondigit) goto bad;
@@ -480,21 +493,9 @@
 	    }
 	    continue;
 	}
-	else if (!ISASCII(c)) {
+	else if ((c = conv_digit(c)) < 0) {
 	    break;
 	}
-	else if (isdigit(c)) {
-	    c -= '0';
-	}
-	else if (islower(c)) {
-	    c -= 'a' - 10;
-	}
-	else if (isupper(c)) {
-	    c -= 'A' - 10;
-	}
-	else {
-	    break;
-	}
 	if (c >= base) break;
 	nondigit = 0;
 	i = 0;

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

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