From 8ff17ef26936f3bc4f0fec430fe4cdb56f069a33 Mon Sep 17 00:00:00 2001 From: yugui Date: Mon, 15 Nov 2010 11:43:50 +0000 Subject: merges r29187 and r29239 from trunk into ruby_1_9_2, but does not raise an error. just warning. -- * util.c (ruby_strtod): reject Float('0x0.'). [ruby-dev:42239] Bug #3820 -- * util.c (ruby_strtod): check there is at least 1 digit after "0x" before ".". [ruby-dev:42183] #3790 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@29795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ test/ruby/envutil.rb | 5 +++++ test/ruby/test_float.rb | 8 ++++++-- util.c | 7 +++++++ version.h | 2 +- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 00a4395217..c0248c5c8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Sep 13 10:12:09 2010 NARUSE, Yui + + * util.c (ruby_strtod): reject Float('0x0.'). + [ruby-dev:42239] Bug #3820 + Mon Sep 13 09:23:58 2010 NARUSE, Yui * ext/openssl/ossl_bn.c (ossl_bn_is_prime): fix comparison diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb index 0703ee4f0d..04c8e409f9 100644 --- a/test/ruby/envutil.rb +++ b/test/ruby/envutil.rb @@ -208,6 +208,11 @@ module Test assert(status.success?, m) end + def assert_warn(msg) + stderr = EnvUtil.verbose_warning { yield } + assert(msg === stderr, "warning message #{stderr.inspect} is expected to match #{msg.inspect}") + end + end end end diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index 2f3bb7952e..fffa96e313 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -1,4 +1,5 @@ require 'test/unit' +require_relative 'envutil' class TestFloat < Test::Unit::TestCase def test_float @@ -91,7 +92,6 @@ class TestFloat < Test::Unit::TestCase assert_equal([ 0.0].pack('G'), [Float(" 0x0p+0").to_f].pack('G')) assert_equal([-0.0].pack('G'), [Float("-0x0p+0").to_f].pack('G')) assert_equal(255.0, Float("0Xff")) - assert_equal(255.5, Float("0Xff.8")) assert_equal(1.0, Float("0X1.P+0")) assert_equal(1024.0, Float("0x1p10")) assert_equal(1024.0, Float("0x1p+10")) @@ -430,7 +430,11 @@ class TestFloat < Test::Unit::TestCase assert(!Float(([1] * 10000).join("_")).infinite?) # is it really OK? assert_raise(ArgumentError) { Float("1.0\x001") } assert_equal(15.9375, Float('0xf.fp0')) - assert_raise(ArgumentError) { Float('0xf.fp') } + assert_warn(/malformed value for Float\(\).*?Ruby 1\.9\.3/) { Float('0x') } + assert_equal(15.0, Float('0xf')) + assert_equal(15.0, Float('0xfp0')) + assert_equal(15.0, Float('0xf.p0')) + assert_warn(/malformed value for Float\(\).*?Ruby 1\.9\.3/) { Float('0xf.f') } assert_equal(1, Float("1e10_00").infinite?) assert_raise(TypeError) { Float(nil) } o = Object.new diff --git a/util.c b/util.c index 1c0d8d6c7b..26f46baf00 100644 --- a/util.c +++ b/util.c @@ -2120,7 +2120,11 @@ break2: static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF"; s0 = ++s; adj = 0; + aadj = -1; + if (!s[1]) { + rb_warn("malformed value for Float(): %s. Ruby 1.9.3 for later will raise an ArgumentError for the value.", s00); + } while (*++s && (s1 = strchr(hexdigit, *s))) { adj *= 16; adj += (s1 - hexdigit) & 15; @@ -2151,6 +2155,9 @@ break2: dval(rv) = ldexp(adj, nd * dsign); } else { + if (aadj != -1) { + rb_warn("malformed value for Float(): %s. Ruby 1.9.3 for later will raise an ArgumentError for the value.", s00); + } dval(rv) = adj; } goto ret; diff --git a/version.h b/version.h index 18b68bedd2..8a05f44a8f 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_PATCHLEVEL 39 +#define RUBY_PATCHLEVEL 40 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 -- cgit v1.2.3