zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit bfc0c35689cd5781a3493bdd9c9b8d527847c7a2 (tree)
parent 951fc09a7e174f8f7cb7384d1fd56dcae9ac73da
Author: mlugg <mlugg@mlugg.co.uk>
Date:   Tue, 26 Mar 2024 14:10:35 +0000

Value: fix underflow reading large `u64` values from packed memory

Diffstat:
Msrc/Value.zig | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/Value.zig b/src/Value.zig @@ -787,12 +787,12 @@ pub fn readFromPackedMemory( if (bits == 0) return mod.intValue(ty, 0); // Fast path for integers <= u64 - if (bits <= 64) { - return mod.intValue( - ty, - std.mem.readVarPackedInt(i64, buffer, bit_offset, bits, endian, int_info.signedness), - ); - } + if (bits <= 64) switch (int_info.signedness) { + // Use different backing types for unsigned vs signed to avoid the need to go via + // a larger type like `i128`. + .unsigned => return mod.intValue(ty, std.mem.readVarPackedInt(u64, buffer, bit_offset, bits, endian, .unsigned)), + .signed => return mod.intValue(ty, std.mem.readVarPackedInt(i64, buffer, bit_offset, bits, endian, .signed)), + }; // Slow path, we have to construct a big-int const abi_size = @as(usize, @intCast(ty.abiSize(mod)));