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.pull/11506/head
parent
4ad7d03c56
commit
647f5adf55
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue