diff options
author | Luca Beldi <v.ronin@yahoo.it> | 2018-08-22 08:21:01 +0100 |
---|---|---|
committer | Luca Beldi <v.ronin@yahoo.it> | 2018-08-22 08:38:44 +0000 |
commit | 02b3d43fd4661271e6e8dc8940d84cb2ba352fe0 (patch) | |
tree | 814ffd42524fd64f299c7dae0f28e0499653e72b /src/corelib/animation | |
parent | 76c328b2b39617310993ce76e65665943b8c111c (diff) |
_q_interpolate<T> is unsafe with unsigned template arguments
_q_interpolate<T> subtracts 2 arguments of type T,
for unsigned types this can cause wrapping around
Task-number: QTBUG-57925
Change-Id: Iffa59f413579a3d5de8cb728fe71443d8e8a04aa
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/corelib/animation')
-rw-r--r-- | src/corelib/animation/qvariantanimation_p.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/corelib/animation/qvariantanimation_p.h b/src/corelib/animation/qvariantanimation_p.h index 37318a5339..9f0f2e3030 100644 --- a/src/corelib/animation/qvariantanimation_p.h +++ b/src/corelib/animation/qvariantanimation_p.h @@ -58,6 +58,8 @@ #include "private/qabstractanimation_p.h" +#include <type_traits> + #ifndef QT_NO_ANIMATION QT_BEGIN_NAMESPACE @@ -104,7 +106,17 @@ public: }; //this should make the interpolation faster -template<typename T> inline T _q_interpolate(const T &f, const T &t, qreal progress) +template<typename T> +typename std::enable_if<std::is_unsigned<T>::value, T>::type +_q_interpolate(const T &f, const T &t, qreal progress) +{ + return T(f + t * progress - f * progress); +} + +// the below will apply also to all non-arithmetic types +template<typename T> +typename std::enable_if<!std::is_unsigned<T>::value, T>::type +_q_interpolate(const T &f, const T &t, qreal progress) { return T(f + (t - f) * progress); } |