From e73fe08a3eacce35ef103f2455b3627b466948c2 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sun, 4 Oct 2020 19:04:24 +0800 Subject: [PATCH] graphics-server: bounds-check for negative coords This prevents us from drawing pixels off the screen. Signed-off-by: Sean Cross --- examples/graphics-server/src/backend/betrusted.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/graphics-server/src/backend/betrusted.rs b/examples/graphics-server/src/backend/betrusted.rs index a5a4b31aa..1ac69cee8 100644 --- a/examples/graphics-server/src/backend/betrusted.rs +++ b/examples/graphics-server/src/backend/betrusted.rs @@ -107,6 +107,9 @@ impl DrawTarget for XousDisplay { /// Draw a `Pixel` that has a color defined as `BinaryColor`. fn draw_pixel(&mut self, pixel: Pixel) -> 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;