diff options
author | Marc Mutz <marc.mutz@qt.io> | 2021-12-16 09:04:01 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-12-22 09:24:09 +0000 |
commit | fe6ee7ec287232240675c3387e9b35c666d0f7f3 (patch) | |
tree | b8eb595df3334ff2c569e19932b67481e3f403cd /src | |
parent | 4c6b61a88eb4de0eb814602232121ffbe9614a0d (diff) |
QVariantAnimation: fix UB (FP 0/0) in interpolated() arg calculation
When startProgress, endProgress, and progress were all 0 (as provoked
by tst_QPropertyAnimation::startWithoutStartValue()), we'd calculate
0/0 and ubsan complained:
qvariantanimation.cpp:284:60: runtime error: division by zero
Fix by detecting progress - startProgress == 0 and setting
localProgress = 0.0 in that case. This is a logical result, even
though it might not be what IEEE754 rules would have yielded.
A more comprehensive change that aims to reliably keep localProgress
∈ [0,1] and thus avoid the infinities when endProgress ==
startProgress, is outside the scope of this patch, which deals only
with the UBSan error.
Change-Id: I5258b054a2060006795f49fb1cd7604aea3ed46b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
(cherry picked from commit 52da10f64542a6c4fda06be1b88e9111331f6500)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/animation/qvariantanimation.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp index a0f0e176b6..026db981ea 100644 --- a/src/corelib/animation/qvariantanimation.cpp +++ b/src/corelib/animation/qvariantanimation.cpp @@ -278,7 +278,9 @@ void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress) const qreal startProgress = currentInterval.start.first; const qreal endProgress = currentInterval.end.first; - const qreal localProgress = (progress - startProgress) / (endProgress - startProgress); + const qreal localProgress = + qIsNull(progress - startProgress) ? 0.0 // avoid 0/0 below + /* else */ : (progress - startProgress) / (endProgress - startProgress); QVariant ret = q->interpolated(currentInterval.start.second, currentInterval.end.second, |