diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-11-15 11:43:50 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-11-15 11:43:50 +0000 |
commit | 8ff17ef26936f3bc4f0fec430fe4cdb56f069a33 (patch) | |
tree | dd6583b5061a7bc5e7adbfb8afd495863dabb584 | |
parent | 856e1f17f1846a2ad077aa7b0da6a2b8399fd7b7 (diff) |
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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | test/ruby/envutil.rb | 5 | ||||
-rw-r--r-- | test/ruby/test_float.rb | 8 | ||||
-rw-r--r-- | util.c | 7 | ||||
-rw-r--r-- | version.h | 2 |
5 files changed, 24 insertions, 3 deletions
@@ -1,3 +1,8 @@ +Mon Sep 13 10:12:09 2010 NARUSE, Yui <naruse@ruby-lang.org> + + * util.c (ruby_strtod): reject Float('0x0.'). + [ruby-dev:42239] Bug #3820 + Mon Sep 13 09:23:58 2010 NARUSE, Yui <naruse@ruby-lang.org> * 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 @@ -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; @@ -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 |