diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-12-21 16:40:30 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-12-27 15:13:14 +0200 |
| commit | 622311fb9ac7ee6d93dcb8cda4b608751f7e092a (patch) | |
| tree | ef54a9f6bc53919a4ef4f01aae2d9e3573aad871 /lib/std/leb128.zig | |
| parent | 54160e7f6aecb4628df633ceaef4c6d956429a3d (diff) | |
| download | zig-622311fb9ac7ee6d93dcb8cda4b608751f7e092a.tar.gz zig-622311fb9ac7ee6d93dcb8cda4b608751f7e092a.zip | |
update uses of overflow arithmetic builtins
Diffstat (limited to 'lib/std/leb128.zig')
| -rw-r--r-- | lib/std/leb128.zig | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/std/leb128.zig b/lib/std/leb128.zig index f72070d13d..bc5955d16a 100644 --- a/lib/std/leb128.zig +++ b/lib/std/leb128.zig @@ -15,11 +15,11 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T { while (group < max_group) : (group += 1) { const byte = try reader.readByte(); - var temp = @as(U, byte & 0x7f); - if (@shlWithOverflow(U, temp, group * 7, &temp)) return error.Overflow; + const ov = @shlWithOverflow(@as(U, byte & 0x7f), group * 7); + if (ov[1] != 0) return error.Overflow; - value |= temp; + value |= ov[0]; if (byte & 0x80 == 0) break; } else { return error.Overflow; @@ -65,13 +65,13 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T { while (group < max_group) : (group += 1) { const byte = try reader.readByte(); - var temp = @as(U, byte & 0x7f); const shift = group * 7; - if (@shlWithOverflow(U, temp, shift, &temp)) { + const ov = @shlWithOverflow(@as(U, byte & 0x7f), shift); + if (ov[1] != 0) { // Overflow is ok so long as the sign bit is set and this is the last byte if (byte & 0x80 != 0) return error.Overflow; - if (@bitCast(S, temp) >= 0) return error.Overflow; + if (@bitCast(S, ov[0]) >= 0) return error.Overflow; // and all the overflowed bits are 1 const remaining_shift = @intCast(u3, @typeInfo(U).Int.bits - @as(u16, shift)); @@ -80,14 +80,14 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T { } else { // If we don't overflow and this is the last byte and the number being decoded // is negative, check that the remaining bits are 1 - if ((byte & 0x80 == 0) and (@bitCast(S, temp) < 0)) { + if ((byte & 0x80 == 0) and (@bitCast(S, ov[0]) < 0)) { const remaining_shift = @intCast(u3, @typeInfo(U).Int.bits - @as(u16, shift)); const remaining_bits = @bitCast(i8, byte | 0x80) >> remaining_shift; if (remaining_bits != -1) return error.Overflow; } } - value |= temp; + value |= ov[0]; if (byte & 0x80 == 0) { const needs_sign_ext = group + 1 < max_group; if (byte & 0x40 != 0 and needs_sign_ext) { |
