mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) 63334: [Backport #14729]
object.c: raise on long invalid float string * object.c (rb_cstr_to_dbl_raise): check long invalid float string more precisely when truncating insignificant part. [ruby-core:86800] [Bug #14729] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@66880 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
389c5843ad
commit
a88ab94e75
3 changed files with 53 additions and 23 deletions
26
object.c
26
object.c
|
@ -3244,7 +3244,13 @@ rb_cstr_to_dbl(const char *p, int badcheck)
|
||||||
char *const init_e = buf + DBL_DIG * 4;
|
char *const init_e = buf + DBL_DIG * 4;
|
||||||
char *e = init_e;
|
char *e = init_e;
|
||||||
char prev = 0;
|
char prev = 0;
|
||||||
|
int dot_seen = FALSE;
|
||||||
|
|
||||||
|
switch (*p) {case '+': case '-': prev = *n++ = *p++;}
|
||||||
|
if (*p == '0') {
|
||||||
|
prev = *n++ = '0';
|
||||||
|
while (*++p == '0');
|
||||||
|
}
|
||||||
while (p < end && n < e) prev = *n++ = *p++;
|
while (p < end && n < e) prev = *n++ = *p++;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (*p == '_') {
|
if (*p == '_') {
|
||||||
|
@ -3255,8 +3261,26 @@ rb_cstr_to_dbl(const char *p, int badcheck)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prev = *p++;
|
prev = *p++;
|
||||||
if (e == init_e && (*p == 'e' || *p == 'E')) {
|
if (e == init_e && (prev == 'e' || prev == 'E' || prev == 'p' || prev == 'P')) {
|
||||||
e = buf + sizeof(buf) - 1;
|
e = buf + sizeof(buf) - 1;
|
||||||
|
*n++ = prev;
|
||||||
|
switch (*p) {case '+': case '-': prev = *n++ = *p++;}
|
||||||
|
if (*p == '0') {
|
||||||
|
prev = *n++ = '0';
|
||||||
|
while (*++p == '0');
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (ISSPACE(prev)) {
|
||||||
|
while (ISSPACE(*p)) ++p;
|
||||||
|
if (*p) {
|
||||||
|
if (badcheck) goto bad;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (prev == '.' ? dot_seen++ : !ISDIGIT(prev)) {
|
||||||
|
if (badcheck) goto bad;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (n < e) *n++ = prev;
|
if (n < e) *n++ = prev;
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,6 +165,12 @@ class TestFloat < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal(1.0e10, Float("1.0_"+"00000"*Float::DIG+"e10"))
|
assert_equal(1.0e10, Float("1.0_"+"00000"*Float::DIG+"e10"))
|
||||||
|
|
||||||
|
z = "0" * (Float::DIG * 4 + 10)
|
||||||
|
all_assertions_foreach("long invalid string", "1.0", "1.0e", "1.0e-", "1.0e+") do |n|
|
||||||
|
assert_raise(ArgumentError, n += z + "A") {Float(n)}
|
||||||
|
assert_raise(ArgumentError, n += z + ".0") {Float(n)}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_divmod
|
def test_divmod
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#define RUBY_VERSION "2.5.4"
|
#define RUBY_VERSION "2.5.4"
|
||||||
#define RUBY_RELEASE_DATE "2019-01-20"
|
#define RUBY_RELEASE_DATE "2019-01-20"
|
||||||
#define RUBY_PATCHLEVEL 135
|
#define RUBY_PATCHLEVEL 136
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2019
|
#define RUBY_RELEASE_YEAR 2019
|
||||||
#define RUBY_RELEASE_MONTH 1
|
#define RUBY_RELEASE_MONTH 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue