Commit d1202b1f66

xackus <14938807+xackus@users.noreply.github.com>
2020-03-29 06:54:23
fix overflow in parseFloat
1 parent f9db21f
Changed files (2)
lib
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));
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" {