From ca6a67f6891e560d640ba4226d0535a5f87ba990 Mon Sep 17 00:00:00 2001 From: 00JCIV00 Date: Fri, 2 Aug 2024 22:34:08 -0400 Subject: [PATCH] window(fill) bounds check for start and end positions in both conditions --- src/Window.zig | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Window.zig b/src/Window.zig index a19e954..817dc2f 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -217,7 +217,7 @@ pub fn fill(self: Window, cell: Cell) void { return; if (self.x_off == 0 and self.width == self.screen.width) { // we have a full width window, therefore contiguous memory. - const start = self.y_off * self.width; + const start = @min(self.y_off * self.width, self.screen.buf.len); const end = @min(start + (self.height * self.width), self.screen.buf.len); @memset(self.screen.buf[start..end], cell); } else { @@ -225,8 +225,9 @@ pub fn fill(self: Window, cell: Cell) void { var row: usize = self.y_off; const last_row = @min(self.height + self.y_off, self.screen.height); while (row < last_row) : (row += 1) { - const start = self.x_off + (row * self.screen.width); - const end = @min(start + self.width, start + (self.screen.width - self.x_off)); + const start = @min(self.x_off + (row * self.screen.width), self.screen.buf.len); + var end = @min(start + self.width, start + (self.screen.width - self.x_off)); + end = @min(end, self.screen.buf.len); @memset(self.screen.buf[start..end], cell); } }