terminal/formatter: safely cast discarding.count to usize

The Discarding writer count field is u64, but appendNTimes expects
usize which is u32 on 32-bit targets like arm-linux-androideabi.
Use std.math.cast instead of @intCast to safely handle the
conversion, returning WriteFailed on overflow rather than risking
undefined behavior.
This commit is contained in:
Mitchell Hashimoto
2026-03-14 15:19:56 -07:00
parent 1e21ac1190
commit 4ad7d03c56

View File

@@ -293,7 +293,7 @@ pub const TerminalFormatter = struct {
m.map.appendNTimes(
m.alloc,
self.terminal.screens.active.pages.getTopLeft(.screen),
discarding.count,
std.math.cast(usize, discarding.count) orelse return error.WriteFailed,
) catch return error.WriteFailed;
}
}
@@ -331,7 +331,7 @@ pub const TerminalFormatter = struct {
m.map.appendNTimes(
m.alloc,
self.terminal.screens.active.pages.getTopLeft(.screen),
discarding.count,
std.math.cast(usize, discarding.count) orelse return error.WriteFailed,
) catch return error.WriteFailed;
}
}
@@ -415,7 +415,7 @@ pub const TerminalFormatter = struct {
.y = last.y,
};
} else self.terminal.screens.active.pages.getTopLeft(.screen),
discarding.count,
std.math.cast(usize, discarding.count) orelse return error.WriteFailed,
) catch return error.WriteFailed;
}
}