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>
This commit is contained in:
parent
28b419c733
commit
c0b0ade622
@ -725,10 +725,17 @@ static inline qreal qSafeDivide(qreal x, qreal y)
|
|||||||
static inline QScFixed qSafeFloatToQScFixed(qreal x)
|
static inline QScFixed qSafeFloatToQScFixed(qreal x)
|
||||||
{
|
{
|
||||||
qreal tmp = x * QScFixedFactor;
|
qreal tmp = x * QScFixedFactor;
|
||||||
if (tmp > qreal(std::numeric_limits<QScFixed>::max()))
|
#if Q_PROCESSOR_WORDSIZE == 8
|
||||||
return std::numeric_limits<QScFixed>::max();
|
if (tmp > qreal(INT_MAX) * QScFixedFactor)
|
||||||
else if (tmp < qreal(std::numeric_limits<QScFixed>::min()))
|
return QScFixed(INT_MAX) * QScFixedFactor;
|
||||||
return std::numeric_limits<QScFixed>::min();
|
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);
|
return QScFixed(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user