Fix UB in tst_QDialog::showExtension()
Don't cast a QDialog to a subclass it is not. Fix by creating it as the required subclass in the first place. Found by UBSan: tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp:203:20: runtime error: downcast of address 0x2b5f5000ad40 which does not point to an object of type 'DummyDialog' tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp:203:46: runtime error: member call on address 0x2b5f5000ad40 which does not point to an object of type 'DummyDialog' Change-Id: I63ae7e782bda6a78d11af5c2bc2f7d88aacd0ac0 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>bb10
parent
f5291bf8b4
commit
9c7be0a7ec
|
|
@ -49,6 +49,14 @@
|
|||
|
||||
QT_FORWARD_DECLARE_CLASS(QDialog)
|
||||
|
||||
// work around function being protected
|
||||
class DummyDialog : public QDialog
|
||||
{
|
||||
public:
|
||||
DummyDialog(): QDialog(0, Qt::X11BypassWindowManagerHint) {}
|
||||
using QDialog::showExtension;
|
||||
};
|
||||
|
||||
class tst_QDialog : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -82,7 +90,7 @@ private slots:
|
|||
void transientParent();
|
||||
|
||||
private:
|
||||
QDialog *testWidget;
|
||||
DummyDialog *testWidget;
|
||||
};
|
||||
|
||||
// Testing get/set functions
|
||||
|
|
@ -108,13 +116,6 @@ void tst_QDialog::getSetCheck()
|
|||
QCOMPARE(INT_MAX, obj1.result());
|
||||
}
|
||||
|
||||
// work around function being protected
|
||||
class DummyDialog : public QDialog {
|
||||
public:
|
||||
DummyDialog(): QDialog(0) {}
|
||||
void showExtension( bool b ) { QDialog::showExtension( b ); }
|
||||
};
|
||||
|
||||
class ToolDialog : public QDialog
|
||||
{
|
||||
public:
|
||||
|
|
@ -148,7 +149,7 @@ tst_QDialog::tst_QDialog()
|
|||
void tst_QDialog::initTestCase()
|
||||
{
|
||||
// Create the test class
|
||||
testWidget = new QDialog(0, Qt::X11BypassWindowManagerHint);
|
||||
testWidget = new DummyDialog;
|
||||
testWidget->resize(200,200);
|
||||
testWidget->show();
|
||||
qApp->setActiveWindow(testWidget);
|
||||
|
|
@ -193,7 +194,7 @@ void tst_QDialog::showExtension()
|
|||
QPoint oldPosition = testWidget->pos();
|
||||
|
||||
// show
|
||||
((DummyDialog*)testWidget)->showExtension( true );
|
||||
testWidget->showExtension( true );
|
||||
// while ( testWidget->size() == dlgSize )
|
||||
// qApp->processEvents();
|
||||
|
||||
|
|
@ -202,7 +203,7 @@ void tst_QDialog::showExtension()
|
|||
QCOMPARE(testWidget->pos(), oldPosition);
|
||||
|
||||
// hide extension. back to old size ?
|
||||
((DummyDialog*)testWidget)->showExtension( false );
|
||||
testWidget->showExtension( false );
|
||||
QCOMPARE( testWidget->size(), dlgSize );
|
||||
|
||||
testWidget->setExtension( 0 );
|
||||
|
|
|
|||
Loading…
Reference in New Issue