From 389c5843adf2c732b6a04560017544c63076f1b4 Mon Sep 17 00:00:00 2001 From: nagachika Date: Sun, 20 Jan 2019 05:13:27 +0000 Subject: [PATCH] merge revision(s) 63322: [Backport #14731] object.c: fix exponent with underscore * object.c (rb_cstr_to_dbl_raise): do not ignore exponent part when the input string longer than internal buffer contains underscore(s). [ruby-core:86836] [Bug #14731] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@66879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 6 +++++- test/ruby/test_float.rb | 2 ++ version.h | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/object.c b/object.c index adec3f5e76..20508e1d61 100644 --- a/object.c +++ b/object.c @@ -3241,7 +3241,8 @@ rb_cstr_to_dbl(const char *p, int badcheck) if (*end) { char buf[DBL_DIG * 4 + 10]; char *n = buf; - char *e = buf + sizeof(buf) - 1; + char *const init_e = buf + DBL_DIG * 4; + char *e = init_e; char prev = 0; while (p < end && n < e) prev = *n++ = *p++; @@ -3254,6 +3255,9 @@ rb_cstr_to_dbl(const char *p, int badcheck) } } prev = *p++; + if (e == init_e && (*p == 'e' || *p == 'E')) { + e = buf + sizeof(buf) - 1; + } if (n < e) *n++ = prev; } *n = '\0'; diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index bddd10bf10..67432627d8 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -163,6 +163,8 @@ class TestFloat < Test::Unit::TestCase assert_equal(-31.0*2**-1027, Float("-0x1f"+("0"*268)+".0p-2099")) assert_equal(-31.0*2**-1027, Float("-0x1f"+("0"*600)+".0p-3427")) end + + assert_equal(1.0e10, Float("1.0_"+"00000"*Float::DIG+"e10")) end def test_divmod diff --git a/version.h b/version.h index 8c5f5743aa..5f0560c88b 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.5.4" #define RUBY_RELEASE_DATE "2019-01-20" -#define RUBY_PATCHLEVEL 134 +#define RUBY_PATCHLEVEL 135 #define RUBY_RELEASE_YEAR 2019 #define RUBY_RELEASE_MONTH 1