Fix error reported by address sanitizer

It is not valid to dereference a null pointer, even if it's just in order
to access enum constants

Change-Id: Id404c308ae7ffd879afdd678302e3ac4e0c69001
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
This commit is contained in:
Olivier Goffart 2014-08-12 13:11:53 +02:00
parent 7ca5af28d0
commit 135a286844
2 changed files with 20 additions and 14 deletions

View File

@ -1030,14 +1030,16 @@ private:
template <class T> inline T qgraphicsitem_cast(QGraphicsItem *item)
{
return int(static_cast<T>(0)->Type) == int(QGraphicsItem::Type)
|| (item && int(static_cast<T>(0)->Type) == item->type()) ? static_cast<T>(item) : 0;
typedef typename QtPrivate::remove_cv<typename QtPrivate::remove_pointer<T>::type>::type Item;
return int(Item::Type) == int(QGraphicsItem::Type)
|| (item && int(Item::Type) == item->type()) ? static_cast<T>(item) : 0;
}
template <class T> inline T qgraphicsitem_cast(const QGraphicsItem *item)
{
return int(static_cast<T>(0)->Type) == int(QGraphicsItem::Type)
|| (item && int(static_cast<T>(0)->Type) == item->type()) ? static_cast<T>(item) : 0;
typedef typename QtPrivate::remove_cv<typename QtPrivate::remove_pointer<T>::type>::type Item;
return int(Item::Type) == int(QGraphicsItem::Type)
|| (item && int(Item::Type) == item->type()) ? static_cast<T>(item) : 0;
}
#ifndef QT_NO_DEBUG_STREAM

View File

@ -666,9 +666,10 @@ protected:
template <typename T>
T qstyleoption_cast(const QStyleOption *opt)
{
if (opt && opt->version >= static_cast<T>(0)->Version && (opt->type == static_cast<T>(0)->Type
|| int(static_cast<T>(0)->Type) == QStyleOption::SO_Default
|| (int(static_cast<T>(0)->Type) == QStyleOption::SO_Complex
typedef typename QtPrivate::remove_cv<typename QtPrivate::remove_pointer<T>::type>::type Opt;
if (opt && opt->version >= Opt::Version && (opt->type == Opt::Type
|| int(Opt::Type) == QStyleOption::SO_Default
|| (int(Opt::Type) == QStyleOption::SO_Complex
&& opt->type > QStyleOption::SO_Complex)))
return static_cast<T>(opt);
return 0;
@ -677,9 +678,10 @@ T qstyleoption_cast(const QStyleOption *opt)
template <typename T>
T qstyleoption_cast(QStyleOption *opt)
{
if (opt && opt->version >= static_cast<T>(0)->Version && (opt->type == static_cast<T>(0)->Type
|| int(static_cast<T>(0)->Type) == QStyleOption::SO_Default
|| (int(static_cast<T>(0)->Type) == QStyleOption::SO_Complex
typedef typename QtPrivate::remove_cv<typename QtPrivate::remove_pointer<T>::type>::type Opt;
if (opt && opt->version >= Opt::Version && (opt->type == Opt::Type
|| int(Opt::Type) == QStyleOption::SO_Default
|| (int(Opt::Type) == QStyleOption::SO_Complex
&& opt->type > QStyleOption::SO_Complex)))
return static_cast<T>(opt);
return 0;
@ -727,8 +729,9 @@ public:
template <typename T>
T qstyleoption_cast(const QStyleHintReturn *hint)
{
if (hint && hint->version <= static_cast<T>(0)->Version &&
(hint->type == static_cast<T>(0)->Type || int(static_cast<T>(0)->Type) == QStyleHintReturn::SH_Default))
typedef typename QtPrivate::remove_cv<typename QtPrivate::remove_pointer<T>::type>::type Opt;
if (hint && hint->version <= Opt::Version &&
(hint->type == Opt::Type || int(Opt::Type) == QStyleHintReturn::SH_Default))
return static_cast<T>(hint);
return 0;
}
@ -736,8 +739,9 @@ T qstyleoption_cast(const QStyleHintReturn *hint)
template <typename T>
T qstyleoption_cast(QStyleHintReturn *hint)
{
if (hint && hint->version <= static_cast<T>(0)->Version &&
(hint->type == static_cast<T>(0)->Type || int(static_cast<T>(0)->Type) == QStyleHintReturn::SH_Default))
typedef typename QtPrivate::remove_cv<typename QtPrivate::remove_pointer<T>::type>::type Opt;
if (hint && hint->version <= Opt::Version &&
(hint->type == Opt::Type || int(Opt::Type) == QStyleHintReturn::SH_Default))
return static_cast<T>(hint);
return 0;
}