overflow tests
This commit is contained in:
parent
d555994960
commit
609ab3d2b6
@ -34,7 +34,7 @@ pub fn uvarint(buf: []const u8) error{Overflow}!Varint {
|
||||
return Varint{ .value = x | (@as(u64, b) << s), .bytesRead = i + 1 };
|
||||
}
|
||||
x |= (@as(u64, b & 0x7f) << s);
|
||||
s += 7;
|
||||
s = try std.math.add(u6, s, 7);
|
||||
}
|
||||
|
||||
return Varint{
|
||||
@ -88,3 +88,17 @@ test "uvarint" {
|
||||
try testing.expectEqual(n, got.bytesRead);
|
||||
}
|
||||
}
|
||||
|
||||
const overflowTest = struct {
|
||||
arr: []const u8,
|
||||
};
|
||||
|
||||
test "overflow" {
|
||||
for ([_][]const u8{
|
||||
&[_]u8{ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x2 },
|
||||
&[_]u8{ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x1, 0, 0 },
|
||||
&[_]u8{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
}) |t| {
|
||||
try testing.expectError(error.Overflow, uvarint(t));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user