diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-06-19 13:42:01 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-06-20 12:19:00 +0200 |
commit | 084e17c4e113f72dc43180bae2cb4e8c68b2a0f6 (patch) | |
tree | 2696fe887942e320dd622319022dc1da4cfbb2de /src/corelib/serialization/qjsonwriter.cpp | |
parent | b6ded193ee64ffe67df6d22e7a23aa1ea9e02ec7 (diff) |
Avoid undefined behavior in qjsonwriter.cpp
See comment in qnumeric_p.h:convertDoubleTo for details.
Change-Id: Ifcd13f7f67995af6a60e50ccabe843a855be04ae
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/serialization/qjsonwriter.cpp')
-rw-r--r-- | src/corelib/serialization/qjsonwriter.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/serialization/qjsonwriter.cpp b/src/corelib/serialization/qjsonwriter.cpp index 12ce20ef09..32feb41183 100644 --- a/src/corelib/serialization/qjsonwriter.cpp +++ b/src/corelib/serialization/qjsonwriter.cpp @@ -43,6 +43,7 @@ #include "qjsonwriter_p.h" #include "qjson_p.h" #include "private/qutfcodec_p.h" +#include <private/qnumeric_p.h> QT_BEGIN_NAMESPACE @@ -131,8 +132,9 @@ static void valueToJson(const QJsonPrivate::Base *b, const QJsonPrivate::Value & case QJsonValue::Double: { const double d = v.toDouble(b); if (qIsFinite(d)) { // +2 to format to ensure the expected precision - const double abs = std::abs(d); - json += QByteArray::number(d, abs == static_cast<quint64>(abs) ? 'f' : 'g', QLocale::FloatingPointShortest); + quint64 absInt; + json += QByteArray::number(d, convertDoubleTo(std::abs(d), &absInt) ? 'f' : 'g', + QLocale::FloatingPointShortest); } else { json += "null"; // +INF || -INF || NaN (see RFC4627#section2.4) } |