Browse Source

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.
pull/15/head
John Beard 7 years ago
parent
commit
2dd5757eb5
  1. 11
      common/bitmap_base.cpp
  2. 9
      qa/common/test_bitmap_base.cpp

11
common/bitmap_base.cpp

@ -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 );
}
}

9
qa/common/test_bitmap_base.cpp

@ -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
{

Loading…
Cancel
Save