this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: integer overflow crash when screen w * h > max(u16)

authored by

CJ van den Berg and committed by
Tim Culverhouse
5a8112b7 77f57958

+12 -12
+2 -2
src/InternalScreen.zig
··· 47 47 /// sets each cell to the default cell 48 48 pub fn init(alloc: std.mem.Allocator, w: u16, h: u16) !InternalScreen { 49 49 var screen = InternalScreen{ 50 - .buf = try alloc.alloc(InternalCell, w * h), 50 + .buf = try alloc.alloc(InternalCell, @as(usize, @intCast(w)) * h), 51 51 }; 52 52 for (screen.buf, 0..) |_, i| { 53 53 screen.buf[i] = .{ ··· 87 87 // height out of bounds 88 88 return; 89 89 } 90 - const i = (row * self.width) + col; 90 + const i = (@as(usize, @intCast(row)) * self.width) + col; 91 91 assert(i < self.buf.len); 92 92 self.buf[i].char.clearRetainingCapacity(); 93 93 self.buf[i].char.appendSlice(cell.char.grapheme) catch {
+3 -3
src/Screen.zig
··· 33 33 const w = winsize.cols; 34 34 const h = winsize.rows; 35 35 const self = Screen{ 36 - .buf = try alloc.alloc(Cell, w * h), 36 + .buf = try alloc.alloc(Cell, @as(usize, @intCast(w)) * h), 37 37 .width = w, 38 38 .height = h, 39 39 .width_pix = winsize.x_pixel, ··· 53 53 if (col >= self.width or 54 54 row >= self.height) 55 55 return; 56 - const i = (row * self.width) + col; 56 + const i = (@as(usize, @intCast(row)) * self.width) + col; 57 57 assert(i < self.buf.len); 58 58 self.buf[i] = cell; 59 59 } ··· 62 62 if (col >= self.width or 63 63 row >= self.height) 64 64 return null; 65 - const i = (row * self.width) + col; 65 + const i = (@as(usize, @intCast(row)) * self.width) + col; 66 66 assert(i < self.buf.len); 67 67 return self.buf[i]; 68 68 }
+2 -2
src/Vaxis.zig
··· 315 315 /// draws the screen to the terminal 316 316 pub fn render(self: *Vaxis, tty: AnyWriter) !void { 317 317 defer self.refresh = false; 318 - assert(self.screen.buf.len == self.screen.width * self.screen.height); // correct size 318 + assert(self.screen.buf.len == @as(usize, @intCast(self.screen.width)) * self.screen.height); // correct size 319 319 assert(self.screen.buf.len == self.screen_last.buf.len); // same size 320 320 321 321 // Set up sync before we write anything ··· 353 353 if (self.caps.kitty_graphics) 354 354 try tty.writeAll(ctlseqs.kitty_graphics_clear); 355 355 356 - var i: u16 = 0; 356 + var i: usize = 0; 357 357 while (i < self.screen.buf.len) { 358 358 const cell = self.screen.buf[i]; 359 359 const w: u16 = blk: {
+4 -4
src/Window.zig
··· 198 198 self.screen.width < self.x_off or 199 199 self.screen.height < self.y_off) 200 200 return; 201 - const first_row: u16 = @intCast(@max(self.y_off, 0)); 201 + const first_row: usize = @intCast(@max(self.y_off, 0)); 202 202 if (self.x_off == 0 and self.width == self.screen.width) { 203 203 // we have a full width window, therefore contiguous memory. 204 204 const start = @min(first_row * self.width, self.screen.buf.len); 205 - const end = @min(start + (self.height * self.width), self.screen.buf.len); 205 + const end = @min(start + (@as(usize, @intCast(self.height)) * self.width), self.screen.buf.len); 206 206 @memset(self.screen.buf[start..end], cell); 207 207 } else { 208 208 // Non-contiguous. Iterate over rows an memset 209 - var row: u16 = first_row; 210 - const first_col: u16 = @max(self.x_off, 0); 209 + var row: usize = first_row; 210 + const first_col: usize = @max(self.x_off, 0); 211 211 const last_row = @min(self.height + self.y_off, self.screen.height); 212 212 while (row < last_row) : (row += 1) { 213 213 const start = @min(first_col + (row * self.screen.width), self.screen.buf.len);
+1 -1
src/widgets/terminal/Screen.zig
··· 95 95 /// sets each cell to the default cell 96 96 pub fn init(alloc: std.mem.Allocator, w: u16, h: u16) !Screen { 97 97 var screen = Screen{ 98 - .buf = try alloc.alloc(Cell, w * h), 98 + .buf = try alloc.alloc(Cell, @as(usize, @intCast(w)) * h), 99 99 .scrolling_region = .{ 100 100 .top = 0, 101 101 .bottom = h - 1,