aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2019-04-23 09:57:22 +0200
committerLemonBoy <thatlemon@gmail.com>2019-04-23 09:57:22 +0200
commit57ec183c09e1c9d313fc6ce35cdbfb4b3aa08016 (patch)
treef4afcd133a45c9dfdadb3689e717587b4ecf6b0b
parent0f8fc3b924ac0d971a800bc6e3b6c931612e06a6 (diff)
downloadzig-57ec183c09e1c9d313fc6ce35cdbfb4b3aa08016.tar.gz
zig-57ec183c09e1c9d313fc6ce35cdbfb4b3aa08016.zip
Fix reading of signed leb128 values
-rw-r--r--std/debug.zig21
1 files changed, 11 insertions, 10 deletions
diff --git a/std/debug.zig b/std/debug.zig
index acb1494a90..dd34e4e205 100644
--- a/std/debug.zig
+++ b/std/debug.zig
@@ -1460,7 +1460,7 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
2 => try in_stream.readIntLittle(u16),
4 => try in_stream.readIntLittle(u32),
8 => try in_stream.readIntLittle(u64),
- -1 => if (signed) @intCast(u64, try readILeb128(in_stream)) else try readULeb128(in_stream),
+ -1 => if (signed) @bitCast(u64, try readILeb128(in_stream)) else try readULeb128(in_stream),
else => @compileError("Invalid size"),
},
},
@@ -2272,14 +2272,15 @@ fn readILeb128Mem(ptr: *[*]const u8) !i64 {
const byte = ptr.*[i];
i += 1;
- var operand: i64 = undefined;
- if (@shlWithOverflow(i64, byte & 0b01111111, @intCast(u6, shift), &operand)) return error.InvalidDebugInfo;
+ if (shift > @sizeOf(i64) * 8) return error.InvalidDebugInfo;
- result |= operand;
+ result |= i64(byte & 0b01111111) << @intCast(u6, shift);
shift += 7;
if ((byte & 0b10000000) == 0) {
- if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) result |= -(i64(1) << @intCast(u6, shift));
+ if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) {
+ result |= -(i64(1) << @intCast(u6, shift));
+ }
ptr.* += i;
return result;
}
@@ -2323,15 +2324,15 @@ fn readILeb128(in_stream: var) !i64 {
while (true) {
const byte = try in_stream.readByte();
- var operand: i64 = undefined;
-
- if (@shlWithOverflow(i64, byte & 0b01111111, @intCast(u6, shift), &operand)) return error.InvalidDebugInfo;
+ if (shift > @sizeOf(i64) * 8) return error.InvalidDebugInfo;
- result |= operand;
+ result |= i64(byte & 0b01111111) << @intCast(u6, shift);
shift += 7;
if ((byte & 0b10000000) == 0) {
- if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) result |= -(i64(1) << @intCast(u6, shift));
+ if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) {
+ result |= -(i64(1) << @intCast(u6, shift));
+ }
return result;
}
}