From 8d842c8b44fd858951db7452418207e45eff5a8a Mon Sep 17 00:00:00 2001 From: 00JCIV00 Date: Wed, 28 Feb 2024 20:08:49 -0500 Subject: [PATCH] Added some various integer overflow protections --- src/Window.zig | 4 ++-- src/widgets.zig | 2 ++ src/widgets/Table.zig | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Window.zig b/src/Window.zig index eb61fc5..ef88b30 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -288,7 +288,7 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print if (row >= self.height) break :blk true; const s = grapheme.bytes(segment.text); if (std.mem.eql(u8, s, "\n")) { - row += 1; + row +|= 1; col = 0; continue; } @@ -433,7 +433,7 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print .style = segment.style, .link = segment.link, }); - col += w; + col +|= w; } } else false; return .{ diff --git a/src/widgets.zig b/src/widgets.zig index 5b97e82..d3c2e51 100644 --- a/src/widgets.zig +++ b/src/widgets.zig @@ -1,3 +1,5 @@ +//! Specialized TUI Widgets + pub const border = @import("widgets/border.zig"); pub const alignment = @import("widgets/alignment.zig"); pub const Scrollbar = @import("widgets/Scrollbar.zig"); diff --git a/src/widgets/Table.zig b/src/widgets/Table.zig index a4e96cc..e6a9704 100644 --- a/src/widgets/Table.zig +++ b/src/widgets/Table.zig @@ -70,7 +70,7 @@ pub fn drawTable( .{ .limit = item_width }, .{ .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 } }); var seg = [_]vaxis.Cell.Segment{ .{ .text = hdr_txt,