summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2014-02-25 14:35:46 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-26 14:18:48 +0100
commitc453571d753160313a8dcb3f3aa4667c34616a8f (patch)
tree00ff7959f95a64dfdc24aad299b92dddbbdbcea0
parentb1a882f178d71d1462b5ee7e7ffde142928b5086 (diff)
CSS parser: fix the pseudo-classes array length
The pseudoclass array is declared with length "NumPseudos - 1", but the declaration has actually 44 elements, not 45. This caused a zero-initialized last element to be silently appended to the array. The zero-initialized element broke the sorting of the array, which in turn broke std::lower_bound usage (although of course the problem was there from before switching to the standard library algorithms). Task-number: QTBUG-36933 Change-Id: I8a02891fc36761b6ae72d15a0a8d6c6a96813947 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
-rw-r--r--src/gui/text/qcssparser_p.h2
-rw-r--r--tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp32
2 files changed, 33 insertions, 1 deletions
diff --git a/src/gui/text/qcssparser_p.h b/src/gui/text/qcssparser_p.h
index b087a2384a..123a53c5cc 100644
--- a/src/gui/text/qcssparser_p.h
+++ b/src/gui/text/qcssparser_p.h
@@ -508,7 +508,7 @@ const quint64 PseudoClass_EditFocus = Q_UINT64_C(0x0000080000000000);
const quint64 PseudoClass_Alternate = Q_UINT64_C(0x0000100000000000);
// The Any specifier is never generated, but can be used as a wildcard in searches.
const quint64 PseudoClass_Any = Q_UINT64_C(0x0000ffffffffffff);
-const int NumPseudos = 46;
+const int NumPseudos = 45;
struct Pseudo
{
diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
index 24e3ac2c99..5a36ffc671 100644
--- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
+++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
@@ -99,6 +99,7 @@ private slots:
void task232085_spinBoxLineEditBg();
void changeStyleInChangeEvent();
void QTBUG15910_crashNullWidget();
+ void QTBUG36933_brokenPseudoClassLookup();
//at the end because it mess with the style.
void widgetStyle();
@@ -1656,6 +1657,37 @@ void tst_QStyleSheetStyle::QTBUG15910_crashNullWidget()
QVERIFY(QTest::qWaitForWindowExposed(&w));
}
+void tst_QStyleSheetStyle::QTBUG36933_brokenPseudoClassLookup()
+{
+ const int rowCount = 10;
+ const int columnCount = 10;
+
+ QTableWidget widget(rowCount, columnCount);
+
+ for (int row = 0; row < rowCount; ++row) {
+ for (int column = 0; column < columnCount; ++column)
+ widget.setItem(row, column, new QTableWidgetItem(QStringLiteral("row %1 column %2").arg(row + 1).arg(column + 1)));
+
+ // put no visible text for the vertical headers, but still put some text or they will collapse
+ widget.setVerticalHeaderItem(row, new QTableWidgetItem(QStringLiteral(" ")));
+ }
+
+ // parsing of this stylesheet must not crash, and it must be correctly applied
+ widget.setStyleSheet(QStringLiteral("QHeaderView::section:vertical { background-color: #FF0000 }"));
+
+ widget.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
+
+ widget.activateWindow();
+ QApplication::setActiveWindow(&widget);
+ QVERIFY(QTest::qWaitForWindowActive(&widget));
+
+ QHeaderView *verticalHeader = widget.verticalHeader();
+ QImage image(verticalHeader->size(), QImage::Format_ARGB32);
+ verticalHeader->render(&image);
+ QVERIFY(testForColors(image, QColor(0xFF, 0x00, 0x00)));
+}
+
QTEST_MAIN(tst_QStyleSheetStyle)
#include "tst_qstylesheetstyle.moc"