cosmetic changes

This commit is contained in:
2022-03-02 06:18:19 +02:00
committed by Motiejus Jakštys
parent 0ccbdc4215
commit a526379fd8
6 changed files with 41 additions and 62 deletions

View File

@@ -103,17 +103,19 @@ pub fn uvarint(buf: []const u8) error{Overflow}!Varint {
var s: u6 = 0;
for (buf) |b, i| {
if (i == maxVarintLen64) {
if (i == maxVarintLen64)
// Catch byte reads past maxVarintLen64.
// See issue https://golang.org/issues/41185
return error.Overflow;
}
if (b < 0x80) {
if (i == maxVarintLen64 - 1 and b > 1) {
return error.Overflow;
}
return Varint{ .value = x | (@as(u64, b) << s), .bytesRead = i + 1 };
return Varint{
.value = x | (@as(u64, b) << s),
.bytesRead = i + 1,
};
}
x |= (@as(u64, b & 0x7f) << s);
s = try std.math.add(u6, s, 7);