From d43d5b26ee6625c03e7040e6a5614cd6cbba4eff Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Tue, 27 Aug 2024 01:00:12 -0400 Subject: [PATCH] fix(terminal): avoid trying to clone bad managed memory in reflow If we call `moveLastRowToNewPage` at any point because we failed to copy some managed memory, it tries to copy managed memory that hasn't been cloned yet when moving our progress to a new page. Avoid this by setting our content tag, hyperlink flag, and style id to indicate no managed memory is present on the cell. --- src/terminal/PageList.zig | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/terminal/PageList.zig b/src/terminal/PageList.zig index 523b0e195..5b960a8c1 100644 --- a/src/terminal/PageList.zig +++ b/src/terminal/PageList.zig @@ -948,17 +948,15 @@ const ReflowCursor = struct { }, } - // Prevent integrity checks from tripping - // while copying graphemes and hyperlinks. - if (comptime std.debug.runtime_safety) { - self.page_cell.style_id = stylepkg.default_id; - } + // These will create issues by trying to clone managed memory that + // isn't set if the current dst row needs to be moved to a new page. + // They'll be fixed once we do properly copy the relevant memory. + self.page_cell.content_tag = .codepoint; + self.page_cell.hyperlink = false; + self.page_cell.style_id = stylepkg.default_id; // Copy grapheme data. if (cell.content_tag == .codepoint_grapheme) { - // The tag is asserted to be .codepoint in setGraphemes. - self.page_cell.content_tag = .codepoint; - // Copy the graphemes const cps = src_page.lookupGrapheme(cell).?; @@ -981,8 +979,6 @@ const ReflowCursor = struct { } } - self.page_row.grapheme = true; - // This shouldn't fail since we made sure we have space above. try self.page.setGraphemes(self.page_row, self.page_cell, cps); } @@ -1015,8 +1011,6 @@ const ReflowCursor = struct { ); } orelse src_id; - self.page_row.hyperlink = true; - // We expect this to succeed due to the // hyperlinkCapacity check we did before. try self.page.setHyperlink(