From 5a938c286cd3d6e409dce8d9f92a6888f7248957 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 16 Dec 2021 09:04:01 +0100 Subject: QVariantAnimation: fix UB (FP 0/0) in interpolated() arg calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Jan Arve Sæther (cherry picked from commit 52da10f64542a6c4fda06be1b88e9111331f6500) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/animation/qvariantanimation.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/corelib/animation/qvariantanimation.cpp') diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp index 1622e6f006..5caafd6dd2 100644 --- a/src/corelib/animation/qvariantanimation.cpp +++ b/src/corelib/animation/qvariantanimation.cpp @@ -276,7 +276,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, -- cgit v1.2.3