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:
Ulf Hermann 2021-06-15 14:46:55 +02:00
parent 988d9dfe85
commit c3b0f8756a
1 changed files with 5 additions and 1 deletions

View File

@ -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();
}