TypedValue: fix crash when string-like aggregate has undefined element

Closes #6334
This commit is contained in:
Veikka Tuominen 2023-01-22 13:29:05 +02:00
parent 23b7d28896
commit 92dfc07489

View File

@ -176,7 +176,9 @@ pub fn print(
var i: u32 = 0;
while (i < max_len) : (i += 1) {
buf[i] = std.math.cast(u8, val.fieldValue(ty, i).toUnsignedInt(target)) orelse break :str;
const elem = val.fieldValue(ty, i);
if (elem.isUndef()) break :str;
buf[i] = std.math.cast(u8, elem.toUnsignedInt(target)) orelse break :str;
}
const truncated = if (len > max_string_len) " (truncated)" else "";
@ -390,6 +392,7 @@ pub fn print(
while (i < max_len) : (i += 1) {
var elem_buf: Value.ElemValueBuffer = undefined;
const elem_val = payload.ptr.elemValueBuffer(mod, i, &elem_buf);
if (elem_val.isUndef()) break :str;
buf[i] = std.math.cast(u8, elem_val.toUnsignedInt(target)) orelse break :str;
}