QCborValue::fromJsonValue: rewrite code to remove UB

Converting an out-of-range FP to integer is UB. See comment in
qnumeric_p.h.

Change-Id: Ief874765cd7b43798de3fffd15a9bfe2c5fbbc01
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Thiago Macieira 2019-06-19 17:15:26 -07:00
parent eb144c3c4d
commit 0ef6150005

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2018 Intel Corporation.
** Copyright (C) 2019 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@ -598,10 +598,12 @@ QCborValue QCborValue::fromJsonValue(const QJsonValue &v)
switch (v.type()) {
case QJsonValue::Bool:
return v.b;
case QJsonValue::Double:
if (v.dbl == qint64(v.dbl))
return qint64(v.dbl);
case QJsonValue::Double: {
qint64 i;
if (convertDoubleTo(v.dbl, &i))
return i;
return v.dbl;
}
case QJsonValue::String:
return v.toString();
case QJsonValue::Array: