fix overflow in parseFloat

This commit is contained in:
xackus 2020-03-29 06:54:23 +02:00
parent f9db21f03e
commit d1202b1f66
2 changed files with 6 additions and 6 deletions

View File

@ -306,7 +306,7 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
State.Exponent => {
if (isDigit(c)) {
if (exponent < std.math.maxInt(i32)) {
if (exponent < std.math.maxInt(i32) / 10) {
exponent *= 10;
exponent += @intCast(i32, c - '0');
}
@ -417,6 +417,8 @@ test "fmt.parseFloat" {
expectEqual((try parseFloat(T, "inF")), std.math.inf(T));
expectEqual((try parseFloat(T, "-INF")), -std.math.inf(T));
expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T));
if (T != f16) {
expect(approxEq(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
expect(approxEq(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));

View File

@ -1751,11 +1751,9 @@ test "i_number_double_huge_neg_exp" {
}
test "i_number_huge_exp" {
return error.SkipZigTest;
// FIXME Integer overflow in parseFloat
// any(
// \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
// );
any(
\\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
);
}
test "i_number_neg_int_huge_exp" {