From 77e1cc4b39fb030a5c299a2d068ff24ce232f5f6 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 22 Dec 2020 14:16:59 +0100 Subject: QHeaderView: pass sectionSize to createSectionItems() .. instead complete size for the affected range. The complete size was calculated before for every call of createSectionItems() and then the function calculated the size per section back for no reason. Passing the sum of all sections is therefore not needed and may lead to an integer overflow for big datasets. Task-number: QTBUG-88728 Change-Id: I8af0b0c3e97021ff0637fe1ee3ca3adfa23a2d0e Reviewed-by: David Faure --- src/widgets/itemviews/qheaderview.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/widgets/itemviews/qheaderview.cpp') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index e815ff53fa..cf74db49fb 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2362,7 +2362,7 @@ void QHeaderView::initializeSections(int start, int end) d->contentsSections = newSectionCount; if (newSectionCount > oldCount) - d->createSectionItems(start, end, (end - start + 1) * d->defaultSectionSize, d->globalResizeMode); + d->createSectionItems(start, end, d->defaultSectionSize, d->globalResizeMode); //Q_ASSERT(d->headerLength() == d->length); if (d->sectionCount() != oldCount) @@ -3681,8 +3681,7 @@ void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool //Q_ASSERT(newSectionLength > 0); if ((previousSectionResizeMode != newSectionResizeMode || previousSectionLength != newSectionLength) && i > 0) { - int spanLength = (i - spanStartSection) * previousSectionLength; - createSectionItems(spanStartSection, i - 1, spanLength, previousSectionResizeMode); + createSectionItems(spanStartSection, i - 1, previousSectionLength, previousSectionResizeMode); //Q_ASSERT(headerLength() == length); spanStartSection = i; } @@ -3695,16 +3694,14 @@ void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool } createSectionItems(spanStartSection, sectionCount() - 1, - (sectionCount() - spanStartSection) * previousSectionLength, - previousSectionResizeMode); + previousSectionLength, previousSectionResizeMode); //Q_ASSERT(headerLength() == length); resizeRecursionBlock = false; viewport->update(); } -void QHeaderViewPrivate::createSectionItems(int start, int end, int size, QHeaderView::ResizeMode mode) +void QHeaderViewPrivate::createSectionItems(int start, int end, int sizePerSection, QHeaderView::ResizeMode mode) { - int sizePerSection = size / (end - start + 1); if (end >= sectionItems.count()) { sectionItems.resize(end + 1); sectionStartposRecalc = true; -- cgit v1.2.3