summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorZhang Yu <zhangyub@uniontech.com>2021-02-22 09:25:01 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-22 15:22:11 +0000
commitd3b24a14bb9e6c258e9183dc05893020d81c9a9f (patch)
treeef81c4507ee268780c2fca899429c6c749d8c74c /tests/auto
parent90267af5df513e7b8301610c5fffcb03dfabf4ac (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 'tests/auto')
-rw-r--r--tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp b/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp
index 411ca7120e..72349cf90b 100644
--- a/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp
+++ b/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp
@@ -75,6 +75,7 @@ private slots:
void taskQTBUG_40609_addingWidgetToItsOwnLayout();
void taskQTBUG_40609_addingLayoutToItself();
void taskQTBUG_52357_spacingWhenItemIsHidden();
+ void taskQTBUG_91261_itemIndexRange();
void replaceWidget();
void dontCrashWhenExtendsToEnd();
};
@@ -1666,6 +1667,56 @@ void tst_QGridLayout::taskQTBUG_52357_spacingWhenItemIsHidden()
QTRY_COMPARE_WITH_TIMEOUT(tempWidth, button1.width() + button3.width() + layout.spacing(), 1000);
}
+void tst_QGridLayout::taskQTBUG_91261_itemIndexRange()
+{
+ QWidget widget;
+ QGridLayout lay(&widget);
+ QPushButton *btn = new QPushButton(&widget);
+ lay.addWidget(btn, 0, 0);
+
+ {
+ auto ptr = lay.itemAt(-1);
+ QCOMPARE(ptr, nullptr);
+
+ ptr = lay.itemAt(0);
+ QCOMPARE(ptr->widget(), btn);
+
+ ptr = lay.itemAt(1);
+ QCOMPARE(ptr, nullptr);
+ }
+
+ {
+ int row = -1;
+ int column = -1;
+ int rowSpan;
+ int columnSpan;
+
+ lay.getItemPosition(-1, &row, &column, &rowSpan, &columnSpan);
+ QCOMPARE(row, -1);
+ QCOMPARE(column, -1);
+
+ lay.getItemPosition(1, &row, &column, &rowSpan, &columnSpan);
+ QCOMPARE(row, -1);
+ QCOMPARE(column, -1);
+
+ lay.getItemPosition(0, &row, &column, &rowSpan, &columnSpan);
+ QCOMPARE(row, 0);
+ QCOMPARE(column, 0);
+ }
+
+ {
+ auto ptr = lay.takeAt(-1);
+ QCOMPARE(ptr, nullptr);
+
+ ptr = lay.takeAt(1);
+ QCOMPARE(ptr, nullptr);
+
+ ptr = lay.takeAt(0);
+ QCOMPARE(ptr->widget(), btn);
+ delete ptr;
+ }
+}
+
void tst_QGridLayout::replaceWidget()
{
QWidget wdg;