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.
This commit is contained in:
Qwerasd
2024-08-27 01:00:12 -04:00
parent a6992baa30
commit d43d5b26ee

View File

@ -948,17 +948,15 @@ const ReflowCursor = struct {
}, },
} }
// Prevent integrity checks from tripping // These will create issues by trying to clone managed memory that
// while copying graphemes and hyperlinks. // isn't set if the current dst row needs to be moved to a new page.
if (comptime std.debug.runtime_safety) { // 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; self.page_cell.style_id = stylepkg.default_id;
}
// Copy grapheme data. // Copy grapheme data.
if (cell.content_tag == .codepoint_grapheme) { if (cell.content_tag == .codepoint_grapheme) {
// The tag is asserted to be .codepoint in setGraphemes.
self.page_cell.content_tag = .codepoint;
// Copy the graphemes // Copy the graphemes
const cps = src_page.lookupGrapheme(cell).?; 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. // This shouldn't fail since we made sure we have space above.
try self.page.setGraphemes(self.page_row, self.page_cell, cps); try self.page.setGraphemes(self.page_row, self.page_cell, cps);
} }
@ -1015,8 +1011,6 @@ const ReflowCursor = struct {
); );
} orelse src_id; } orelse src_id;
self.page_row.hyperlink = true;
// We expect this to succeed due to the // We expect this to succeed due to the
// hyperlinkCapacity check we did before. // hyperlinkCapacity check we did before.
try self.page.setHyperlink( try self.page.setHyperlink(