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

ruby-changes:17186

From: naruse <ko1@a...>
Date: Mon, 6 Sep 2010 09:54:54 +0900 (JST)
Subject: [ruby-changes:17186] Ruby:r29186 (trunk): * util.c (ruby_strtod): check integr overflow.

naruse	2010-09-06 09:46:48 +0900 (Mon, 06 Sep 2010)

  New Revision: 29186

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29186

  Log:
    * util.c (ruby_strtod): check integr overflow.
      [ruby-dev:42180] #3789

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_float.rb
    trunk/util.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29185)
+++ ChangeLog	(revision 29186)
@@ -1,3 +1,8 @@
+Mon Sep  6 09:44:50 2010  NARUSE, Yui  <naruse@r...>
+
+	* util.c (ruby_strtod): check integr overflow.
+	  [ruby-dev:42180] #3789
+
 Mon Sep  6 06:17:21 2010  Tanaka Akira  <akr@f...>
 
 	* ext/pathname/pathname.c (path_readable_p): Pathname#readable?
Index: util.c
===================================================================
--- util.c	(revision 29185)
+++ util.c	(revision 29186)
@@ -2143,12 +2143,17 @@
 
                nd = 0;
                c = *s;
-               if (c < '0' || '9' < c) goto ret0;
-               do {
-		    nd *= 10;
-		    nd += c;
-		    nd -= '0';
-                   c = *++s;
+	       if (c < '0' || '9' < c) goto ret0;
+	       do {
+		   nd *= 10;
+		   nd += c;
+		   nd -= '0';
+		   c = *++s;
+		   /* Float("0x0."+("0"*267)+"1fp2095") */
+		   if (abs(nd) > 2095) {
+		       while ('0' <= c && c <= '9') c = *++s;
+		       break;
+		   }
                } while ('0' <= c && c <= '9');
 		dval(rv) = ldexp(adj, nd * dsign);
 	    }
Index: test/ruby/test_float.rb
===================================================================
--- test/ruby/test_float.rb	(revision 29185)
+++ test/ruby/test_float.rb	(revision 29186)
@@ -448,6 +448,7 @@
     assert_raise(ArgumentError) { Float("1.0\x001") }
     assert_equal(15.9375, Float('0xf.fp0'))
     assert_raise(ArgumentError) { Float('0xf.fp') }
+    assert_equal(Float::INFINITY, Float('0xf.fp1000000000000000'))
     assert_equal(1, suppress_warning {Float("1e10_00")}.infinite?)
     assert_raise(TypeError) { Float(nil) }
     o = Object.new

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

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