From 8f3331e8c1fc08257b2f632fac001f23455435ee Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 29 Oct 2023 00:53:21 +0200 Subject: [PATCH] Fix assert checking input size in wxOSX GetSubBitmap() Extend the just added GetSubBitmap() unit test to check for this too. --- src/osx/core/bitmap.cpp | 4 ++-- tests/graphics/bitmap.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index 03066e49be..20718d0e13 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -967,8 +967,8 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const wxCHECK_MSG( IsOk(), wxNullBitmap, wxT("invalid bitmap") ); wxCHECK_MSG((rect.x >= 0) && (rect.y >= 0) && - (rect.x+rect.width <= GetWidth()) && - (rect.y+rect.height <= GetHeight()), + (rect.x+rect.width <= GetLogicalWidth()) && + (rect.y+rect.height <= GetLogicalHeight()), wxNullBitmap, wxT("invalid bitmap region") ); wxBitmap ret; diff --git a/tests/graphics/bitmap.cpp b/tests/graphics/bitmap.cpp index 4249e14516..a8c7ecbf19 100644 --- a/tests/graphics/bitmap.cpp +++ b/tests/graphics/bitmap.cpp @@ -1842,7 +1842,7 @@ TEST_CASE("wxBitmap::GetSubBitmap", "[bitmap]") // Extracting sub-bitmap of the entire bitmap size should return the bitmap // of the same size. -#if wxHAS_DPI_INDEPENDENT_PIXELS +#ifdef wxHAS_DPI_INDEPENDENT_PIXELS const wxRect rectAll(wxPoint(0, 0), sizeLog); #else const wxRect rectAll(wxPoint(0, 0), sizePhy); @@ -1852,6 +1852,11 @@ TEST_CASE("wxBitmap::GetSubBitmap", "[bitmap]") CHECK( sub.GetDIPSize() == sizeLog ); CHECK( sub.GetSize() == sizePhy ); CHECK( sub.GetScaleFactor() == scale ); + + // Using incorrect bounds should assert. + wxRect rectInvalid = rectAll; + rectInvalid.Offset(1, 0); + WX_ASSERT_FAILS_WITH_ASSERT( bmp.GetSubBitmap(rectInvalid) ); } #endif // ports with scaled bitmaps support