Added some various integer overflow protections

This commit is contained in:
00JCIV00 2024-02-28 20:08:49 -05:00 committed by Tim Culverhouse
parent 32a4b4baab
commit 8d842c8b44
3 changed files with 5 additions and 3 deletions

View file

@ -288,7 +288,7 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print
if (row >= self.height) break :blk true; if (row >= self.height) break :blk true;
const s = grapheme.bytes(segment.text); const s = grapheme.bytes(segment.text);
if (std.mem.eql(u8, s, "\n")) { if (std.mem.eql(u8, s, "\n")) {
row += 1; row +|= 1;
col = 0; col = 0;
continue; continue;
} }
@ -433,7 +433,7 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print
.style = segment.style, .style = segment.style,
.link = segment.link, .link = segment.link,
}); });
col += w; col +|= w;
} }
} else false; } else false;
return .{ return .{

View file

@ -1,3 +1,5 @@
//! Specialized TUI Widgets
pub const border = @import("widgets/border.zig"); pub const border = @import("widgets/border.zig");
pub const alignment = @import("widgets/alignment.zig"); pub const alignment = @import("widgets/alignment.zig");
pub const Scrollbar = @import("widgets/Scrollbar.zig"); pub const Scrollbar = @import("widgets/Scrollbar.zig");

View file

@ -70,7 +70,7 @@ pub fn drawTable(
.{ .limit = item_width }, .{ .limit = item_width },
.{ .limit = 1 }, .{ .limit = 1 },
); );
var hdr = vaxis.widgets.alignment.center(hdr_win, @min(item_width - 1, hdr_txt.len), 1); var hdr = vaxis.widgets.alignment.center(hdr_win, @min(item_width - 1, hdr_txt.len + 1), 1);
hdr_win.fill(.{ .style = .{ .bg = hdr_bg } }); hdr_win.fill(.{ .style = .{ .bg = hdr_bg } });
var seg = [_]vaxis.Cell.Segment{ .{ var seg = [_]vaxis.Cell.Segment{ .{
.text = hdr_txt, .text = hdr_txt,