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 * 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> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -258,9 +258,16 @@ namespace NXWidgets
*/ */
virtual inline const CListDataItem *getItem(const int index) const virtual inline const CListDataItem *getItem(const int index) const
{
if (index < 0 || index >= m_items.size())
{
return nullptr;
}
else
{ {
return m_items[index]; return m_items[index];
} }
}
/** /**
* Sort the items using their compareTo() methods. * Sort the items using their compareTo() methods.

View File

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