summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-11-27 01:00:08 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-11-27 01:00:09 +0100
commit1b5bbacdb0888c01de588bf3b4d42166757c98e0 (patch)
treeadba8989ebb09a024c5e5924d2910856ca42473f /src
parentba13c6c08f30a4c2f188f69deeaf4ca6a020d7a1 (diff)
parent71bd06d516a2410ae0ea698e79dcb94aba9bc5b4 (diff)
Merge remote-tracking branch 'origin/5.11' into 5.12
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qbytearray.cpp6
-rw-r--r--src/corelib/tools/qlocale.cpp36
-rw-r--r--src/corelib/tools/qlocale_p.h11
-rw-r--r--src/corelib/tools/qlocale_tools.cpp2
-rw-r--r--src/corelib/tools/qstring.cpp12
-rw-r--r--src/plugins/platforms/cocoa/qmacclipboard.mm28
-rw-r--r--src/testlib/qtestcase.cpp11
7 files changed, 80 insertions, 26 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 53ae7b9452..c8bb384532 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -4114,7 +4114,8 @@ ushort QByteArray::toUShort(bool *ok, int base) const
/*!
Returns the byte array converted to a \c double value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -4149,7 +4150,8 @@ double QByteArray::toDouble(bool *ok) const
/*!
Returns the byte array converted to a \c float value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index ddc973cb37..1f5d5f0dc6 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -1366,8 +1366,10 @@ qulonglong QLocale::toULongLong(const QString &s, bool *ok) const
}
/*!
- Returns the float represented by the localized string \a s, or 0.0
- if the conversion failed.
+ Returns the float represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1386,8 +1388,10 @@ float QLocale::toFloat(const QString &s, bool *ok) const
}
/*!
- Returns the double represented by the localized string \a s, or
- 0.0 if the conversion failed.
+ Returns the double represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1533,8 +1537,10 @@ qulonglong QLocale::toULongLong(const QStringRef &s, bool *ok) const
}
/*!
- Returns the float represented by the localized string \a s, or 0.0
- if the conversion failed.
+ Returns the float represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1555,8 +1561,10 @@ float QLocale::toFloat(const QStringRef &s, bool *ok) const
}
/*!
- Returns the double represented by the localized string \a s, or
- 0.0 if the conversion failed.
+ Returns the double represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1705,8 +1713,10 @@ qulonglong QLocale::toULongLong(QStringView s, bool *ok) const
}
/*!
- Returns the float represented by the localized string \a s, or 0.0
- if the conversion failed.
+ Returns the float represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1724,8 +1734,10 @@ float QLocale::toFloat(QStringView s, bool *ok) const
}
/*!
- Returns the double represented by the localized string \a s, or
- 0.0 if the conversion failed.
+ Returns the double represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index a9c23aed61..a96ecf1c1c 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -249,7 +249,16 @@ public:
if (std::fabs(d) > std::numeric_limits<float>::max()) {
if (ok != 0)
*ok = false;
- return 0.0f;
+ const float huge = std::numeric_limits<float>::infinity();
+ return d < 0 ? -huge : huge;
+ }
+ if (std::fabs(d) >= std::numeric_limits<double>::min() // i.e. d != 0
+ && std::fabs(d) < std::numeric_limits<float>::min()) {
+ // Values smaller than std::numeric_limits<double>::min() have
+ // failed already; match them.
+ if (ok != 0)
+ *ok = false;
+ return 0;
}
return float(d);
}
diff --git a/src/corelib/tools/qlocale_tools.cpp b/src/corelib/tools/qlocale_tools.cpp
index bde52a20b9..53258bec3e 100644
--- a/src/corelib/tools/qlocale_tools.cpp
+++ b/src/corelib/tools/qlocale_tools.cpp
@@ -354,7 +354,7 @@ double qt_asciiToDouble(const char *num, int numLen, bool &ok, int &processed,
ok = false;
for (int i = 0; i < processed; ++i) {
char c = num[i];
- if ((c < '0' || c > '9') && c != '.' && c != '-' && c != '+' && c != 'e') {
+ if ((c < '0' || c > '9') && c != '.' && c != '-' && c != '+' && c != 'e' && c != 'E') {
// Garbage found
processed = 0;
return 0.0;
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index d5a67352ad..edb9983c33 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -7401,7 +7401,8 @@ ushort QString::toUShort(bool *ok, int base) const
/*!
Returns the string converted to a \c double value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -7439,7 +7440,8 @@ double QString::toDouble(bool *ok) const
/*!
Returns the string converted to a \c float value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -12008,7 +12010,8 @@ ushort QStringRef::toUShort(bool *ok, int base) const
/*!
Returns the string converted to a \c double value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -12033,7 +12036,8 @@ double QStringRef::toDouble(bool *ok) const
/*!
Returns the string converted to a \c float value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
diff --git a/src/plugins/platforms/cocoa/qmacclipboard.mm b/src/plugins/platforms/cocoa/qmacclipboard.mm
index 5939003c64..ba6cfca219 100644
--- a/src/plugins/platforms/cocoa/qmacclipboard.mm
+++ b/src/plugins/platforms/cocoa/qmacclipboard.mm
@@ -49,6 +49,7 @@
#include <stdlib.h>
#include <string.h>
#include "qcocoahelpers.h"
+#include <type_traits>
QT_BEGIN_NAMESPACE
@@ -61,6 +62,23 @@ QT_BEGIN_NAMESPACE
QMacPasteboard code
*****************************************************************************/
+namespace
+{
+OSStatus PasteboardGetItemCountSafe(PasteboardRef paste, ItemCount *cnt)
+{
+ Q_ASSERT(paste);
+ Q_ASSERT(cnt);
+ const OSStatus result = PasteboardGetItemCount(paste, cnt);
+ // Despite being declared unsigned, this API can return -1
+ if (std::make_signed<ItemCount>::type(*cnt) < 0)
+ *cnt = 0;
+ return result;
+}
+} // namespace
+
+// Ensure we don't call the broken one later on
+#define PasteboardGetItemCount
+
class QMacMimeData : public QMimeData
{
public:
@@ -210,7 +228,7 @@ QMacPasteboard::hasOSType(int c_flavor) const
sync();
ItemCount cnt = 0;
- if (PasteboardGetItemCount(paste, &cnt) || !cnt)
+ if (PasteboardGetItemCountSafe(paste, &cnt) || !cnt)
return false;
#ifdef DEBUG_PASTEBOARD
@@ -257,7 +275,7 @@ QMacPasteboard::hasFlavor(QString c_flavor) const
sync();
ItemCount cnt = 0;
- if (PasteboardGetItemCount(paste, &cnt) || !cnt)
+ if (PasteboardGetItemCountSafe(paste, &cnt) || !cnt)
return false;
#ifdef DEBUG_PASTEBOARD
@@ -374,7 +392,7 @@ QMacPasteboard::formats() const
QStringList ret;
ItemCount cnt = 0;
- if (PasteboardGetItemCount(paste, &cnt) || !cnt)
+ if (PasteboardGetItemCountSafe(paste, &cnt) || !cnt)
return ret;
#ifdef DEBUG_PASTEBOARD
@@ -417,7 +435,7 @@ QMacPasteboard::hasFormat(const QString &format) const
sync();
ItemCount cnt = 0;
- if (PasteboardGetItemCount(paste, &cnt) || !cnt)
+ if (PasteboardGetItemCountSafe(paste, &cnt) || !cnt)
return false;
#ifdef DEBUG_PASTEBOARD
@@ -460,7 +478,7 @@ QMacPasteboard::retrieveData(const QString &format, QVariant::Type) const
sync();
ItemCount cnt = 0;
- if (PasteboardGetItemCount(paste, &cnt) || !cnt)
+ if (PasteboardGetItemCountSafe(paste, &cnt) || !cnt)
return QByteArray();
#ifdef DEBUG_PASTEBOARD
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 32facaf12b..dbe7353bbe 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -2484,7 +2484,16 @@ bool QTest::compare_helper(bool success, const char *failureMsg,
bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const char *expected,
const char *file, int line)
{
- return compare_helper(qFuzzyCompare(t1, t2), "Compared floats are not the same (fuzzy compare)",
+ bool equal = false;
+ int cl1 = std::fpclassify(t1);
+ int cl2 = std::fpclassify(t2);
+ if (cl1 == FP_INFINITE)
+ equal = ((t1 < 0) == (t2 < 0)) && cl2 == FP_INFINITE;
+ else if (cl1 == FP_NAN)
+ equal = (cl2 == FP_NAN);
+ else
+ equal = qFuzzyCompare(t1, t2);
+ return compare_helper(equal, "Compared floats are not the same (fuzzy compare)",
toString(t1), toString(t2), actual, expected, file, line);
}