diff --git a/lib/std/fmt/parse_float.zig b/lib/std/fmt/parse_float.zig index 0268ca96cc..14844e27c8 100644 --- a/lib/std/fmt/parse_float.zig +++ b/lib/std/fmt/parse_float.zig @@ -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)); diff --git a/lib/std/json/test.zig b/lib/std/json/test.zig index 6873fa038a..5d46b75a48 100644 --- a/lib/std/json/test.zig +++ b/lib/std/json/test.zig @@ -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" {