summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qrasterizer.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-11-20 15:58:04 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-11-21 03:21:21 +0000
commit9379e47831bd634aa046cf9a21542371ddde5c66 (patch)
tree4e8993f5ed094ec680c570520990c7cb788cd352 /src/gui/painting/qrasterizer.cpp
parent53b5bf1cd756cd7c75ca94e666d45b52c641d73d (diff)
Fix safe conversion
Ensure the resulting QScFixed values are no larger than can be safely returned to int after shifting the fixed factor away. Fixes: QTBUG-88683 Change-Id: Id0754b021e5fa9a3cf0d15e37ac643cfc1509993 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io> (cherry picked from commit a31484302d71c29c0e0e62f9941f9d5f0c87f9aa) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/gui/painting/qrasterizer.cpp')
-rw-r--r--src/gui/painting/qrasterizer.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/gui/painting/qrasterizer.cpp b/src/gui/painting/qrasterizer.cpp
index 921d260320..5a63840c03 100644
--- a/src/gui/painting/qrasterizer.cpp
+++ b/src/gui/painting/qrasterizer.cpp
@@ -725,10 +725,17 @@ static inline qreal qSafeDivide(qreal x, qreal y)
static inline QScFixed qSafeFloatToQScFixed(qreal x)
{
qreal tmp = x * QScFixedFactor;
- if (tmp > qreal(std::numeric_limits<QScFixed>::max()))
- return std::numeric_limits<QScFixed>::max();
- else if (tmp < qreal(std::numeric_limits<QScFixed>::min()))
- return std::numeric_limits<QScFixed>::min();
+#if Q_PROCESSOR_WORDSIZE == 8
+ if (tmp > qreal(INT_MAX) * QScFixedFactor)
+ return QScFixed(INT_MAX) * QScFixedFactor;
+ else if (tmp < qreal(INT_MIN) * QScFixedFactor)
+ return QScFixed(INT_MIN) * QScFixedFactor;
+#else
+ if (tmp > qreal(INT_MAX))
+ return INT_MAX;
+ else if (tmp < qreal(INT_MIN))
+ return -INT_MAX;
+#endif
return QScFixed(tmp);
}