motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 3c45a945285dff00d0eb8160342560bcb7d24cc5 (tree)
parent 03ad862197d27fb079d16cabdf2026da23aa2653
Author: mlugg <mlugg@mlugg.co.uk>
Date:   Tue, 16 Apr 2024 22:38:54 +0100

Value: fix out-of-bounds slice access writing zero-bit undef value

I have no idea why this wasn't being hit on master before.

Diffstat:
Msrc/Value.zig | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/Value.zig b/src/Value.zig @@ -469,7 +469,9 @@ pub fn writeToPackedMemory( const endian = target.cpu.arch.endian(); if (val.isUndef(mod)) { const bit_size: usize = @intCast(ty.bitSize(mod)); - std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian); + if (bit_size != 0) { + std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian); + } return; } switch (ty.zigTypeTag(mod)) {