authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-04-23 09:57:22+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-04-23 09:57:22+02:00
log57ec183c09e1c9d313fc6ce35cdbfb4b3aa08016
treef4afcd133a45c9dfdadb3689e717587b4ecf6b0b
parent0f8fc3b924ac0d971a800bc6e3b6c931612e06a6

Fix reading of signed leb128 values


1 files changed, 11 insertions(+), 10 deletions(-)

std/debug.zig+11-10
......@@ -1460,7 +1460,7 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
14601460 2 => try in_stream.readIntLittle(u16),
14611461 4 => try in_stream.readIntLittle(u32),
14621462 8 => try in_stream.readIntLittle(u64),
1463 -1 => if (signed) @intCast(u64, try readILeb128(in_stream)) else try readULeb128(in_stream),
1463 -1 => if (signed) @bitCast(u64, try readILeb128(in_stream)) else try readULeb128(in_stream),
14641464 else => @compileError("Invalid size"),
14651465 },
14661466 },
......@@ -2272,14 +2272,15 @@ fn readILeb128Mem(ptr: *[*]const u8) !i64 {
22722272 const byte = ptr.*[i];
22732273 i += 1;
22742274
2275 var operand: i64 = undefined;
2276 if (@shlWithOverflow(i64, byte & 0b01111111, @intCast(u6, shift), &operand)) return error.InvalidDebugInfo;
2275 if (shift > @sizeOf(i64) * 8) return error.InvalidDebugInfo;
22772276
2278 result |= operand;
2277 result |= i64(byte & 0b01111111) << @intCast(u6, shift);
22792278 shift += 7;
22802279
22812280 if ((byte & 0b10000000) == 0) {
2282 if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) result |= -(i64(1) << @intCast(u6, shift));
2281 if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) {
2282 result |= -(i64(1) << @intCast(u6, shift));
2283 }
22832284 ptr.* += i;
22842285 return result;
22852286 }
......@@ -2323,15 +2324,15 @@ fn readILeb128(in_stream: var) !i64 {
23232324 while (true) {
23242325 const byte = try in_stream.readByte();
23252326
2326 var operand: i64 = undefined;
2327
2328 if (@shlWithOverflow(i64, byte & 0b01111111, @intCast(u6, shift), &operand)) return error.InvalidDebugInfo;
2327 if (shift > @sizeOf(i64) * 8) return error.InvalidDebugInfo;
23292328
2330 result |= operand;
2329 result |= i64(byte & 0b01111111) << @intCast(u6, shift);
23312330 shift += 7;
23322331
23332332 if ((byte & 0b10000000) == 0) {
2334 if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) result |= -(i64(1) << @intCast(u6, shift));
2333 if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) {
2334 result |= -(i64(1) << @intCast(u6, shift));
2335 }
23352336 return result;
23362337 }
23372338 }