diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2014-08-12 13:10:16 +0200 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2014-08-12 23:59:59 +0200 |
commit | 7ca5af28d0591ab34c6ce17ed7b9eff20cca1d67 (patch) | |
tree | eddd1e0296b791e2deeb50adb2eb814f7e5d9cd8 /src/corelib/kernel/qobject.h | |
parent | b08cc0ec6f096d0e6764486c81264c24a406bee1 (diff) |
Fix error reported by address sanitizer
One can't dereference the null pointer value. Even to access a static member.
Change-Id: I5edc92d7886ccc7029d1f3c00a12de78b439f080
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Diffstat (limited to 'src/corelib/kernel/qobject.h')
-rw-r--r-- | src/corelib/kernel/qobject.h | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index a54690606a..0b6c65ef95 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -156,13 +156,17 @@ public: template<typename T> inline T findChild(const QString &aName = QString(), Qt::FindChildOptions options = Qt::FindChildrenRecursively) const - { return static_cast<T>(qt_qFindChild_helper(this, aName, reinterpret_cast<T>(0)->staticMetaObject, options)); } + { + typedef typename QtPrivate::remove_cv<typename QtPrivate::remove_pointer<T>::type>::type ObjType; + return static_cast<T>(qt_qFindChild_helper(this, aName, ObjType::staticMetaObject, options)); + } template<typename T> inline QList<T> findChildren(const QString &aName = QString(), Qt::FindChildOptions options = Qt::FindChildrenRecursively) const { + typedef typename QtPrivate::remove_cv<typename QtPrivate::remove_pointer<T>::type>::type ObjType; QList<T> list; - qt_qFindChildren_helper(this, aName, reinterpret_cast<T>(0)->staticMetaObject, + qt_qFindChildren_helper(this, aName, ObjType::staticMetaObject, reinterpret_cast<QList<void *> *>(&list), options); return list; } @@ -171,8 +175,9 @@ public: template<typename T> inline QList<T> findChildren(const QRegExp &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const { + typedef typename QtPrivate::remove_cv<typename QtPrivate::remove_pointer<T>::type>::type ObjType; QList<T> list; - qt_qFindChildren_helper(this, re, reinterpret_cast<T>(0)->staticMetaObject, + qt_qFindChildren_helper(this, re, ObjType::staticMetaObject, reinterpret_cast<QList<void *> *>(&list), options); return list; } @@ -182,8 +187,9 @@ public: template<typename T> inline QList<T> findChildren(const QRegularExpression &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const { + typedef typename QtPrivate::remove_cv<typename QtPrivate::remove_pointer<T>::type>::type ObjType; QList<T> list; - qt_qFindChildren_helper(this, re, reinterpret_cast<T>(0)->staticMetaObject, + qt_qFindChildren_helper(this, re, ObjType::staticMetaObject, reinterpret_cast<QList<void *> *>(&list), options); return list; } @@ -519,7 +525,7 @@ inline T qobject_cast(QObject *object) typedef typename QtPrivate::remove_cv<typename QtPrivate::remove_pointer<T>::type>::type ObjType; Q_STATIC_ASSERT_X(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value, "qobject_cast requires the type to have a Q_OBJECT macro"); - return static_cast<T>(reinterpret_cast<T>(object)->staticMetaObject.cast(object)); + return static_cast<T>(ObjType::staticMetaObject.cast(object)); } template <class T> @@ -528,7 +534,7 @@ inline T qobject_cast(const QObject *object) typedef typename QtPrivate::remove_cv<typename QtPrivate::remove_pointer<T>::type>::type ObjType; Q_STATIC_ASSERT_X(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value, "qobject_cast requires the type to have a Q_OBJECT macro"); - return static_cast<T>(reinterpret_cast<T>(object)->staticMetaObject.cast(object)); + return static_cast<T>(ObjType::staticMetaObject.cast(object)); } |