NxWidgets::CImage: Allow NULL bitmaps. From Petteri Aimonen

This commit is contained in:
Gregory Nutt 2013-06-04 07:54:26 -06:00
parent d69d3cd080
commit 1e7b43629a
2 changed files with 46 additions and 33 deletions

View File

@ -368,4 +368,7 @@
Pettit (2013-5-17).
* UnitTests/*/Makefile and .gitignore: Update the way that NSH
the Unit Tests are registered as built-in NSH applications (2013-5-30).
* NxWidgets::CImage: Allow a NULL pointer for a bitmap. Add protection
to prevent dereferencing the NULL pointer. From Petteri Aimonen
(2013-6-3).

View File

@ -138,6 +138,15 @@ CImage::CImage(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
void CImage::getPreferredDimensions(CRect &rect) const
{
if (!m_bitmap)
{
rect.setX(m_rect.getX());
rect.setY(m_rect.getY());
rect.setWidth(0);
rect.setHeight(0);
}
else
{
nxgl_coord_t width = m_bitmap->getWidth();
nxgl_coord_t height = m_bitmap->getHeight();
@ -151,6 +160,7 @@ void CImage::getPreferredDimensions(CRect &rect) const
rect.setY(m_rect.getY());
rect.setWidth(width);
rect.setHeight(height);
}
}
/**
@ -440,7 +450,7 @@ void CImage::onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y)
void CImage::setImageLeft(nxgl_coord_t column)
{
if (column > 0 && column <= m_bitmap->getWidth())
if (m_bitmap && column > 0 && column <= m_bitmap->getWidth())
{
m_origin.x = column;
}
@ -455,7 +465,7 @@ void CImage::setImageLeft(nxgl_coord_t column)
void CImage::setImageTop(nxgl_coord_t row)
{
if (row > 0 && row <= m_bitmap->getHeight())
if (m_bitmap && row > 0 && row <= m_bitmap->getHeight())
{
m_origin.x = row;
}