diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2017-10-02 16:54:27 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2017-10-04 10:17:47 +0000 |
commit | 837da5953ff325a5bc5171a0c1f9f7aecd4834e9 (patch) | |
tree | 585008587dfac9df26d379262278537b25997fca /src | |
parent | 265b3bea18c1ac13da413931024f64f49a2da7fc (diff) |
Fix Number.isNaN sometimes returning false for NaN
We use Encode(std::isnan(v)) and while std::isnan() is documented to
have bool as a return type, there is the case where cmath pulls ::isnan
into std with a using declaration when ::isnan() will sometimes return
an int.
See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69450
This appears to be the only case where we use the overloaded Encode()
constructor in conjunction with a direct std::isXXX call.
[ChangeLog][QtQml] Fix Number.isNaN() returning incorrect values with
some glibc versions.
Task-number: QTBUG-63464
Change-Id: Iaaba3735f7400eac0950aad8f3ac47befaf9dab9
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4numberobject.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp index 09644c161d..255d0212c1 100644 --- a/src/qml/jsruntime/qv4numberobject.cpp +++ b/src/qml/jsruntime/qv4numberobject.cpp @@ -163,7 +163,9 @@ void NumberPrototype::method_isNaN(const BuiltinFunction *, Scope &scope, CallDa } double v = callData->args[0].toNumber(); - scope.result = Encode(std::isnan(v)); + // cast to bool explicitly as std::isnan() may give us ::isnan(), which + // sometimes returns an int and we don't want the Encode(int) overload. + scope.result = Encode(bool(std::isnan(v))); } void NumberPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData) |