summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2014-08-12 13:11:53 +0200
committerOlivier Goffart <ogoffart@woboq.com>2014-08-13 00:00:03 +0200
commit135a2868443a1d9962dece52034db475f3e75036 (patch)
tree9b6cdfb85c780b78730b30849d6c26da756271d1 /src/widgets/styles
parent7ca5af28d0591ab34c6ce17ed7b9eff20cca1d67 (diff)
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>
Diffstat (limited to 'src/widgets/styles')
-rw-r--r--src/widgets/styles/qstyleoption.h24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/widgets/styles/qstyleoption.h b/src/widgets/styles/qstyleoption.h
index 4f817a3353..94ec55002a 100644
--- a/src/widgets/styles/qstyleoption.h
+++ b/src/widgets/styles/qstyleoption.h
@@ -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;
}