diff options
author | Zhang Yu <zhangyub@uniontech.com> | 2021-02-22 09:25:01 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-03-23 00:51:53 +0000 |
commit | 466177c9112de8b7a0bd0994767e8dfb8034d67f (patch) | |
tree | 7cb7741f3d86739576dd874576d6b4e5f1bedf25 /src | |
parent | fa444f9286f341cd318ea9a4ab60313127ea03ce (diff) |
Fix invalid pointer return with QGridLayout::itemAt(-1)
QGridLayout::takeAt() and QLayoutItem *itemAt() only check the upper bound.
If the index < 0, these function will return invalid pointer.
Fixes: QTBUG-91261
Change-Id: Idfb9fb6228b9707f817353b04974da16205a835c
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
(cherry picked from commit c47bb4478a4c3a29c0505d7d89755f40601b326f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/kernel/qgridlayout.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/widgets/kernel/qgridlayout.cpp b/src/widgets/kernel/qgridlayout.cpp index 121bae0352..336a68cd80 100644 --- a/src/widgets/kernel/qgridlayout.cpp +++ b/src/widgets/kernel/qgridlayout.cpp @@ -149,14 +149,14 @@ public: QRect cellRect(int row, int col) const; inline QLayoutItem *itemAt(int index) const { - if (index < things.count()) + if (index >= 0 && index < things.count()) return things.at(index)->item(); else return nullptr; } inline QLayoutItem *takeAt(int index) { Q_Q(QGridLayout); - if (index < things.count()) { + if (index >= 0 && index < things.count()) { if (QGridBox *b = things.takeAt(index)) { QLayoutItem *item = b->takeItem(); if (QLayout *l = item->layout()) { @@ -184,7 +184,7 @@ public: } void getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) const { - if (index < things.count()) { + if (index >= 0 && index < things.count()) { const QGridBox *b = things.at(index); int toRow = b->toRow(rr); int toCol = b->toCol(cc); |