From ddc886d670694df9e400ea6f04f76df19d0e1145 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 18 May 2021 16:08:36 +0200 Subject: QListView: add assert for static analyzer The loop that initializes the item should execute at least once, so the pointer should be pointing to something valid. The static analyzer doesn't see that, and warns about unguarded access to the item pointer in report with hash d008dbef4573afca54be0139e2971a4a. Add asserts for both the condition that makes the loop run at least once, and for the item pointer not being nullptr. Pick-to: 6.1 Change-Id: I94b9f3db3b3ce3d82445cf66788c05854b441aaf Reviewed-by: Giuseppe D'Angelo --- src/widgets/itemviews/qlistview.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/widgets/itemviews') diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 04da694b72..b7eca2d10a 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -3170,6 +3170,7 @@ void QIconModeViewBase::doDynamicLayout(const QListViewLayoutInfo &info) QRect rect(QPoint(), topLeft); QListViewItem *item = nullptr; + Q_ASSERT(info.first <= info.last); for (int row = info.first; row <= info.last; ++row) { item = &items[row]; if (isHidden(row)) { @@ -3240,6 +3241,7 @@ void QIconModeViewBase::doDynamicLayout(const QListViewLayoutInfo &info) flowPosition += deltaFlowPosition; // current position + item width + gap } } + Q_ASSERT(item); batchSavedDeltaSeg = deltaSegPosition; batchStartRow = info.last + 1; bool done = (info.last >= rowCount() - 1); -- cgit v1.2.3