1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* util.c (ruby_strtod): reject Float('0x0.').

[ruby-dev:42239] Bug #3820

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2010-09-13 01:15:39 +00:00
parent 1973984f90
commit 2590d7447a
3 changed files with 14 additions and 1 deletions

View file

@ -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

View file

@ -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?)

2
util.c
View file

@ -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;