From b84e033f2e77d108da413c00ee3d9f1636e8ad5b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 12 Apr 2012 16:55:36 +0200 Subject: Fix out of bounds use of QVector API. This is a regression introduced by commit d63910575949106f84dacf04abaa14fc866aa66b. Task-number: QTBUG-24965 Task-number: QTBUG-25140 Change-Id: Ice9d90ebb81dcc3c0bc166eeb8f77a0ad9d99476 Reviewed-by: David Faure --- src/gui/itemviews/qtreeview.cpp | 11 ++++++----- src/gui/itemviews/qtreeview_p.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/gui/itemviews') diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 813787fb8d..4006601cef 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -1390,7 +1390,10 @@ void QTreeViewPrivate::adjustViewOptionsForIndex(QStyleOptionViewItemV4 *option, QVector logicalIndices; // index = visual index of visible columns only. data = logical index. QVector viewItemPosList; // vector of left/middle/end for each logicalIndex, visible columns only. - calcLogicalIndices(&logicalIndices, &viewItemPosList); + const bool spanning = viewItems.at(row).spanning; + const int left = (spanning ? header->visualIndex(0) : 0); + const int right = (spanning ? header->visualIndex(0) : header->count() - 1 ); + calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right); int columnIndex = 0; for (int visualIndex = 0; visualIndex < current.column(); ++visualIndex) { @@ -1488,10 +1491,8 @@ static inline bool ancestorOf(QObject *widget, QObject *other) return false; } -void QTreeViewPrivate::calcLogicalIndices(QVector *logicalIndices, QVector *itemPositions) const +void QTreeViewPrivate::calcLogicalIndices(QVector *logicalIndices, QVector *itemPositions, int left, int right) const { - const int left = (spanning ? header->visualIndex(0) : leftAndRight.first); - const int right = (spanning ? header->visualIndex(0) : leftAndRight.second); const int columnCount = header->count(); /* 'left' and 'right' are the left-most and right-most visible visual indices. Compute the first visible logical indices before and after the left and right. @@ -1615,7 +1616,7 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, QVector logicalIndices; QVector viewItemPosList; // vector of left/middle/end for each logicalIndex - d->calcLogicalIndices(&logicalIndices, &viewItemPosList); + d->calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right); for (int currentLogicalSection = 0; currentLogicalSection < logicalIndices.count(); ++currentLogicalSection) { int headerSection = logicalIndices.at(currentLogicalSection); diff --git a/src/gui/itemviews/qtreeview_p.h b/src/gui/itemviews/qtreeview_p.h index 1124b6c7c4..a9b3fc9eaa 100644 --- a/src/gui/itemviews/qtreeview_p.h +++ b/src/gui/itemviews/qtreeview_p.h @@ -170,7 +170,7 @@ public: // logicalIndices: vector of currently visibly logical indices // itemPositions: vector of view item positions (beginning/middle/end/onlyone) - void calcLogicalIndices(QVector *logicalIndices, QVector *itemPositions) const; + void calcLogicalIndices(QVector *logicalIndices, QVector *itemPositions, int left, int right) const; QHeaderView *header; int indent; -- cgit v1.2.3