From 106ca7fb5dd27266c8d31bcc6ad47caf6de723be Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 27 Jan 2022 09:47:59 +0100 Subject: [PATCH] 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 Reviewed-by: David Faure (cherry picked from commit 33ad8b6fa9afbe4b8612f26c0bad42d23d94e7b2) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/itemviews/qabstractitemview.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index b2d19937423..7770096d248 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -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;