mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-18 13:30:29 +00:00
terminal/formatter: safely cast discarding.count to usize
The Discarding writer count field is u64, but several call sites pass it where a usize is expected. On wasm32-freestanding, usize is 32-bit, so this caused compilation errors. Use std.math.cast instead of a bare @intCast so that overflow is handled gracefully, returning WriteFailed rather than triggering safety-checked undefined behavior at runtime.
This commit is contained in:
@@ -688,7 +688,7 @@ pub const ScreenFormatter = struct {
|
||||
.y = last.y,
|
||||
};
|
||||
} else self.screen.pages.getTopLeft(.screen),
|
||||
discarding.count,
|
||||
std.math.cast(usize, discarding.count) orelse return error.WriteFailed,
|
||||
) catch return error.WriteFailed;
|
||||
}
|
||||
}
|
||||
@@ -1234,7 +1234,10 @@ pub const PageFormatter = struct {
|
||||
&discarding.writer,
|
||||
&style,
|
||||
);
|
||||
for (0..discarding.count) |_| map.map.append(map.alloc, .{
|
||||
for (0..std.math.cast(
|
||||
usize,
|
||||
discarding.count,
|
||||
) orelse return error.WriteFailed) |_| map.map.append(map.alloc, .{
|
||||
.x = x,
|
||||
.y = y,
|
||||
}) catch return error.WriteFailed;
|
||||
@@ -1291,7 +1294,10 @@ pub const PageFormatter = struct {
|
||||
&discarding.writer,
|
||||
uri,
|
||||
);
|
||||
for (0..discarding.count) |_| map.map.append(map.alloc, .{
|
||||
for (0..std.math.cast(
|
||||
usize,
|
||||
discarding.count,
|
||||
) orelse return error.WriteFailed) |_| map.map.append(map.alloc, .{
|
||||
.x = x,
|
||||
.y = y,
|
||||
}) catch return error.WriteFailed;
|
||||
@@ -1309,7 +1315,10 @@ pub const PageFormatter = struct {
|
||||
if (self.point_map) |*map| {
|
||||
var discarding: std.Io.Writer.Discarding = .init(&.{});
|
||||
try self.writeCell(tag, &discarding.writer, cell);
|
||||
for (0..discarding.count) |_| map.map.append(map.alloc, .{
|
||||
for (0..std.math.cast(
|
||||
usize,
|
||||
discarding.count,
|
||||
) orelse return error.WriteFailed) |_| map.map.append(map.alloc, .{
|
||||
.x = x,
|
||||
.y = y,
|
||||
}) catch return error.WriteFailed;
|
||||
|
||||
Reference in New Issue
Block a user