QStackedLayout: Fix UB (invalid cast) in qt_wasDeleted()

Fixup of commit b4995eb749.
We can't call QWidgetPrivate::get(w) on a deleted QWidget, because of
the call to the member function QWidget::d_func. We can however call
QObjectPrivate::get since we still are in the QObject destructor.

tst_qstackedlayout now pass without ubsan Warnings.

Change-Id: I4e839a97ddbd1cf21435a8fca76523b98a1f7d9b
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Olivier Goffart 2017-05-29 13:45:25 +02:00 committed by Olivier Goffart (Woboq GmbH)
parent c3030d7163
commit c70c1d54f4
2 changed files with 2 additions and 1 deletions

View File

@ -198,6 +198,7 @@ public:
static QObjectPrivate *get(QObject *o) { static QObjectPrivate *get(QObject *o) {
return o->d_func(); return o->d_func();
} }
static const QObjectPrivate *get(const QObject *o) { return o->d_func(); }
int signalIndex(const char *signalName, const QMetaObject **meta = 0) const; int signalIndex(const char *signalName, const QMetaObject **meta = 0) const;
inline bool isSignalConnected(uint signalIdx, bool checkDeclarative = true) const; inline bool isSignalConnected(uint signalIdx, bool checkDeclarative = true) const;

View File

@ -253,7 +253,7 @@ QLayoutItem *QStackedLayout::itemAt(int index) const
// on the object then) // on the object then)
static bool qt_wasDeleted(const QWidget *w) static bool qt_wasDeleted(const QWidget *w)
{ {
return QWidgetPrivate::get(w)->wasDeleted; return QObjectPrivate::get(w)->wasDeleted;
} }