diff options
author | Robert Loehning <robert.loehning@qt.io> | 2020-08-03 22:42:23 +0200 |
---|---|---|
committer | Robert Loehning <robert.loehning@qt.io> | 2020-08-25 17:59:10 +0200 |
commit | c0d0949448c5a75d50ca189974d4d9f48133aea8 (patch) | |
tree | 4754cd61f7f61289c2171a93e6716b7165bef9f2 /src/corelib/tools/qline.h | |
parent | e1d7df5ce9eb1d370e1b6dcd31ced4029082d63d (diff) |
QLineF: Don't try calculating a unit vector when length is null
It's undefined and causes a division by zero.
Fixes: oss-fuzz-24561
Pick-to: 5.12 5.15
Change-Id: Idebaba4b286e3ab0ecb74825d203244958ce6aec
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qline.h')
-rw-r--r-- | src/corelib/tools/qline.h | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/corelib/tools/qline.h b/src/corelib/tools/qline.h index 066bcecc1b..8889c4afb9 100644 --- a/src/corelib/tools/qline.h +++ b/src/corelib/tools/qline.h @@ -40,6 +40,8 @@ #ifndef QLINE_H #define QLINE_H +#include "qmath.h" + #include <QtCore/qpoint.h> QT_BEGIN_NAMESPACE @@ -369,12 +371,15 @@ constexpr inline QPointF QLineF::center() const return QPointF(0.5 * pt1.x() + 0.5 * pt2.x(), 0.5 * pt1.y() + 0.5 * pt2.y()); } +QT_WARNING_DISABLE_FLOAT_COMPARE + inline void QLineF::setLength(qreal len) { - if (isNull()) + const qreal oldlength = qSqrt(dx() * dx() + dy() * dy()); + if (!oldlength) return; - QLineF v = unitVector(); - pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); + const qreal factor = len / oldlength; + pt2 = QPointF(pt1.x() + dx() * factor, pt1.y() + dy() * factor); } constexpr inline QPointF QLineF::pointAt(qreal t) const |