From 76537c065aea1cb3926796f6a34eb39eb81f605f Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 16 Apr 2021 21:24:45 +0200 Subject: 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 --- examples/widgets/painting/gradients/gradients.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'examples') 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)))); -- cgit v1.2.3