mirror of
https://github.com/ziglang/zig.git
synced 2025-12-30 18:13:19 +00:00
std: fix potential bug in parseInt
This commit is contained in:
parent
93d1c2d6d4
commit
ce41ddcd23
@ -1374,6 +1374,10 @@ test "parseInt" {
|
||||
std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));
|
||||
std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));
|
||||
std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));
|
||||
std.testing.expectError(error.InvalidCharacter, parseInt(u32, "_10_", 10));
|
||||
std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10_", 10));
|
||||
std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x10_", 10));
|
||||
std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10", 10));
|
||||
std.testing.expect((try parseInt(u8, "255", 10)) == 255);
|
||||
std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));
|
||||
|
||||
@ -1454,6 +1458,8 @@ fn parseWithSign(
|
||||
|
||||
var x: T = 0;
|
||||
|
||||
if (buf_start[0] == '_' or buf_start[buf_start.len - 1] == '_') return error.InvalidCharacter;
|
||||
|
||||
for (buf_start) |c| {
|
||||
if (c == '_') continue;
|
||||
const digit = try charToDigit(c, buf_radix);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user