NxWidgets: Fix CListBox crash when clicked below the last item

This commit is contained in:
Petteri Aimonen 2016-09-22 11:17:37 -06:00 committed by Gregory Nutt
parent 8f305416ed
commit cb3dc4d544
2 changed files with 14 additions and 2 deletions

View File

@ -1,7 +1,7 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/clistdata.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -259,7 +259,14 @@ namespace NXWidgets
virtual inline const CListDataItem *getItem(const int index) const
{
return m_items[index];
if (index < 0 || index >= m_items.size())
{
return nullptr;
}
else
{
return m_items[index];
}
}
/**

View File

@ -607,6 +607,11 @@ void CListBox::onClick(nxgl_coord_t x, nxgl_coord_t y)
const CListBoxDataItem *item =
(const CListBoxDataItem*)m_options.getItem(m_lastSelectedIndex);
if (!item)
{
return; // No item at click position
}
// Are we selecting or de-selecting?
if (item->isSelected())