window(fill): bounds check the memcpy op
Bounds check our window before performing any direct buffer access. This affects clear and fill, and allows a window to technically be out of bounds, but only the visual portion of the window will be filled.
This commit is contained in:
parent
cce22e8850
commit
f7f4606f1d
1 changed files with 3 additions and 2 deletions
|
@ -221,9 +221,10 @@ pub fn fill(self: Window, cell: Cell) void {
|
||||||
} else {
|
} else {
|
||||||
// Non-contiguous. Iterate over rows an memset
|
// Non-contiguous. Iterate over rows an memset
|
||||||
var row: usize = self.y_off;
|
var row: usize = self.y_off;
|
||||||
while (row < (self.height + self.y_off)) : (row += 1) {
|
const last_row = @min(self.height + self.y_off, self.screen.height - self.y_off);
|
||||||
|
while (row < last_row) : (row += 1) {
|
||||||
const start = self.x_off + (row * self.screen.width);
|
const start = self.x_off + (row * self.screen.width);
|
||||||
const end = start + self.width;
|
const end = @min(start + self.width, start + (self.screen.width - self.x_off));
|
||||||
@memset(self.screen.buf[start..end], cell);
|
@memset(self.screen.buf[start..end], cell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue