Skip to content

Commit

Permalink
QStackedLayout: Fix UB (invalid cast) in qt_wasDeleted()
Browse files Browse the repository at this point in the history
Fixup of commit b4995eb.
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 <[email protected]>
  • Loading branch information
ogoffart committed May 30, 2017
1 parent c3030d7 commit c70c1d5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/corelib/kernel/qobject_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class Q_CORE_EXPORT QObjectPrivate : public QObjectData
static QObjectPrivate *get(QObject *o) {
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;
inline bool isSignalConnected(uint signalIdx, bool checkDeclarative = true) const;
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/kernel/qstackedlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ QLayoutItem *QStackedLayout::itemAt(int index) const
// on the object then)
static bool qt_wasDeleted(const QWidget *w)
{
return QWidgetPrivate::get(w)->wasDeleted;
return QObjectPrivate::get(w)->wasDeleted;
}


Expand Down

0 comments on commit c70c1d5

Please sign in to comment.