Qt: Fix out of bounds indices in InputModel

This commit is contained in:
Vicki Pfau 2017-07-12 19:22:34 -07:00
parent 1de4c8dc2e
commit bcb1617a69
1 changed files with 6 additions and 0 deletions

View File

@ -120,8 +120,14 @@ QVariant InputModel::headerData(int section, Qt::Orientation orientation, int ro
QModelIndex InputModel::index(int row, int column, const QModelIndex& parent) const { QModelIndex InputModel::index(int row, int column, const QModelIndex& parent) const {
if (parent.isValid()) { if (parent.isValid()) {
InputModelItem* p = static_cast<InputModelItem*>(parent.internalPointer()); InputModelItem* p = static_cast<InputModelItem*>(parent.internalPointer());
if (row >= m_tree[p->obj].count()) {
return QModelIndex();
}
return createIndex(row, column, const_cast<InputModelItem*>(&m_tree[p->obj][row])); return createIndex(row, column, const_cast<InputModelItem*>(&m_tree[p->obj][row]));
} }
if (row >= m_topLevelMenus.count()) {
return QModelIndex();
}
return createIndex(row, column, const_cast<InputModelItem*>(&m_topLevelMenus[row])); return createIndex(row, column, const_cast<InputModelItem*>(&m_topLevelMenus[row]));
} }