NxWidgets: Fix CListBox crash when clicked below the last item
This commit is contained in:
parent
8f305416ed
commit
cb3dc4d544
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user