qt5base-lts/tests/auto/widgets/kernel
Marc Mutz dc737fa0d7 tst_QShortcut: Fix UB (invalid cast) in shortcutDestroyed()
The slot is invoked from QObject::destroyed(), which is emitted
from ~QObject. By that time the object is no longer a QShortcut,
so the static_cast it invalid.

Found by UBSan:

  tst_qshortcut.cpp:1210:53: runtime error: downcast of address 0x6020000289d0 which does not point to an object of type 'QShortcut'
  0x6020000289d0: note: object is of type 'QObject'
   10 00 80 17  c0 ce 63 df 93 2b 00 00  b0 02 00 00 d0 60 00 00  02 00 00 00 ff ff ff 04  04 00 00 00
                ^~~~~~~~~~~~~~~~~~~~~~~
                vptr for 'QObject'
    #0 0x42b3bb in tst_QShortcut::shortcutDestroyed(QObject*) tst_qshortcut.cpp:1210
    #1 0x446cc9 in tst_QShortcut::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) .moc/tst_qshortcut.moc:186
    #2 0x2b93dba52c86 in QMetaObject::activate(QObject*, int, int, void**) qobject.cpp:3787
    #3 0x2b93dba55400 in QObject::destroyed(QObject*) .moc/moc_qobject.cpp:213
    #4 0x2b93dba8d80d in QObject::~QObject() qobject.cpp:967
    #5 0x2b93c6b6e032 in QShortcut::~QShortcut() qshortcut.cpp:476
    #6 0x2b93c6b6e370 in QShortcut::~QShortcut() qshortcut.cpp:481
    #7 0x42a5de in void qDeleteAll<QList<QShortcut*>::const_iterator>(QList<QShortcut*>::const_iterator, QList<QShortcut*>::const_iterator) qalgorithms.h:317
    #8 0x42a5de in void qDeleteAll<QList<QShortcut*> >(QList<QShortcut*> const&) qalgorithms.h:325
    #9 0x42a5de in tst_QShortcut::clearAllShortcuts() tst_qshortcut.cpp:1136

Fix by replacing QVector::replaceAll() with the erase-remove idiom,
which does not require the cast, because it can perform mixed-type
lookups.

Change-Id: I4251c1895fa4398023f489dbfd7108d90c1a6c94
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2016-10-05 17:47:09 +00:00
..
qaction tests/auto/widgets: Replace Q[TRY]_VERIFY(a == b) by Q[TRY]_COMPARE(a, b). 2015-07-31 11:50:10 +00:00
qactiongroup tests/auto/widgets: Replace Q[TRY]_VERIFY(a == b) by Q[TRY]_COMPARE(a, b). 2015-07-31 11:50:10 +00:00
qapplication tst_QApplication: Fix UBs (invalid cast) in focusMouseClick() 2016-09-28 04:56:34 +00:00
qboxlayout Plug memleaks in tst_QBoxLayout 2016-09-27 06:30:29 +00:00
qdesktopwidget Add check for top level widget leaks in kernel test of QtWidgets. 2015-06-16 14:14:18 +00:00
qformlayout tests/auto/widgets: Replace Q[TRY]_VERIFY(a == b) by Q[TRY]_COMPARE(a, b). 2015-07-31 11:50:10 +00:00
qgridlayout Plug memleaks in tst_QGridLayout 2016-09-27 06:30:34 +00:00
qlayout tests/auto/widgets: Replace Q[TRY]_VERIFY(a == b) by Q[TRY]_COMPARE(a, b). 2015-07-31 11:50:10 +00:00
qshortcut tst_QShortcut: Fix UB (invalid cast) in shortcutDestroyed() 2016-10-05 17:47:09 +00:00
qsizepolicy Add check for top level widget leaks in kernel test of QtWidgets. 2015-06-16 14:14:18 +00:00
qstackedlayout Update copyright headers 2015-02-11 06:49:51 +00:00
qtooltip Merge remote-tracking branch 'origin/5.5' into dev 2015-07-01 11:05:26 +02:00
qwidget Plug memleaks in tst_QWidget 2016-09-28 04:56:48 +00:00
qwidget_window QtWidgets: Reduce paint events when resizing native widget 2016-05-19 10:11:27 +00:00
qwidgetaction tests/auto/widgets: Replace Q[TRY]_VERIFY(a == b) by Q[TRY]_COMPARE(a, b). 2015-07-31 11:50:10 +00:00
qwidgetmetatype Update copyright headers 2015-02-11 06:49:51 +00:00
qwidgetsvariant tests/auto/widgets: Replace Q[TRY]_VERIFY(a == b) by Q[TRY]_COMPARE(a, b). 2015-07-31 11:50:10 +00:00
qwindowcontainer QtWidgets: Allow to cover up the window container by another widget 2016-01-28 17:40:53 +00:00
kernel.pro Introducing QWidget::createWindowContainer() 2013-01-25 14:11:07 +01:00