Common: Fix copy-construction of empty BITMAP_BASE

The bitmap pointer is not checked at copy construct. This is
an instant segfault if you copy an empty bitmap.

Fix the constructor and remove the expected test failure, from the
previous commit.
This commit is contained in:
John Beard 2019-05-23 16:52:07 +01:00
parent d642ac39ae
commit 2dd5757eb5
2 changed files with 13 additions and 7 deletions

View File

@ -59,8 +59,15 @@ BITMAP_BASE::BITMAP_BASE( const BITMAP_BASE& aSchBitmap )
m_scale = aSchBitmap.m_scale;
m_ppi = aSchBitmap.m_ppi;
m_pixelScaleFactor = aSchBitmap.m_pixelScaleFactor;
m_image = new wxImage( *aSchBitmap.m_image );
m_bitmap = new wxBitmap( *m_image );
m_image = nullptr;
m_bitmap = nullptr;
if( aSchBitmap.m_image )
{
m_image = new wxImage( *aSchBitmap.m_image );
m_bitmap = new wxBitmap( *m_image );
}
}

View File

@ -113,9 +113,10 @@ BOOST_AUTO_TEST_CASE( Empty )
}
#ifdef HAVE_EXPECTED_FAILURES
BOOST_AUTO_TEST_CASE( EmptyCopy, *boost::unit_test::expected_failures( 1 ) )
/**
* Check we can validly copy an empty bitmap
*/
BOOST_AUTO_TEST_CASE( EmptyCopy )
{
BITMAP_BASE empty;
BITMAP_BASE copied = empty;
@ -124,8 +125,6 @@ BOOST_AUTO_TEST_CASE( EmptyCopy, *boost::unit_test::expected_failures( 1 ) )
BOOST_CHECK_EQUAL( copied.GetImageData(), nullptr );
}
#endif
struct TEST_PIXEL_CASE
{