diff --git a/libnxwidgets/include/clistdata.hxx b/libnxwidgets/include/clistdata.hxx index da46a6acd..ad8ec3803 100644 --- a/libnxwidgets/include/clistdata.hxx +++ b/libnxwidgets/include/clistdata.hxx @@ -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 * * 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]; + } } /** diff --git a/libnxwidgets/src/clistbox.cxx b/libnxwidgets/src/clistbox.cxx index 1c5d1e507..bcf612343 100644 --- a/libnxwidgets/src/clistbox.cxx +++ b/libnxwidgets/src/clistbox.cxx @@ -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())