authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-03-29 06:54:23+02:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-03-29 11:50:41+02:00
logd1202b1f6627eb1d8955fc8157685871bafe0d24
treed8a8b5dd2f734e69e31fa9b2da693431005816ff
parentf9db21f03eaf0b800e531d12c2677d579eceaff0

fix overflow in parseFloat


2 files changed, 6 insertions(+), 6 deletions(-)

lib/std/fmt/parse_float.zig+3-1
...@@ -306,7 +306,7 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {...@@ -306,7 +306,7 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
306306
307 State.Exponent => {307 State.Exponent => {
308 if (isDigit(c)) {308 if (isDigit(c)) {
309 if (exponent < std.math.maxInt(i32)) {309 if (exponent < std.math.maxInt(i32) / 10) {
310 exponent *= 10;310 exponent *= 10;
311 exponent += @intCast(i32, c - '0');311 exponent += @intCast(i32, c - '0');
312 }312 }
...@@ -417,6 +417,8 @@ test "fmt.parseFloat" {...@@ -417,6 +417,8 @@ test "fmt.parseFloat" {
417 expectEqual((try parseFloat(T, "inF")), std.math.inf(T));417 expectEqual((try parseFloat(T, "inF")), std.math.inf(T));
418 expectEqual((try parseFloat(T, "-INF")), -std.math.inf(T));418 expectEqual((try parseFloat(T, "-INF")), -std.math.inf(T));
419419
420 expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T));
421
420 if (T != f16) {422 if (T != f16) {
421 expect(approxEq(T, try parseFloat(T, "1e-2"), 0.01, epsilon));423 expect(approxEq(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
422 expect(approxEq(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));424 expect(approxEq(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
lib/std/json/test.zig+3-5
...@@ -1751,11 +1751,9 @@ test "i_number_double_huge_neg_exp" {...@@ -1751,11 +1751,9 @@ test "i_number_double_huge_neg_exp" {
1751}1751}
17521752
1753test "i_number_huge_exp" {1753test "i_number_huge_exp" {
1754 return error.SkipZigTest;1754 any(
1755 // FIXME Integer overflow in parseFloat1755 \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
1756 // any(1756 );
1757 // \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
1758 // );
1759}1757}
17601758
1761test "i_number_neg_int_huge_exp" {1759test "i_number_neg_int_huge_exp" {