summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRobert Löhning <[email protected]>2025-10-17 17:22:33 +0200
committerRobert Löhning <[email protected]>2025-10-22 12:19:16 +0200
commit81f13dbadc428a044f9c75e9181928de08d2d8db (patch)
treef7e17870df263a45217a1a4c5d17bdb71f33add6 /src
parent1f5a45116232cbebbc9504614dcb0a6dc6f330c7 (diff)
QPainterPath: Avoid division by zero in *AtPercent
Without the added checks, the code divided by the paths' lengths which are zero. Pick-to: 6.10 6.8 Change-Id: I78a2066af96136635f85f4937619ff398a28072c Reviewed-by: Eirik Aavitsland <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/gui/painting/qpainterpath.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp
index 5763696266a..38c4a9ea87f 100644
--- a/src/gui/painting/qpainterpath.cpp
+++ b/src/gui/painting/qpainterpath.cpp
@@ -2937,6 +2937,8 @@ qreal QPainterPath::percentAtLength(qreal len) const
if (len > totalLength)
return 1;
+ Q_ASSERT(totalLength != 0);
+
if (d->cacheEnabled) {
const int ei = qMax(d->elementAtT(len / totalLength), 1); // Skip initial MoveTo
qreal res = 0;
@@ -3117,6 +3119,7 @@ QPointF QPainterPath::pointAtPercent(qreal t) const
qreal curLen = 0;
qreal bezierLen = 0;
QBezier b = d_ptr->bezierAtT(*this, t, &curLen, &bezierLen);
+ Q_ASSERT(bezierLen != 0);
qreal realT = (totalLength * t - curLen) / bezierLen;
return b.pointAt(qBound(qreal(0), realT, qreal(1)));
@@ -3141,10 +3144,14 @@ qreal QPainterPath::angleAtPercent(qreal t) const
return 0;
}
+ if (isEmpty())
+ return 0;
+
qreal totalLength = length();
qreal curLen = 0;
qreal bezierLen = 0;
QBezier bez = d_ptr->bezierAtT(*this, t, &curLen, &bezierLen);
+ Q_ASSERT(bezierLen != 0);
qreal realT = (totalLength * t - curLen) / bezierLen;
qreal m1 = slopeAt(realT, bez.x1, bez.x2, bez.x3, bez.x4);
@@ -3170,10 +3177,14 @@ qreal QPainterPath::slopeAtPercent(qreal t) const
return 0;
}
+ if (isEmpty())
+ return 0;
+
qreal totalLength = length();
qreal curLen = 0;
qreal bezierLen = 0;
QBezier bez = d_ptr->bezierAtT(*this, t, &curLen, &bezierLen);
+ Q_ASSERT(bezierLen != 0);
qreal realT = (totalLength * t - curLen) / bezierLen;
qreal m1 = slopeAt(realT, bez.x1, bez.x2, bez.x3, bez.x4);