summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_float.rb8
-rw-r--r--util.c2
3 files changed, 14 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 271143446e..e9826db20c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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/test_float.rb b/test/ruby/test_float.rb
index 1146b583f0..961596b9a3 100644
--- a/test/ruby/test_float.rb
+++ b/test/ruby/test_float.rb
@@ -94,7 +94,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"))
@@ -448,6 +447,13 @@ class TestFloat < Test::Unit::TestCase
assert_raise(ArgumentError) { Float("1.0\x001") }
assert_equal(15.9375, Float('0xf.fp0'))
assert_raise(ArgumentError) { Float('0x') }
+ assert_equal(15, Float('0xf'))
+ assert_equal(15, Float('0xfp0'))
+ assert_raise(ArgumentError) { Float('0xfp') }
+ assert_raise(ArgumentError) { Float('0xf.') }
+ assert_raise(ArgumentError) { Float('0xf.p') }
+ assert_equal(15, Float('0xf.p0'))
+ assert_raise(ArgumentError) { Float('0xf.f') }
assert_raise(ArgumentError) { Float('0xf.fp') }
assert_equal(Float::INFINITY, Float('0xf.fp1000000000000000'))
assert_equal(1, suppress_warning {Float("1e10_00")}.infinite?)
diff --git a/util.c b/util.c
index 40b4573660..94396a3991 100644
--- a/util.c
+++ b/util.c
@@ -2122,6 +2122,7 @@ break2:
static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
s0 = ++s;
adj = 0;
+ aadj = -1;
if (!*++s || !(s1 = strchr(hexdigit, *s))) goto ret0;
do {
@@ -2159,6 +2160,7 @@ break2:
dval(rv) = ldexp(adj, nd * dsign);
}
else {
+ if (aadj != -1) goto ret0;
dval(rv) = adj;
}
goto ret;