an experimental irc client

ui: fix scrollbar integer overflow on channels with lots of messages

Reported-by: erk on IRC

rockorager.dev b397cdf8 3f4baf75

verified
+5 -2
+5 -2
src/Scrollbar.zig
··· 58 58 @memset(surface.buffer, empty); 59 59 60 60 // (view_size / total) * window height = size of the scroll bar 61 - const bar_height = @max(std.math.divCeil(usize, self.view_size * max.height, self.total) catch unreachable, 1); 61 + const premul1 = std.math.mulWide(u16, self.view_size, max.height); 62 + const bar_height = @max(std.math.divCeil(usize, premul1, self.total) catch unreachable, 1); 62 63 64 + // Premultiply. We use mulWide to ensure we never overflow 65 + const premul2 = std.math.mulWide(u16, self.bottom, max.height); 63 66 // The row of the last cell of the bottom of the bar 64 - const bar_bottom = (max.height - 1) -| (std.math.divCeil(usize, self.bottom * max.height, self.total) catch unreachable); 67 + const bar_bottom = (max.height - 1) -| (std.math.divCeil(usize, premul2, self.total) catch unreachable); 65 68 66 69 var i: usize = 0; 67 70 while (i <= bar_height) : (i += 1)