Fix safe conversion
Ensure the resulting QScFixed values are no larger than can be safely returned to int after shifting the fixed factor away. Pick-to: 6.0 6.0.0 Fixes: QTBUG-88683 Change-Id: Id0754b021e5fa9a3cf0d15e37ac643cfc1509993 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>bb10
parent
fb21a5ce1a
commit
a31484302d
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue