Fix crash when exponent is -2147483648

parent 73cc0877
...@@ -2868,7 +2868,11 @@ mrb_float_read(const char *string, char **endPtr) ...@@ -2868,7 +2868,11 @@ mrb_float_read(const char *string, char **endPtr)
mantSize -= 1; /* One of the digits was the point. */ mantSize -= 1; /* One of the digits was the point. */
} }
if (mantSize > 18) { if (mantSize > 18) {
if (decPt - 18 > 29999) {
fracExp = 29999;
} else {
fracExp = decPt - 18; fracExp = decPt - 18;
}
mantSize = 18; mantSize = 18;
} else { } else {
fracExp = decPt - mantSize; fracExp = decPt - mantSize;
...@@ -2922,6 +2926,9 @@ mrb_float_read(const char *string, char **endPtr) ...@@ -2922,6 +2926,9 @@ mrb_float_read(const char *string, char **endPtr)
} }
while (isdigit(*p)) { while (isdigit(*p)) {
exp = exp * 10 + (*p - '0'); exp = exp * 10 + (*p - '0');
if (exp > 19999) {
exp = 19999;
}
p += 1; p += 1;
} }
} }
......
...@@ -596,10 +596,14 @@ assert('String#to_f', '15.2.10.5.38') do ...@@ -596,10 +596,14 @@ assert('String#to_f', '15.2.10.5.38') do
a = ''.to_f a = ''.to_f
b = '123456789'.to_f b = '123456789'.to_f
c = '12345.6789'.to_f c = '12345.6789'.to_f
d = '1e-2147483648'.to_f
e = '1e2147483648'.to_f
assert_float(0.0, a) assert_float(0.0, a)
assert_float(123456789.0, b) assert_float(123456789.0, b)
assert_float(12345.6789, c) assert_float(12345.6789, c)
assert_float(0, d)
assert_float(Float::INFINITY, e)
end end
assert('String#to_i', '15.2.10.5.39') do assert('String#to_i', '15.2.10.5.39') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment