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.
This commit is contained in:
mlugg 2024-04-16 22:38:54 +01:00
parent 03ad862197
commit 3c45a94528
No known key found for this signature in database
GPG Key ID: 3F5B7DCCBF4AF02E

View File

@ -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)) {