Avoid UB in qjsnumbercoercion.h
We need to check for NaN before casting a double to an integer. Pick-to: 6.2 Task-number: QTBUG-94068 Change-Id: Ib7bfab5ab2e24af950c8f8d7b32c7d411bd8cb71 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
988d9dfe85
commit
c3b0f8756a
|
@ -49,9 +49,13 @@ class QJSNumberCoercion
|
|||
{
|
||||
public:
|
||||
static constexpr int toInteger(double d) {
|
||||
int i = static_cast<int>(d);
|
||||
if (!equals(d, d))
|
||||
return 0;
|
||||
|
||||
const int i = static_cast<int>(d);
|
||||
if (equals(i, d))
|
||||
return i;
|
||||
|
||||
return QJSNumberCoercion(d).toInteger();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue