QAbstractItemView: do not access invalid model indices (1/N)

Calling selectAll() on a view with an empty model, with the view
in ContiguousSelection, causes an out of bounds access into the model.
Guard the access.

Change-Id: I3830a979bad760e9e1526c1c8b12d9767d41fc99
Pick-to: 5.15 6.2 6.3
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Giuseppe D'Angelo 2022-01-27 09:47:59 +01:00
parent 22ac61e62a
commit 33ad8b6fa9

View File

@ -1213,7 +1213,8 @@ void QAbstractItemView::selectAll()
break;
case NoSelection:
case ContiguousSelection:
d->selectAll(selectionCommand(d->model->index(0, 0, d->root)));
if (d->model->hasChildren(d->root))
d->selectAll(selectionCommand(d->model->index(0, 0, d->root)));
break;
case SingleSelection:
break;