graphics-server: bounds-check for negative coords

This prevents us from drawing pixels off the screen.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-10-04 19:04:24 +08:00
parent 8759f552f7
commit e73fe08a3e

View file

@ -107,6 +107,9 @@ impl DrawTarget<BinaryColor> for XousDisplay {
/// Draw a `Pixel` that has a color defined as `BinaryColor`.
fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
let Pixel(coord, color) = pixel;
if coord.x < 0 || coord.y < 0 {
return Ok(())
}
if coord.x < FB_WIDTH_PIXELS as _ && coord.y < FB_LINES as _ {
let framebuffer = self.fb.as_mut_ptr() as *mut u32;
let offset = (coord.x / 32 + coord.y * FB_WIDTH_WORDS as i32) as usize;