summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2021-04-16 21:24:45 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2021-04-19 20:13:58 +0000
commit905c71a434ae6de2cc075e00da2149065f7b5f98 (patch)
tree4aadb3fc1441b4e379ccf417c19b5d85834abbbb /examples
parentfbf6e77eecac2974ef26ef5a5b39a58c9fd23268 (diff)
Avoid divide-by-zero in the gradients example
After 7a738daa97436478a21b5dd31ba2312b2cb2df41 we require QLineF::setLength() to take a finite length, and this code was probably always risky when HoverPoints has two points that are both 0,0. It's probably a transient condition anyway. Fixes: QTBUG-92908 Change-Id: If81122d2f78761026b0d656ceffe173132751317 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io> (cherry picked from commit 76537c065aea1cb3926796f6a34eb39eb81f605f) Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/widgets/painting/gradients/gradients.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp
index 76d5818d32..045da2b0c0 100644
--- a/examples/widgets/painting/gradients/gradients.cpp
+++ b/examples/widgets/painting/gradients/gradients.cpp
@@ -105,6 +105,8 @@ uint ShadeWidget::colorAt(int x)
for (int i = 1; i < pts.size(); ++i) {
if (pts.at(i - 1).x() <= x && pts.at(i).x() >= x) {
QLineF l(pts.at(i - 1), pts.at(i));
+ if (qIsNull(l.dx()))
+ continue;
l.setLength(l.length() * ((x - l.x1()) / l.dx()));
return m_shade.pixel(qRound(qMin(l.x2(), (qreal(m_shade.width() - 1)))),
qRound(qMin(l.y2(), qreal(m_shade.height() - 1))));