mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 13:30:45 +00:00
fix overflow in parseFloat
This commit is contained in:
parent
f9db21f03e
commit
d1202b1f66
@ -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));
|
||||
|
||||
@ -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" {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user