authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-04-21 15:30:06-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-22 22:42:46-04:00
logce41ddcd2382ef9c3866ccdf25a526a8eca5fe51
treebf3f2b89af79cfad9c57c090fc7c865e5c204285
parent93d1c2d6d4092bd17dc27298294581b77fa68881

std: fix potential bug in parseInt


1 files changed, 6 insertions(+), 0 deletions(-)

lib/std/fmt.zig+6
......@@ -1374,6 +1374,10 @@ test "parseInt" {
13741374 std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));
13751375 std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));
13761376 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));
1377 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "_10_", 10));
1378 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10_", 10));
1379 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x10_", 10));
1380 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10", 10));
13771381 std.testing.expect((try parseInt(u8, "255", 10)) == 255);
13781382 std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));
13791383
......@@ -1454,6 +1458,8 @@ fn parseWithSign(
14541458
14551459 var x: T = 0;
14561460
1461 if (buf_start[0] == '_' or buf_start[buf_start.len - 1] == '_') return error.InvalidCharacter;
1462
14571463 for (buf_start) |c| {
14581464 if (c == '_') continue;
14591465 const digit = try charToDigit(c, buf_radix);