From ee21a724c75e5d398c9c227e2aec64452f550749 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 2 Nov 2020 11:01:00 +0100 Subject: [PATCH] LibGfx: Add some more assertions to Gfx::Bitmap Let's also be paranoid about get_pixel() since we started worrying about set_pixel(). :^) --- Libraries/LibGfx/Bitmap.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Libraries/LibGfx/Bitmap.h b/Libraries/LibGfx/Bitmap.h index 24baa2281d7..2aabb3e83ef 100644 --- a/Libraries/LibGfx/Bitmap.h +++ b/Libraries/LibGfx/Bitmap.h @@ -247,11 +247,13 @@ private: inline u8* Bitmap::scanline_u8(int y) { + ASSERT(y >= 0 && y < height()); return reinterpret_cast(m_data) + (y * m_pitch); } inline const u8* Bitmap::scanline_u8(int y) const { + ASSERT(y >= 0 && y < height()); return reinterpret_cast(m_data) + (y * m_pitch); } @@ -268,18 +270,21 @@ inline const RGBA32* Bitmap::scanline(int y) const template<> inline Color Bitmap::get_pixel(int x, int y) const { + ASSERT(x >= 0 && x < width()); return Color::from_rgb(scanline(y)[x]); } template<> inline Color Bitmap::get_pixel(int x, int y) const { + ASSERT(x >= 0 && x < width()); return Color::from_rgba(scanline(y)[x]); } template<> inline Color Bitmap::get_pixel(int x, int y) const { + ASSERT(x >= 0 && x < width()); return Color::from_rgb(m_palette[scanline_u8(y)[x]]); } @@ -300,13 +305,13 @@ inline Color Bitmap::get_pixel(int x, int y) const template<> inline void Bitmap::set_pixel(int x, int y, Color color) { - ASSERT(rect().contains(x, y)); + ASSERT(x >= 0 && x < width()); scanline(y)[x] = color.value(); } template<> inline void Bitmap::set_pixel(int x, int y, Color color) { - ASSERT(rect().contains(x, y)); + ASSERT(x >= 0 && x < width()); scanline(y)[x] = color.value(); // drop alpha } inline void Bitmap::set_pixel(int x, int y, Color color)