diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-06-15 14:46:55 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-06-16 13:30:47 +0200 |
commit | c3b0f8756aee5cc9d965a641088390fff0fed459 (patch) | |
tree | ba16f8da3fa50ef3948e63aee2524f279c84e1d9 /src/qml/common | |
parent | 988d9dfe8591ae19f2758b69b158bcb45c55d9ae (diff) |
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>
Diffstat (limited to 'src/qml/common')
-rw-r--r-- | src/qml/common/qjsnumbercoercion.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/qml/common/qjsnumbercoercion.h b/src/qml/common/qjsnumbercoercion.h index 51dbe6beb5..2517442bb6 100644 --- a/src/qml/common/qjsnumbercoercion.h +++ b/src/qml/common/qjsnumbercoercion.h @@ -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(); } |