terminal: fix uninitialized memory in Cell init

pull/8319/head
Mitchell Hashimoto 2025-08-20 20:15:47 -07:00
parent 3ce043123b
commit be51f3e729
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
1 changed files with 7 additions and 4 deletions

View File

@ -2043,10 +2043,13 @@ pub const Cell = packed struct(u64) {
/// Helper to make a cell that just has a codepoint. /// Helper to make a cell that just has a codepoint.
pub fn init(cp: u21) Cell { pub fn init(cp: u21) Cell {
return .{ // We have to use this bitCast here to ensure that our memory is
.content_tag = .codepoint, // zeroed. Otherwise, the content below will leave some uninitialized
.content = .{ .codepoint = cp }, // memory in the packed union. Valgrind verifies this.
}; var cell: Cell = @bitCast(@as(u64, 0));
cell.content_tag = .codepoint;
cell.content = .{ .codepoint = cp };
return cell;
} }
pub fn isZero(self: Cell) bool { pub fn isZero(self: Cell) bool {