From 456ae0dfeb7f537266995c66b180cddf0c587743 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 21 Sep 2016 19:06:53 -0700 Subject: QNetworkInterface: fix reporting of virtual interfaces on Linux We checked if we had seen the interface by looking into seenInterfaces and seenIndexes, but we never updated those variables with what we saw in this block. This fixes the reporting of PPP interfaces as well as TUN/TAP virtual interfaces. Change-Id: I33dc971f005a4848bb8ffffd1476830b8482b808 Reviewed-by: Edward Welbourne --- src/network/kernel/qnetworkinterface_unix.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/network/kernel/qnetworkinterface_unix.cpp b/src/network/kernel/qnetworkinterface_unix.cpp index eb73a2fb18..8ae36b56c2 100644 --- a/src/network/kernel/qnetworkinterface_unix.cpp +++ b/src/network/kernel/qnetworkinterface_unix.cpp @@ -352,6 +352,9 @@ static QList createInterfaces(ifaddrs *rawList) if (seenIndexes.contains(ifindex)) continue; + seenInterfaces.insert(name); + seenIndexes.append(ifindex); + QNetworkInterfacePrivate *iface = new QNetworkInterfacePrivate; interfaces << iface; iface->name = name; -- cgit v1.2.3 From 6a7b6c376be27390f359f0638f61147478323dae Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 23 Sep 2016 15:35:46 +0200 Subject: QApplication: Fix UB (invalid cast) in notify() Found by UBSan, which was so shocked that it crashed: #6 #7 __dynamic_cast () at ../../../../gcc/libstdc++-v3/libsupc++/dyncast.cc:50 #8 0x00002b9278fa1c3b in __ubsan::checkDynamicType(void*, void*, unsigned long) () from /opt/gcc/trunk/lib64/libubsan.so.0 #9 0x00002b9278fa10c3 in HandleDynamicTypeCacheMiss(__ubsan::DynamicTypeCacheMissData*, unsigned long, unsigned long, __ubsan::ReportOptions) () from /opt/gcc/trunk/lib64/libubsan.so.0 #10 0x00002b9278fa1783 in __ubsan_handle_dynamic_type_cache_miss () from /opt/gcc/trunk/lib64/libubsan.so.0 #11 0x00002b926c08ab8d in QApplication::notify(QObject*, QEvent*) () at /home/marc/Qt/qt5/qtbase/src/widgets/kernel/qapplication.cpp:3120 (full backtrace originates in tst_QWidget::testDeletionInEventHandlers(), testing key events). Fix is simple: just perform the cast before delivering the event. Change-Id: Ic26e36f47ef57e980c0dba00900927ff39fe6392 Reviewed-by: Thiago Macieira --- src/widgets/kernel/qapplication.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 917273e8cf..b64d6e2159 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3178,11 +3178,11 @@ bool QApplication::notify(QObject *receiver, QEvent *e) key->accept(); else key->ignore(); - res = d->notify_helper(receiver, e); QWidget *w = isWidget ? static_cast(receiver) : 0; #ifndef QT_NO_GRAPHICSVIEW QGraphicsWidget *gw = isGraphicsWidget ? static_cast(receiver) : 0; #endif + res = d->notify_helper(receiver, e); if ((res && key->isAccepted()) /* -- cgit v1.2.3 From 82eb7d1537d4c1265575c62b4678d668d77a4d96 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Sep 2016 15:21:00 +0200 Subject: Q(Color|File)Dialog: Fix several UBs (invalid cast/member call) in Private::canBeNativeDialog() Found by UBSan: qcolordialog.cpp:86:5: runtime error: downcast of address 0x7ffdf50c1ec0 which does not point to an object of type 'QColorDialog' 0x7ffdf50c1ec0: note: object is of type 'QDialog' fd 7f 00 00 d8 6e c7 23 b7 2a 00 00 50 c1 af 01 00 00 00 00 b0 70 c7 23 b7 2a 00 00 00 00 1a 1e ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QDialog' #0 0x2ab720e4ec97 in QColorDialogPrivate::q_func() const qcolordialog.cpp:86 #1 0x2ab720e4ec97 in QColorDialogPrivate::canBeNativeDialog() const qcolordialog.cpp:1865 #2 0x2ab720e84ed6 in QDialog::setVisible(bool) qdialog.cpp:696 #3 0x2ab720e6c1fa in QDialog::~QDialog() qdialog.cpp:357 #4 0x2ab720e2b276 in QColorDialog::~QColorDialog() qcolordialog.cpp:2187 #5 0x2ab720e5e2c6 in QColorDialog::getColor(QColor const&, QWidget*, QString const&, QFlags) qcolordialog.cpp:2148 #6 0x2ab720e5e473 in QColorDialog::getRgba(unsigned int, bool*, QWidget*) qcolordialog.cpp:2176 #7 0x407180 in tst_QColorDialog::testGetRgba() tst_qcolordialog.cpp:118 qfiledialog_p.h:112:5: runtime error: downcast of address 0x7ffd6858cc60 which does not point to an object of type 'QFileDialog' 0x7ffd6858cc60: note: object is of type 'QDialog' a1 2b 00 00 d8 1e 5e 0c a1 2b 00 00 b0 af 01 20 a1 2b 00 00 b0 20 5e 0c a1 2b 00 00 00 00 46 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QDialog' #0 0x2ba10980a9e7 in QFileDialogPrivate::q_func() const qfiledialog_p.h:112 #1 0x2ba10980a9e7 in QFileDialogPrivate::canBeNativeDialog() const qfiledialog.cpp:695 #2 0x2ba1097efe36 in QDialog::setVisible(bool) qdialog.cpp:696 #3 0x2ba1097d715a in QDialog::~QDialog() qdialog.cpp:357 #4 0x2ba109854c4b in QFileDialog::~QFileDialog() qfiledialog.cpp:380 #5 0x4179dc in tst_QFiledialog::init() tst_qfiledialog.cpp:175 Fix by replacing Q_Q with the the equivalent expression for QDialog. We can't re-use QDialogPrivate::q_func() here, since that is private, and probably should stay like that. Also fix an invalid member call in QColorDialogPrivate::canBeNativeDialog(): qcolordialog.cpp:2050:5: runtime error: member call on address 0x7ffdf50c1ec0 which does not point to an object of type 'QColorDialog' 0x7ffdf50c1ec0: note: object is of type 'QDialog' fd 7f 00 00 d8 6e c7 23 b7 2a 00 00 50 c1 af 01 00 00 00 00 b0 70 c7 23 b7 2a 00 00 00 00 1a 1e ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QDialog' #0 0x2ab720e4e5ea in QColorDialog::options() const qcolordialog.cpp:2050 #1 0x2ab720e4e8c8 in QColorDialogPrivate::canBeNativeDialog() const qcolordialog.cpp:1870 #2 0x2ab720e84ed6 in QDialog::setVisible(bool) qdialog.cpp:696 #3 0x2ab720e6c1fa in QDialog::~QDialog() qdialog.cpp:357 #4 0x2ab720e2b276 in QColorDialog::~QColorDialog() qcolordialog.cpp:2187 #5 0x2ab720e5e2c6 in QColorDialog::getColor(QColor const&, QWidget*, QString const&, QFlags) qcolordialog.cpp:2148 #6 0x2ab720e5e473 in QColorDialog::getRgba(unsigned int, bool*, QWidget*) qcolordialog.cpp:2176 #7 0x407180 in tst_QColorDialog::testGetRgba() tst_qcolordialog.cpp:118 by accessing the data member directly instead of through the Public API. Fix the same code in QFileDialog, even though the autotest coverage is too limited for UBSan to point that one out explicitly. This commit amends abe8b4ab9b5243b477c72f3e900d4f6cca79b5c5, in which it should have been included in the first place... Change-Id: Iff0538eba61d2381359f0b61f35918d643f7aa0c Reviewed-by: Thiago Macieira --- src/widgets/dialogs/qcolordialog.cpp | 6 ++++-- src/widgets/dialogs/qfiledialog.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index c4cc21cbe5..8e699e87c5 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -1862,12 +1862,14 @@ void QColorDialogPrivate::retranslateStrings() bool QColorDialogPrivate::canBeNativeDialog() const { - Q_Q(const QColorDialog); + // Don't use Q_Q here! This function is called from ~QDialog, + // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()). + const QDialog * const q = static_cast(q_ptr); if (nativeDialogInUse) return true; if (q->testAttribute(Qt::WA_DontShowOnScreen)) return false; - if (q->options() & QColorDialog::DontUseNativeDialog) + if (options->options() & QColorDialog::DontUseNativeDialog) return false; QLatin1String staticName(QColorDialog::staticMetaObject.className()); diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index bc2de899f5..3aa9052917 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -695,12 +695,14 @@ void QFileDialogPrivate::emitFilesSelected(const QStringList &files) bool QFileDialogPrivate::canBeNativeDialog() const { - Q_Q(const QFileDialog); + // Don't use Q_Q here! This function is called from ~QDialog, + // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()). + const QDialog * const q = static_cast(q_ptr); if (nativeDialogInUse) return true; if (q->testAttribute(Qt::WA_DontShowOnScreen)) return false; - if (q->options() & QFileDialog::DontUseNativeDialog) + if (options->options() & QFileDialog::DontUseNativeDialog) return false; QLatin1String staticName(QFileDialog::staticMetaObject.className()); -- cgit v1.2.3 From 8e45fe6d6c2084752983d905cf22f777e7062baf Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Sep 2016 09:12:24 +0200 Subject: QGraphicsScene: don't search for nullptr Following f6cb8b1af8f15a06898c5c71f81c64779d9478f6, take advantage of the nullptr return case of QGraphicsItem ::toGraphicsObject() by not looking up nullptr in the QList and the two QHashes. They don't contain nullptrs. Change-Id: Ic1cfbb4c60061577a09348ef78fdc573f95ad9a8 Reviewed-by: Friedemann Kleint --- src/widgets/graphicsview/qgraphicsscene.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index ebc521eb00..5e3b426d49 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -710,10 +710,11 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item) ++it; } - QGraphicsObject *dummy = item->toGraphicsObject(); - cachedTargetItems.removeOne(dummy); - cachedItemGestures.remove(dummy); - cachedAlreadyDeliveredGestures.remove(dummy); + if (QGraphicsObject *dummy = item->toGraphicsObject()) { + cachedTargetItems.removeOne(dummy); + cachedItemGestures.remove(dummy); + cachedAlreadyDeliveredGestures.remove(dummy); + } foreach (Qt::GestureType gesture, item->d_ptr->gestureContext.keys()) ungrabGesture(item, gesture); -- cgit v1.2.3 From b4ada3f0d8feed7dbff22aa780d38ab126020ac6 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 23 Sep 2016 13:18:03 +0200 Subject: add buildsystem changelog for 5.6.2 Change-Id: I39f5c4918107d894b8335b11c3b9c26b2b728421 Reviewed-by: Thiago Macieira --- dist/changes-5.6.2 | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/dist/changes-5.6.2 b/dist/changes-5.6.2 index 7b62a018f3..af02f2a6b9 100644 --- a/dist/changes-5.6.2 +++ b/dist/changes-5.6.2 @@ -41,6 +41,11 @@ information about a particular change. * Library * ****************************************************************************** +General +------- + + - [QTBUG-45291] Qt headers are now gcc -Wzero-as-null-pointer-constant clean. + QtCore ------ @@ -335,5 +340,47 @@ Windows moc --- + - [QTBUG-53441] Fixed crash on file ending with a backslash followed by carriage return + +configure & build system +------------------------ + + - [QTBUG-35886][QTBUG-51417] Fixed Fontconfig vs. system FreeType + configuration. + - [QTBUG-43784][X11] Fixed detection of GLX with -qt-xcb. + - [QTBUG-52951] Fixed dynamic library support detection for platforms + without libdl. + - [QTBUG-53038] Fixed running of configure tests outside qtbase when + cross compiling on Windows (for example for Android). + - [QTBUG-53312] The flags supplied by the configure -D/-I/-L/-l options + are now applied after Qt's own flags. This helps in some cases when + the provided paths contain files which conflict with the Qt build. + - [QTBUG-55011][Unix] Fixed -no-pkg-config being ignored by some + configure tests, which led to build failures later on. + - Fixed configure tests outside qtbase when $MAKEFLAGS contains the + -i flag. + - [Android] Some unused plugins are not built anymore. + - [MinGW] Added support for -separate-debug-info. + - [Unix] Added configure -no-opengles3 option. + - [Unix] Fixed MySQL detection/use on RHEL 6.6. + +qmake +----- + + - [QTBUG-41830] Fixed nested custom functions inheriting their callers' + arguments. + - [QTBUG-53895][MSVC] Started using separate PDB files for compiling + and linking. + - [QTBUG-54036][Darwin] Fixed installation of debug symbols. + - [QTBUG-54550] Fixed access to freed memory in $$absolute_path(). + - [QTBUG-55183][nmake] _WINDLL is now automatically defined when building + a DLL, consistently with Visual Studio. + - [QTBUG-55649][QTBUG-55915][Xcode] Fixed support for Xcode 8. + - Fixed several cases where the error() function would not abort qmake. + - Interrupting a command run via system() will now abort qmake as well. + - The packagesExist() function will now warn when used when Qt was + configured with -no-pkg-config. + - [Android] The default compiler flags were adjusted to match newer + NDK versions. -- cgit v1.2.3 From 6ea626a32fe070847629b6715c2a253717ff7412 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 22 Sep 2016 23:04:37 +0200 Subject: QObject test: check that throwing from a child's constructor works A check "just in case" -- we don't want leaks nor crashes due to double deletions, and so on. Change-Id: I24f1a486f0d438595bbe352ab780b07c5d53acbd Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 76 +++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 46889225eb..4417aa2353 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -6333,6 +6333,29 @@ signals: CountedStruct mySignal(const CountedStruct &s1, CountedStruct s2); }; +class CountedExceptionThrower : public QObject +{ + Q_OBJECT + +public: + explicit CountedExceptionThrower(bool throwException, QObject *parent = Q_NULLPTR) + : QObject(parent) + { + if (throwException) + throw ObjectException(); + ++counter; + } + + ~CountedExceptionThrower() + { + --counter; + } + + static int counter; +}; + +int CountedExceptionThrower::counter = 0; + void tst_QObject::exceptions() { #ifndef QT_NO_EXCEPTIONS @@ -6394,6 +6417,59 @@ void tst_QObject::exceptions() } QCOMPARE(countedStructObjectsCount, 0); + // Child object reaping in case of exceptions thrown by constructors + { + QCOMPARE(CountedExceptionThrower::counter, 0); + + try { + class ParentObject : public QObject { + public: + explicit ParentObject(QObject *parent = Q_NULLPTR) + : QObject(parent) + { + new CountedExceptionThrower(false, this); + new CountedExceptionThrower(false, this); + new CountedExceptionThrower(true, this); // throws + } + }; + + ParentObject p; + QFAIL("Exception not thrown"); + } catch (const ObjectException &) { + } catch (...) { + QFAIL("Wrong exception thrown"); + } + + QCOMPARE(CountedExceptionThrower::counter, 0); + + try { + QObject o; + new CountedExceptionThrower(false, &o); + new CountedExceptionThrower(false, &o); + new CountedExceptionThrower(true, &o); // throws + + QFAIL("Exception not thrown"); + } catch (const ObjectException &) { + } catch (...) { + QFAIL("Wrong exception thrown"); + } + + QCOMPARE(CountedExceptionThrower::counter, 0); + + try { + QObject o; + CountedExceptionThrower c1(false, &o); + CountedExceptionThrower c2(false, &o); + CountedExceptionThrower c3(true, &o); // throws + + QFAIL("Exception not thrown"); + } catch (const ObjectException &) { + } catch (...) { + QFAIL("Wrong exception thrown"); + } + + QCOMPARE(CountedExceptionThrower::counter, 0); + } #else QSKIP("Needs exceptions"); -- cgit v1.2.3 From b4995eb7491c1b4784a1bf48db834c11c42b8d9d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 26 Sep 2016 23:41:41 +0200 Subject: QStackedLayout: Fix UB (invalid cast) in qt_wasDeleted() Found by UBSan: qstackedlayout.cpp:261:98: runtime error: downcast of address 0x60400003cd10 which does not point to an object of type 'QtFriendlyLayoutWidget' 0x60400003cd10: note: object is of type 'QWidget' 0e 00 80 76 70 0b 06 3f d6 2a 00 00 00 99 00 00 50 61 00 00 20 0d 06 3f d6 2a 00 00 00 00 be be ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QWidget' #0 0x2ad637b8f58f in qt_wasDeleted qstackedlayout.cpp:261 #1 0x2ad637b8f58f in QStackedLayout::takeAt(int) qstackedlayout.cpp:285 #2 0x2ad637b4afcb in QLayout::removeWidget(QWidget*) qlayout.cpp:1369 #3 0x413534 in tst_QStackedLayout::testCase() tst_qstackedlayout.cpp:155 Caused by using a struct to get access to QWidgetPrivate::wasDeleted using a cast. That cast is invalid, of course, so simply use QWidgetPrivate::get(). Caveat: we need a const version of that function, but that didn't exist, yet, so added one. Change-Id: I27d449b90be7e2072646d950c676b500ef698349 Reviewed-by: Thiago Macieira --- src/widgets/kernel/qstackedlayout.cpp | 12 ++++-------- src/widgets/kernel/qwidget_p.h | 1 + 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/widgets/kernel/qstackedlayout.cpp b/src/widgets/kernel/qstackedlayout.cpp index 029c2bcec2..7afd6d076d 100644 --- a/src/widgets/kernel/qstackedlayout.cpp +++ b/src/widgets/kernel/qstackedlayout.cpp @@ -35,7 +35,7 @@ #include "qlayout_p.h" #include -#include +#include "private/qwidget_p.h" #include "private/qlayoutengine_p.h" QT_BEGIN_NAMESPACE @@ -245,14 +245,10 @@ QLayoutItem *QStackedLayout::itemAt(int index) const // Code that enables proper handling of the case that takeAt() is // called somewhere inside QObject destructor (can't call hide() // on the object then) - -class QtFriendlyLayoutWidget : public QWidget +static bool qt_wasDeleted(const QWidget *w) { -public: - inline bool wasDeleted() const { return d_ptr->wasDeleted; } -}; - -static bool qt_wasDeleted(const QWidget *w) { return static_cast(w)->wasDeleted(); } + return QWidgetPrivate::get(w)->wasDeleted; +} /*! diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 5f07a8802a..37f2c0e5c7 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -323,6 +323,7 @@ public: ~QWidgetPrivate(); static QWidgetPrivate *get(QWidget *w) { return w->d_func(); } + static const QWidgetPrivate *get(const QWidget *w) { return w->d_func(); } QWExtra *extraData() const; QTLWExtra *topData() const; -- cgit v1.2.3 From fcf4767bffd201a0b8da1ed6f5425e3f5ce0e4ff Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 26 Sep 2016 19:56:07 +0200 Subject: QLayout: Fix UB (invalid cast) in widgetEvent() Found by UBSan: qlayout.cpp:612:50: runtime error: downcast of address 0x7ffcd4c39a70 which does not point to an object of type 'QWidget' 0x7ffcd4c39a70: note: object is of type 'QObject' 00 00 00 00 b0 43 4c 7b f5 2a 00 00 70 c9 28 02 00 00 00 00 08 93 9a 77 f5 2a 00 00 00 00 c3 d4 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QObject' #0 0x2af56f189960 in QLayout::widgetEvent(QEvent*) qlayout.cpp:612 #1 0x2af56f037660 in QApplicationPrivate::notify_helper(QObject*, QEvent*) qapplication.cpp:3732 #2 0x2af56f06ae5b in QApplication::notify(QObject*, QEvent*) qapplication.cpp:3704 #3 0x2af57989e383 in QCoreApplication::notifyInternal2(QObject*, QEvent*) qcoreapplication.cpp:988 #4 0x2af5799c1696 in QCoreApplication::sendEvent(QObject*, QEvent*) qcoreapplication.h:231 #5 0x2af5799c1696 in QObjectPrivate::setParent_helper(QObject*) qobject.cpp:2043 #6 0x2af5799c4823 in QObject::~QObject() qobject.cpp:1095 #7 0x2af56f2d205d in QWidget::~QWidget() qwidget.cpp:1549 #8 0x2af56f9c1366 in QFrame::~QFrame() qframe.cpp:262 #9 0x2af56f9e76cb in QLabel::~QLabel() qlabel.cpp:247 #10 0x458077 in tst_QStyleSheetStyle::emptyStyleSheet() tst_qstylesheetstyle.cpp:1400 Fix by not casting at all (or, to be precise, casting implicitly up instead of explicitly down). Change-Id: Ic19fd29e0cabd1aee5b1c93ca4c0fc70bc7a5927 Reviewed-by: Thiago Macieira --- src/widgets/kernel/qlayout.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index 8631149f3d..7ca8de6f7a 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -540,7 +540,7 @@ void QLayout::invalidate() update(); } -static bool removeWidgetRecursively(QLayoutItem *li, QWidget *w) +static bool removeWidgetRecursively(QLayoutItem *li, QObject *w) { QLayout *lay = li->layout(); if (!lay) @@ -603,12 +603,11 @@ void QLayout::widgetEvent(QEvent *e) { QChildEvent *c = (QChildEvent *)e; if (c->child()->isWidgetType()) { - QWidget *w = (QWidget *)c->child(); #ifndef QT_NO_MENUBAR - if (w == d->menubar) + if (c->child() == d->menubar) d->menubar = 0; #endif - removeWidgetRecursively(this, w); + removeWidgetRecursively(this, c->child()); } } break; -- cgit v1.2.3 From 77eafa8d890bc80813159ad29ba3a4e1909866fd Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 26 Sep 2016 21:37:49 +0200 Subject: Plug memleaks in tst_QBoxLayout In sizeConstraints(), QLayout::takeAt(), as the name suggests, doesn't actually delete the item. We have to do that ourselves. Likewise, in replaceWidget(), QLayout::replaceWidget() also doesn't delete the affected item, but returns it. That's spectacularly bad API design, but the leak is easy to fix: just delete the return value. Change-Id: I8dcbc59898949eabce766cda2c0edae2e1f2799e Reviewed-by: Friedemann Kleint --- tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp index aeaf1e7bf0..ed5b763b0f 100644 --- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp +++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp @@ -188,7 +188,7 @@ void tst_QBoxLayout::sizeConstraints() window.show(); QTest::qWaitForWindowExposed(&window); QSize sh = window.sizeHint(); - lay->takeAt(1); + delete lay->takeAt(1); QVERIFY(sh.width() >= window.sizeHint().width() && sh.height() >= window.sizeHint().height()); @@ -517,7 +517,7 @@ void tst_QBoxLayout::replaceWidget() QCOMPARE(boxLayout->indexOf(replaceFrom), 1); QCOMPARE(boxLayout->indexOf(replaceTo), -1); - boxLayout->replaceWidget(replaceFrom, replaceTo); + delete boxLayout->replaceWidget(replaceFrom, replaceTo); QCOMPARE(boxLayout->indexOf(replaceFrom), -1); QCOMPARE(boxLayout->indexOf(replaceTo), 1); -- cgit v1.2.3 From b827b8ccf7311d8bc3551501a5faa6d456da052b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 26 Sep 2016 21:37:49 +0200 Subject: Plug memleaks in tst_QGridLayout In setMinAndMaxSize(), QLayout::removeItem() doesn't actually delete the removed item. We have to do that ourselves (RAII not necessary, since the spacer is owned by the layout until we remove it). In distributeMultiCell(), allocate the QStyle subclass on the stack so the compiler cleans it up properly on all exit paths (was: unconditional leak). Change-Id: I24f8f11af2bfc5abf78f9aab0139dcfe0187402b Reviewed-by: Friedemann Kleint --- tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp b/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp index 1e67c675ef..255481031b 100644 --- a/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp +++ b/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp @@ -353,6 +353,8 @@ void tst_QGridLayout::setMinAndMaxSize() layout.removeItem(spacer); + delete spacer; + spacer = Q_NULLPTR; rightChild.hide(); QApplication::sendPostedEvents(0, 0); @@ -1601,10 +1603,10 @@ void tst_QGridLayout::contentsRect() void tst_QGridLayout::distributeMultiCell() { QWidget w; - Qt42Style *style = new Qt42Style(); - style->spacing = 9; + Qt42Style style; + style.spacing = 9; - w.setStyle(style); + w.setStyle(&style); QGridLayout grid; w.setLayout(&grid); -- cgit v1.2.3 From 158781ff2555fabcb9af6b47c887519ade5aba50 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 6 Sep 2016 12:36:55 +0200 Subject: QSslSocket: respect read buffer's max size (SecureTransport) 1. QSslSocketBackendPrivate::transmit was ignoring 'readBufferMaxSize'; as a result, we can have a user trying to set read buffer's size to a small value (and more important - reading slowly in a small chunks from this socket), but SSL itself socket reading 'too fast', potentially growing its internal buffer to a huge size. This also results in auto-tests failing - whenever we're trying to limit read rate in some test. 2. Update qsslsocket auto-test. Task-number: QTBUG-43388 Task-number: QTBUG-55170 Change-Id: Iedece26df0ac5b3b7cad62cc8c98aedc28e7ca5b Reviewed-by: Richard J. Moore --- src/network/ssl/qsslsocket_mac.cpp | 2 +- .../auto/network/ssl/qsslsocket/tst_qsslsocket.cpp | 63 ++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/network/ssl/qsslsocket_mac.cpp b/src/network/ssl/qsslsocket_mac.cpp index 8aa9269f4b..233f7b5d15 100644 --- a/src/network/ssl/qsslsocket_mac.cpp +++ b/src/network/ssl/qsslsocket_mac.cpp @@ -668,7 +668,7 @@ void QSslSocketBackendPrivate::transmit() if (connectionEncrypted) { QVarLengthArray data; - while (context) { + while (context && (!readBufferMaxSize || buffer.size() < readBufferMaxSize)) { size_t readBytes = 0; data.resize(4096); const OSStatus err = SSLRead(context, data.data(), data.size(), &readBytes); diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index 2d35081dff..9b544e0db8 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -229,6 +229,7 @@ private slots: void ecdhServer(); void verifyClientCertificate_data(); void verifyClientCertificate(); + void readBufferMaxSize(); void setEmptyDefaultConfiguration(); // this test should be last #ifndef QT_NO_OPENSSL @@ -3043,6 +3044,68 @@ void tst_QSslSocket::verifyClientCertificate() QCOMPARE(client->isEncrypted(), works); } +void tst_QSslSocket::readBufferMaxSize() +{ +#ifdef QT_SECURETRANSPORT + // QTBUG-55170: + // SecureTransport back-end was ignoring read-buffer + // size limit, resulting (potentially) in a constantly + // growing internal buffer. + // The test's logic is: we set a small read buffer size on a client + // socket (to some ridiculously small value), server sends us + // a bunch of bytes , we ignore readReady signal so + // that socket's internal buffer size stays + // >= readBufferMaxSize, we wait for a quite long time + // (which previously would be enough to read completely) + // and we check socket's bytesAvaiable to be less than sent. + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) + return; + + SslServer server; + QVERIFY(server.listen()); + + QEventLoop loop; + + QSslSocketPtr client(new QSslSocket); + socket = client.data(); + connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), &loop, SLOT(quit())); + connect(socket, SIGNAL(sslErrors(QList)), this, SLOT(ignoreErrorSlot())); + connect(socket, SIGNAL(encrypted()), &loop, SLOT(quit())); + + client->connectToHostEncrypted(QHostAddress(QHostAddress::LocalHost).toString(), + server.serverPort()); + + // Wait for 'encrypted' first: + QTimer::singleShot(5000, &loop, SLOT(quit())); + loop.exec(); + + QCOMPARE(client->state(), QAbstractSocket::ConnectedState); + QCOMPARE(client->mode(), QSslSocket::SslClientMode); + + client->setReadBufferSize(10); + const QByteArray message(int(0xffff), 'a'); + server.socket->write(message); + + QTimer::singleShot(5000, &loop, SLOT(quit())); + loop.exec(); + + int readSoFar = client->bytesAvailable(); + QVERIFY(readSoFar > 0 && readSoFar < message.size()); + // Now, let's check that we still can read the rest of it: + QCOMPARE(client->readAll().size(), readSoFar); + + client->setReadBufferSize(0); + + QTimer::singleShot(1500, &loop, SLOT(quit())); + loop.exec(); + + QCOMPARE(client->bytesAvailable() + readSoFar, message.size()); +#else + // Not needed, QSslSocket works correctly with other back-ends. +#endif +} + void tst_QSslSocket::setEmptyDefaultConfiguration() // this test should be last, as it has some side effects { // used to produce a crash in QSslConfigurationPrivate::deepCopyDefaultConfiguration, QTBUG-13265 -- cgit v1.2.3 From a95d103bd2ed907b11c483c91e32139144828148 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 20 Sep 2016 16:12:35 +0200 Subject: Add GLSL version 110 on Intel with compat profiles The Windows Intel drivers reject shader sources without a version directive in 3.2+ compatibility profiles. This is odd but can be worked around by adding #version 110 (which should be the default...) Change-Id: I1ccac41b80121e6423d4f8964d03dda52a433296 Task-number: QTBUG-55733 Reviewed-by: Friedemann Kleint Reviewed-by: Giuseppe D'Angelo Reviewed-by: Andy Nichols --- src/gui/opengl/qopenglshaderprogram.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp index d567800fbd..824831ab29 100644 --- a/src/gui/opengl/qopenglshaderprogram.cpp +++ b/src/gui/opengl/qopenglshaderprogram.cpp @@ -516,16 +516,26 @@ bool QOpenGLShader::compileSourceCode(const char *source) QVarLengthArray sourceChunks; QVarLengthArray sourceChunkLengths; + QOpenGLContext *ctx = QOpenGLContext::currentContext(); if (versionDirectivePosition.hasPosition()) { - // Append source up to #version directive + // Append source up to and including the #version directive sourceChunks.append(source); sourceChunkLengths.append(GLint(versionDirectivePosition.position)); + } else { + // QTBUG-55733: Intel on Windows with Compatibility profile requires a #version always + if (ctx->format().profile() == QSurfaceFormat::CompatibilityProfile) { + const char *vendor = reinterpret_cast(ctx->functions()->glGetString(GL_VENDOR)); + if (vendor && !strcmp(vendor, "Intel")) { + static const char version110[] = "#version 110\n"; + sourceChunks.append(version110); + sourceChunkLengths.append(GLint(sizeof(version110)) - 1); + } + } } // The precision qualifiers are useful on OpenGL/ES systems, // but usually not present on desktop systems. - QOpenGLContext *ctx = QOpenGLContext::currentContext(); const QSurfaceFormat currentSurfaceFormat = ctx->format(); QOpenGLContextPrivate *ctx_d = QOpenGLContextPrivate::get(QOpenGLContext::currentContext()); if (currentSurfaceFormat.renderableType() == QSurfaceFormat::OpenGL -- cgit v1.2.3 From 3379ace11b30d8e9a2c9b45789561ac44bf29c06 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 4 Aug 2016 16:41:12 +0200 Subject: QDateTimeEdit: synchronize time-spec before initializing display QDateTimeEdit ignores the time-spec of its date-time value, using its own time-spec instead; mostly, this works because it first conforms the value to its own time-spec. However, during construction, before doing this, it set up its display data, which could leave it with a different time (rather than a different representation of the given time) than it was asked to use. Moved the updateTimeSpec() calls to immediately after setting value in QDateTimeEditPrivate::init() to ensure correct handling. Added test. Task-number: QTBUG-54781 Change-Id: I3b07c10997abb858fc0b40558bff96e3fdabbd83 Reviewed-by: Jesus Fernandez Reviewed-by: Marc Mutz --- src/widgets/widgets/qdatetimeedit.cpp | 4 +++- tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index 960f84c13a..96a37197e9 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -2388,18 +2388,21 @@ void QDateTimeEditPrivate::init(const QVariant &var) switch (var.type()) { case QVariant::Date: value = QDateTime(var.toDate(), QDATETIMEEDIT_TIME_MIN); + updateTimeSpec(); q->setDisplayFormat(defaultDateFormat); if (sectionNodes.isEmpty()) // ### safeguard for broken locale q->setDisplayFormat(QLatin1String("dd/MM/yyyy")); break; case QVariant::DateTime: value = var; + updateTimeSpec(); q->setDisplayFormat(defaultDateTimeFormat); if (sectionNodes.isEmpty()) // ### safeguard for broken locale q->setDisplayFormat(QLatin1String("dd/MM/yyyy hh:mm:ss")); break; case QVariant::Time: value = QDateTime(QDATETIMEEDIT_DATE_INITIAL, var.toTime()); + updateTimeSpec(); q->setDisplayFormat(defaultTimeFormat); if (sectionNodes.isEmpty()) // ### safeguard for broken locale q->setDisplayFormat(QLatin1String("hh:mm:ss")); @@ -2412,7 +2415,6 @@ void QDateTimeEditPrivate::init(const QVariant &var) if (QApplication::keypadNavigationEnabled()) q->setCalendarPopup(true); #endif - updateTimeSpec(); q->setInputMethodHints(Qt::ImhPreferNumbers); setLayoutItemMargins(QStyle::SE_DateTimeEditLayoutItem); } diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp index d41398046f..08a28f3ea0 100644 --- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp +++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp @@ -252,6 +252,7 @@ private slots: void timeSpec_data(); void timeSpec(); void timeSpecBug(); + void timeSpecInit(); void monthEdgeCase(); void setLocale(); @@ -3215,6 +3216,13 @@ void tst_QDateTimeEdit::timeSpecBug() QCOMPARE(oldText, testWidget->text()); } +void tst_QDateTimeEdit::timeSpecInit() +{ + QDateTime utc(QDate(2000, 1, 1), QTime(12, 0, 0), Qt::UTC); + QDateTimeEdit widget(utc); + QCOMPARE(widget.dateTime(), utc); +} + void tst_QDateTimeEdit::cachedDayTest() { testWidget->setDisplayFormat("MM/dd"); -- cgit v1.2.3 From 99242a2dec07d2b299092354870cae391c80ce95 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 26 Sep 2016 14:22:28 +0200 Subject: syncqt.pl: also allow digits in upper-case macro names The check for Q_... macros used a regex that didn't allow digits; it thus failed to match Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(). Change-Id: I3f9339349aa21e2fea04a7f53d9d8e0903e4c65b Reviewed-by: Marc Mutz Reviewed-by: Oswald Buddenhagen --- bin/syncqt.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/syncqt.pl b/bin/syncqt.pl index 93c962cf90..9dcc7fe4fd 100755 --- a/bin/syncqt.pl +++ b/bin/syncqt.pl @@ -224,7 +224,7 @@ sub classNames { } if($line) { $line =~ s,//.*$,,; #remove c++ comments - $line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro + $line .= ";" if($line =~ m/^Q_[A-Z_0-9]*\(.*\)[\r\n]*$/); #qt macro $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE(_[A-Z]+)*[\r\n]*$/); #qt macro $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro -- cgit v1.2.3 From bf76405afc196f0db9d0aeef3307678d74ed1c30 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 19 Sep 2016 10:41:57 +0200 Subject: Extend tested formats in lancelot Adds two formats that does not have optimized code-paths in qdrawhelper to ensure the generic path has coverage. This has already uncovered one bug fixed before this patch could go in. Change-Id: I0e0a1a873555b27f6438f69a76982b8e06263dcf Reviewed-by: Marc Mutz --- tests/auto/other/lancelot/tst_lancelot.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/auto/other/lancelot/tst_lancelot.cpp b/tests/auto/other/lancelot/tst_lancelot.cpp index 3022114403..7fa53bbb46 100644 --- a/tests/auto/other/lancelot/tst_lancelot.cpp +++ b/tests/auto/other/lancelot/tst_lancelot.cpp @@ -76,6 +76,10 @@ private slots: void testRasterRGB32(); void testRasterRGB16_data(); void testRasterRGB16(); + void testRasterARGB8565PM_data(); + void testRasterARGB8565PM(); + void testRasterGrayscale8_data(); + void testRasterGrayscale8(); #ifndef QT_NO_OPENGL void testOpenGL_data(); @@ -155,6 +159,28 @@ void tst_Lancelot::testRasterRGB16() } +void tst_Lancelot::testRasterARGB8565PM_data() +{ + setupTestSuite(); +} + +void tst_Lancelot::testRasterARGB8565PM() +{ + runTestSuite(Raster, QImage::Format_ARGB8565_Premultiplied); +} + + +void tst_Lancelot::testRasterGrayscale8_data() +{ + setupTestSuite(); +} + +void tst_Lancelot::testRasterGrayscale8() +{ + runTestSuite(Raster, QImage::Format_Grayscale8); +} + + #ifndef QT_NO_OPENGL bool tst_Lancelot::checkSystemGLSupport() { -- cgit v1.2.3 From b9e42067268bc80d126e82c4d892ffe33bb4c17a Mon Sep 17 00:00:00 2001 From: Palo Kisa Date: Mon, 26 Sep 2016 22:16:55 +0200 Subject: QGraphicsAnchorLayout: Fix invalid use of Q_AUTOTEST_EXPORT The Q_AUTOTEST_EXPORT is defined in all cases. So usage as #if defined(Q_AUTOTEST_EXPORT) was wrong. Change-Id: Ia1c1526ad08fdfa35ca773d7c62f8bbba39a6d38 Reviewed-by: Marc Mutz Reviewed-by: Oswald Buddenhagen --- src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp | 4 ++-- src/widgets/graphicsview/qgraphicsanchorlayout_p.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp index dac8e61645..8c27af1da5 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp @@ -2090,7 +2090,7 @@ QList getVariables(const QList &constraints) void QGraphicsAnchorLayoutPrivate::calculateGraphs( QGraphicsAnchorLayoutPrivate::Orientation orientation) { -#if defined(QT_DEBUG) || defined(Q_AUTOTEST_EXPORT) +#if defined(QT_DEBUG) || defined(QT_BUILD_INTERNAL) lastCalculationUsedSimplex[orientation] = false; #endif @@ -2254,7 +2254,7 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const sizeHints[orientation][Qt::MaximumSize] = ad->sizeAtMaximum; } -#if defined(QT_DEBUG) || defined(Q_AUTOTEST_EXPORT) +#if defined(QT_DEBUG) || defined(QT_BUILD_INTERNAL) lastCalculationUsedSimplex[orientation] = needsSimplex; #endif diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.h b/src/widgets/graphicsview/qgraphicsanchorlayout_p.h index a5c7f1e2ce..4f8a106811 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.h @@ -568,7 +568,7 @@ public: bool graphHasConflicts[2]; QSet m_floatItems[2]; -#if defined(QT_DEBUG) || defined(Q_AUTOTEST_EXPORT) +#if defined(QT_DEBUG) || defined(QT_BUILD_INTERNAL) bool lastCalculationUsedSimplex[2]; #endif -- cgit v1.2.3 From 5571d2bf62a69f2422a849a8d0cd2c40c35b8d47 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 27 Sep 2016 13:59:37 +0200 Subject: tst_QApplication: Fix UBs (invalid cast) in focusMouseClick() Found by UBSan: tst_qapplication.cpp:1754:48: runtime error: member access within address 0x7ffda11f2220 which does not point to an object of type 'SpontaneousEvent' 0x7ffda11f2220: note: object is of type 'QMouseEvent' The code attempted to model the layout of a QEvent with another class that allows public access to the memory location that (hopefully) corresponds to QEvent::spont, gaining access by casting a QEvent object to that specifically-crafted class. Fix by the using the existing QSpontaneKeyEvent::setSpontaneous() call, which, despite its name, works for all QEvent subclasses, and which has already been fixed to not invoke UB (in bc087db). Change-Id: I7db8b8a8a823f7d61ab17375142d19dc3874fea5 Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../kernel/qapplication/tst_qapplication.cpp | 25 +++------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 878136b4a0..87a189fc87 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -1769,25 +1769,6 @@ void tst_QApplication::focusOut() QTest::qWait(2000); } -class SpontaneousEvent -{ - Q_GADGET - QDOC_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) - Q_ENUMS(Type) -public: - enum Type { - Void - }; - - virtual ~SpontaneousEvent() {} - - QEventPrivate *d; - ushort t; - - ushort posted : 1; - ushort spont : 1; -}; - void tst_QApplication::focusMouseClick() { int argc = 1; @@ -1805,14 +1786,14 @@ void tst_QApplication::focusMouseClick() // now send a mouse button press event and check what happens with the focus // it should be given to the parent widget QMouseEvent ev(QEvent::MouseButtonPress, QPointF(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); - reinterpret_cast(&ev)->spont = 1; + QSpontaneKeyEvent::setSpontaneous(&ev); QVERIFY(ev.spontaneous()); qApp->notify(&w2, &ev); QCOMPARE(QApplication::focusWidget(), &w); // then we give the inner widget strong focus -> it should get focus w2.setFocusPolicy(Qt::StrongFocus); - reinterpret_cast(&ev)->spont = 1; + QSpontaneKeyEvent::setSpontaneous(&ev); QVERIFY(ev.spontaneous()); qApp->notify(&w2, &ev); QTRY_COMPARE(QApplication::focusWidget(), &w2); @@ -1820,7 +1801,7 @@ void tst_QApplication::focusMouseClick() // now back to tab focus and click again (it already had focus) -> focus should stay // (focus was revoked as of QTBUG-34042) w2.setFocusPolicy(Qt::TabFocus); - reinterpret_cast(&ev)->spont = 1; + QSpontaneKeyEvent::setSpontaneous(&ev); QVERIFY(ev.spontaneous()); qApp->notify(&w2, &ev); QCOMPARE(QApplication::focusWidget(), &w2); -- cgit v1.2.3 From c65621b36208556556ffaad473b53a3782ad5fd6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 27 Sep 2016 13:41:55 +0200 Subject: QWidget: Fix UB (invalid cast) in sendResizeEvents() Found by UBSan: qwidget.cpp:5228:62: runtime error: downcast of address 0x61b00003d480 which does not point to an object of type 'QWidget' 0x61b00003d480: note: object is of type 'QMainWindowLayout' bc 00 00 75 90 2e 2a 78 4f 2b 00 00 40 c1 02 00 f0 60 00 00 78 2f 2a 78 4f 2b 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QMainWindowLayout' #0 0x2b4f70efb1c2 in sendResizeEvents qwidget.cpp:5228 #1 0x2b4f70f65f7f in QWidget::grab(QRect const&) qwidget.cpp:5252 #2 0x6b1746 in tst_QWidget::render_task188133() tst_qwidget.cpp:6615 Fix by performing the cast only after the test for isWidgetType() has succeeded. Change-Id: I061a60ef35bcb5fbefb9bc7b84706c9dd5afd207 Reviewed-by: Thiago Macieira --- src/widgets/kernel/qwidget.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index b99fca6620..b2db4e1529 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -5201,8 +5201,10 @@ static void sendResizeEvents(QWidget *target) const QObjectList children = target->children(); for (int i = 0; i < children.size(); ++i) { + if (!children.at(i)->isWidgetType()) + continue; QWidget *child = static_cast(children.at(i)); - if (child->isWidgetType() && !child->isWindow() && child->testAttribute(Qt::WA_PendingResizeEvent)) + if (!child->isWindow() && child->testAttribute(Qt::WA_PendingResizeEvent)) sendResizeEvents(child); } } -- cgit v1.2.3 From 24314c73ae711fb9bd16626c41a09ddeee0a7001 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 27 Sep 2016 10:41:41 +0200 Subject: QTapAndHoldGestureRecognizer: Fix several UBs (invalid cast) in recognize() As found by UBSan: qstandardgestures.cpp:511:67: runtime error: downcast of address 0x7ffc9beb1b90 which does not point to an object of type 'QTouchEvent' 0x7ffc9beb1b90: note: object is of type 'QPlatformSurfaceEvent' fc 7f 00 00 08 93 b1 6f f5 2a 00 00 00 00 00 00 00 00 00 00 d9 00 ec 9b 00 00 00 00 49 01 c1 5e ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QPlatformSurfaceEvent' #0 0x2af55edfa66a in QTapAndHoldGestureRecognizer::recognize(QGesture*, QObject*, QEvent*) qstandardgestures.cpp:511 #1 0x2af55ee3d9bb in QGestureManager::filterEventThroughContexts(QMultiMap const&, QEvent*) qgesturemanager.cpp:276 #2 0x2af55ee4565b in QGestureManager::filterEvent(QWidget*, QEvent*) qgesturemanager.cpp:512 #3 0x2af55ee53945 in QGestureManager::filterEvent(QObject*, QEvent*) qgesturemanager.cpp:556 #4 0x2af55ea1b83a in QApplication::notify(QObject*, QEvent*) qapplication.cpp:3053 #5 0x2af573949d0f in QCoreApplication::notifyInternal2(QObject*, QEvent*) qcoreapplication.cpp:988 #6 0x2af56982ff94 in QCoreApplication::sendEvent(QObject*, QEvent*) qcoreapplication.h:231 #7 0x2af56982ff94 in QWindowPrivate::create(bool) qwindow.cpp:435 #8 0x2af55ecd10fe in QWidgetPrivate::create_sys(unsigned long long, bool, bool) qwidget.cpp:1471 #9 0x2af55ecc770e in QWidget::create(unsigned long long, bool, bool) qwidget.cpp:1333 #10 0x2af55ed80618 in QWidget::setVisible(bool) qwidget.cpp:8156 #11 0x4feec4 in tst_QWidget::touchEventsForGesturePendingWidgets() tst_qwidget.cpp:9824 qstandardgestures.cpp:512:67: runtime error: downcast of address 0x7ffc9beb1b90 which does not point to an object of type 'QMouseEvent' 0x7ffc9beb1b90: note: object is of type 'QPlatformSurfaceEvent' fc 7f 00 00 08 93 b1 6f f5 2a 00 00 00 00 00 00 00 00 00 00 d9 00 ec 9b 00 00 00 00 49 01 c1 5e ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QPlatformSurfaceEvent' #0 0x2af55edfaa19 in QTapAndHoldGestureRecognizer::recognize(QGesture*, QObject*, QEvent*) qstandardgestures.cpp:512 [... skipping common lines ...] qstandardgestures.cpp:514:95: runtime error: downcast of address 0x 0x7ffc9beb1b90: note: object is of type 'QPlatformSurfaceEvent' fc 7f 00 00 08 93 b1 6f f5 2a 00 00 00 00 00 00 00 00 00 00 d9 00 ec 9b 00 00 00 0 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QPlatformSurfaceEvent' #0 0x2af55edfa966 in QTapAndHoldGestureRecognizer::recognize(QGesture*, QObject*, QEvent*) qstandardgestures.cpp:514 [... skipping common lines ...] The problem is that the casts are done outside the switch that determines the event's type, so for any given event object, at least any two of the casts are invalid. This could actually be a real problem, because it's trivial for a compiler to prove that these three lines unconditionally invoke UB, so it has all the right in the world to decide to drop the complete rest of the function, using this line of reasoning: 1. The only way for these three casts not to be UB is if event == nullptr. 2. If event == nullptr, then event->type() invokes UB, so event cannot be nullptr. 3. The only way both can be true is if this code path is never taken. I can thus assume that object == state && event->type() == QEvent::Timer is always true, drop the check and execute the if block unconditionally (I need to call QEvent::type(), to satisfy the as-if-rule, but I needn't check its return value). Fix by moving the casts where they belong: into each case of the switch, where the type of the event has been checked to match the target type of the cast. Change-Id: I3aee8e213dc19d2f51636bcc5221cc92b3142e58 Reviewed-by: Thiago Macieira --- src/widgets/kernel/qstandardgestures.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/widgets/kernel/qstandardgestures.cpp b/src/widgets/kernel/qstandardgestures.cpp index d7589cc594..dd3f782120 100644 --- a/src/widgets/kernel/qstandardgestures.cpp +++ b/src/widgets/kernel/qstandardgestures.cpp @@ -502,45 +502,46 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object, return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; } - const QTouchEvent *ev = static_cast(event); - const QMouseEvent *me = static_cast(event); -#ifndef QT_NO_GRAPHICSVIEW - const QGraphicsSceneMouseEvent *gsme = static_cast(event); -#endif - enum { TapRadius = 40 }; switch (event->type()) { #ifndef QT_NO_GRAPHICSVIEW - case QEvent::GraphicsSceneMousePress: + case QEvent::GraphicsSceneMousePress: { + const QGraphicsSceneMouseEvent *gsme = static_cast(event); d->position = gsme->screenPos(); q->setHotSpot(d->position); if (d->timerId) q->killTimer(d->timerId); d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout); return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout + } #endif - case QEvent::MouseButtonPress: + case QEvent::MouseButtonPress: { + const QMouseEvent *me = static_cast(event); d->position = me->globalPos(); q->setHotSpot(d->position); if (d->timerId) q->killTimer(d->timerId); d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout); return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout - case QEvent::TouchBegin: + } + case QEvent::TouchBegin: { + const QTouchEvent *ev = static_cast(event); d->position = ev->touchPoints().at(0).startScreenPos(); q->setHotSpot(d->position); if (d->timerId) q->killTimer(d->timerId); d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout); return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout + } #ifndef QT_NO_GRAPHICSVIEW case QEvent::GraphicsSceneMouseRelease: #endif case QEvent::MouseButtonRelease: case QEvent::TouchEnd: return QGestureRecognizer::CancelGesture; // get out of the MayBeGesture state - case QEvent::TouchUpdate: + case QEvent::TouchUpdate: { + const QTouchEvent *ev = static_cast(event); if (d->timerId && ev->touchPoints().size() == 1) { QTouchEvent::TouchPoint p = ev->touchPoints().at(0); QPoint delta = p.pos().toPoint() - p.startPos().toPoint(); @@ -548,7 +549,9 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object, return QGestureRecognizer::MayBeGesture; } return QGestureRecognizer::CancelGesture; + } case QEvent::MouseMove: { + const QMouseEvent *me = static_cast(event); QPoint delta = me->globalPos() - d->position.toPoint(); if (d->timerId && delta.manhattanLength() <= TapRadius) return QGestureRecognizer::MayBeGesture; @@ -556,6 +559,7 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object, } #ifndef QT_NO_GRAPHICSVIEW case QEvent::GraphicsSceneMouseMove: { + const QGraphicsSceneMouseEvent *gsme = static_cast(event); QPoint delta = gsme->screenPos() - d->position.toPoint(); if (d->timerId && delta.manhattanLength() <= TapRadius) return QGestureRecognizer::MayBeGesture; -- cgit v1.2.3 From da2c73ad2b84ef9d58a23fa880c05ca33a0053e5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 27 Sep 2016 10:22:46 +0200 Subject: Plug memleaks in tst_QWidget We need to delete the style returned from QStyleFactory::create() ourselves, so put them into a QScopedPointer. The alternative would have been to create this once, as a member of tst_QWidget, but this is the minimal approach that ensures behavior just as the old code, but without the leak. Change-Id: I527f1031c57be6f05942f4acc057e7dae1af2571 Reviewed-by: Thiago Macieira --- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 50d7b258bc..e00e575c36 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -5135,7 +5135,8 @@ void tst_QWidget::moveChild() ColorWidget parent(0, Qt::Window | Qt::WindowStaysOnTopHint); // prevent custom styles - parent.setStyle(QStyleFactory::create(QLatin1String("Windows"))); + const QScopedPointer style(QStyleFactory::create(QLatin1String("Windows"))); + parent.setStyle(style.data()); ColorWidget child(&parent, Qt::Widget, Qt::blue); #ifndef Q_OS_WINCE @@ -5184,7 +5185,8 @@ void tst_QWidget::showAndMoveChild() QSKIP("Wayland: This fails. Figure out why."); QWidget parent(0, Qt::Window | Qt::WindowStaysOnTopHint); // prevent custom styles - parent.setStyle(QStyleFactory::create(QLatin1String("Windows"))); + const QScopedPointer style(QStyleFactory::create(QLatin1String("Windows"))); + parent.setStyle(style.data()); QDesktopWidget desktop; QRect desktopDimensions = desktop.availableGeometry(&parent); @@ -6680,7 +6682,9 @@ void tst_QWidget::renderWithPainter() { QWidget widget(0, Qt::Tool); // prevent custom styles - widget.setStyle(QStyleFactory::create(QLatin1String("Windows"))); + + const QScopedPointer style(QStyleFactory::create(QLatin1String("Windows"))); + widget.setStyle(style.data()); widget.show(); widget.resize(70, 50); widget.setAutoFillBackground(true); -- cgit v1.2.3 From cf0119bb69592d58ca7e6a75753799ebae61e4b5 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 14 Sep 2016 16:48:10 +0200 Subject: syncqt.pl: fix a few misguided regexes to match .h file names To match correctly (only) .h files, a regex needs to end in \.h$ Some of them missed the \, one missed the $. (The last also had a legitimate .* before its misunescaped .) One pair matched _p.h and _pch.h, which could be combined. Change-Id: I7539a28eb7017cd0f1b36c72e05108e03a68a952 Reviewed-by: Oswald Buddenhagen --- bin/syncqt.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/syncqt.pl b/bin/syncqt.pl index 9dcc7fe4fd..06aff79a3a 100755 --- a/bin/syncqt.pl +++ b/bin/syncqt.pl @@ -355,7 +355,7 @@ sub check_header { $include = 0; } if ($include && $public_header) { - print STDERR "$lib: ERROR: $iheader includes private header $include\n" if ($include =~ /_p.h$/); + print STDERR "$lib: ERROR: $iheader includes private header $include\n" if ($include =~ /_p\.h$/); for my $trylib (keys(%modules)) { if (-e "$out_basedir/include/$trylib/$include") { print STDERR "$lib: WARNING: $iheader includes $include when it should include $trylib/$include\n"; @@ -982,7 +982,7 @@ foreach my $lib (@modules_to_sync) { my $header_dirname = ""; foreach my $header (@headers) { my $shadow = ($header =~ s/^\*//); - $header = 0 if($header =~ /^ui_.*.h/); + $header = 0 if ($header =~ /^ui_.*\.h$/); foreach (@ignore_headers) { $header = 0 if($header eq $_); } @@ -994,7 +994,7 @@ foreach my $lib (@modules_to_sync) { if(isQpaHeader($public_header)) { $public_header = 0; $qpa_header = 1; - } elsif($allheadersprivate || $thisprivate || $public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) { + } elsif ($allheadersprivate || $thisprivate || $public_header =~ /_p(ch)?\.h$/) { $public_header = 0; } else { foreach (@ignore_for_master_contents) { -- cgit v1.2.3