From 7831b276e610368514087a81396d1ca2425b2e42 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 5 Mar 2019 11:06:55 +0100 Subject: Handle error from MS-Win API in QCollator::compare() CompreString(Ex|) can fail, e.g. if it doesn't like the flags given. Report such failure and treat compared values as equal rather than whichever is first being less. Fixes: QTBUG-74209 Change-Id: If8fa962f9e14ee43cc423a09a67bc58259a24794 Reviewed-by: Thiago Macieira Reviewed-by: Aleix Pol Gonzalez --- src/corelib/tools/qcollator_win.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qcollator_win.cpp b/src/corelib/tools/qcollator_win.cpp index 35142bb8b8..10cfdaa264 100644 --- a/src/corelib/tools/qcollator_win.cpp +++ b/src/corelib/tools/qcollator_win.cpp @@ -72,6 +72,8 @@ void QCollatorPrivate::init() if (caseSensitivity == Qt::CaseInsensitive) collator |= NORM_IGNORECASE; + // WINE does not support SORT_DIGITSASNUMBERS :-( + // (and its std::sort() crashes on bad comparisons, QTBUG-74209) if (numericMode) collator |= SORT_DIGITSASNUMBERS; @@ -98,16 +100,36 @@ int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) con // Returns one of the following values if successful. To maintain the C runtime convention of // comparing strings, the value 2 can be subtracted from a nonzero return value. Then, the // meaning of <0, ==0, and >0 is consistent with the C runtime. + // [...] The function returns 0 if it does not succeed. + // https://docs.microsoft.com/en-us/windows/desktop/api/stringapiset/nf-stringapiset-comparestringex#return-value #ifndef USE_COMPARESTRINGEX - return CompareString(d->localeID, d->collator, - reinterpret_cast(s1), len1, - reinterpret_cast(s2), len2) - 2; + const int ret = CompareString(d->localeID, d->collator, + reinterpret_cast(s1), len1, + reinterpret_cast(s2), len2); #else - return CompareStringEx(LPCWSTR(d->localeName.utf16()), d->collator, - reinterpret_cast(s1), len1, - reinterpret_cast(s2), len2, NULL, NULL, 0) - 2; + const int ret = CompareStringEx(LPCWSTR(d->localeName.utf16()), d->collator, + reinterpret_cast(s1), len1, + reinterpret_cast(s2), len2, + nullptr, nullptr, 0); #endif + if (Q_LIKELY(ret)) + return ret - 2; + + switch (DWORD error = GetLastError()) { + case ERROR_INVALID_FLAGS: + qWarning("Unsupported flags (%d) used in QCollator", int(d->collator)); + break; + case ERROR_INVALID_PARAMETER: + qWarning("Invalid parameter for QCollator::compare()"); + break; + default: + qWarning("Failed (%ld) comparison in QCollator::compare()", long(error)); + break; + } + // We have no idea what to return, so pretend we think they're equal. + // At least that way we'll be consistent if we get the same values swapped ... + return 0; } int QCollator::compare(const QString &str1, const QString &str2) const -- cgit v1.2.3 From 6a86cc612dbcd1983c6bcb50c41832b2a835b937 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 8 Mar 2019 07:27:39 +0100 Subject: Fix a couple of small doc things in relation to QScopeGuard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I6e61a18697b95d9e3f534d1d71ebf32fdff4a04f Reviewed-by: Tor Arne Vestbø Reviewed-by: Frederik Gladhorn --- src/corelib/doc/snippets/code/src_corelib_tools_qscopeguard.cpp | 2 +- src/corelib/tools/qscopeguard.qdoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qscopeguard.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qscopeguard.cpp index c8c5f694c6..2fa4f88011 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qscopeguard.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qscopeguard.cpp @@ -57,7 +57,7 @@ void myComplexCodeWithMultipleReturnPoints(int v) if (v == -1) return; - int v2 = code_that_might_through_exceptions(); + int v2 = code_that_might_throw_exceptions(); if (v2 == -1) return; diff --git a/src/corelib/tools/qscopeguard.qdoc b/src/corelib/tools/qscopeguard.qdoc index 70e13ab2fd..21b0bab9cf 100644 --- a/src/corelib/tools/qscopeguard.qdoc +++ b/src/corelib/tools/qscopeguard.qdoc @@ -33,7 +33,7 @@ QT_BEGIN_NAMESPACE \class QScopeGuard \since 5.12 \inmodule QtCore - \brief Provides a scope guard for calling a function at the of + \brief Provides a scope guard for calling a function at the end of a scope. */ -- cgit v1.2.3 From 3cdf3ae1f0f90cbb20791c69552453f2555d3016 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 7 Mar 2019 22:10:09 -0800 Subject: Fix Coverity warning about mixing enums MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Coverity says: >>> CID 190310: Incorrect expression (MIXED_ENUMS) >>> Mixing enum types "CborType" and "QCborStreamReader::Type" for "type_". Change-Id: Ifbadc62ac2d04a9a8952fffd1589e6e304fc7703 Reviewed-by: Mårten Nordheim Reviewed-by: Edward Welbourne --- src/corelib/serialization/qcborstream.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/serialization/qcborstream.cpp b/src/corelib/serialization/qcborstream.cpp index d7b81ae324..264856b4bf 100644 --- a/src/corelib/serialization/qcborstream.cpp +++ b/src/corelib/serialization/qcborstream.cpp @@ -1934,7 +1934,7 @@ inline void QCborStreamReader::preparse() // for negative integer and we don't have separate types for Boolean, // Null and Undefined). if (type_ == CborBooleanType || type_ == CborNullType || type_ == CborUndefinedType) { - type_ = SimpleType; + type_ = CborSimpleType; value64 = quint8(d->buffer.at(d->bufferStart)) - CborSimpleType; } else { // Using internal TinyCBOR API! -- cgit v1.2.3 From b0f17780dfc20722fba9cb2caa174e79009b058a Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 11 Mar 2019 22:01:17 +0100 Subject: Doc: Unify terminology for '\0'-terminated strings The documentation for QByteArray and QString is using different notations for '\0'-terminated strings. Unify them by using '\0'-terminated everywhere. Change-Id: Ia26ec5c50635bebba1b54b7fe227ff0bcca4f2ad Reviewed-by: Paul Wicking Reviewed-by: Samuel Gaist --- src/corelib/tools/qbytearray.cpp | 19 ++++++++++--------- src/corelib/tools/qstring.cpp | 26 +++++++++++--------------- 2 files changed, 21 insertions(+), 24 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 64674ddc00..0f27071176 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -523,7 +523,7 @@ int qstrnicmp(const char *str1, const char *str2, uint len) A helper for QByteArray::compare. Compares \a len1 bytes from \a str1 to \a len2 bytes from \a str2. If \a len2 is -1, then \a str2 is expected to be - null-terminated. + '\\0'-terminated. */ int qstrnicmp(const char *str1, qsizetype len1, const char *str2, qsizetype len2) { @@ -1765,9 +1765,10 @@ void QByteArray::chop(int n) If \a data is 0, a null byte array is constructed. - If \a size is negative, \a data is assumed to point to a nul-terminated - string and its length is determined dynamically. The terminating - nul-character is not considered part of the byte array. + If \a size is negative, \a data is assumed to point to a + '\\0'-terminated string and its length is determined dynamically. + The terminating \\0 character is not considered part of the + byte array. QByteArray makes a deep copy of the string data. @@ -1924,7 +1925,7 @@ void QByteArray::expand(int i) /*! \internal - Return a QByteArray that is sure to be NUL-terminated. + Return a QByteArray that is sure to be '\\0'-terminated. By default, all QByteArray have an extra NUL at the end, guaranteeing that assumption. However, if QByteArray::fromRawData @@ -2336,8 +2337,8 @@ QByteArray &QByteArray::replace(int pos, int len, const QByteArray &after) \overload - Replaces \a len bytes from index position \a pos with the zero terminated - string \a after. + Replaces \a len bytes from index position \a pos with the + '\\0'-terminated string \a after. Notice: this can change the length of the byte array. */ @@ -2415,7 +2416,7 @@ QByteArray &QByteArray::replace(const char *c, const QByteArray &after) Replaces every occurrence of the string \a before with the string \a after. Since the sizes of the strings are given by \a bsize and \a asize, they - may contain zero characters and do not need to be zero-terminated. + may contain zero characters and do not need to be '\\0'-terminated. */ QByteArray &QByteArray::replace(const char *before, int bsize, const char *after, int asize) @@ -4541,7 +4542,7 @@ QByteArray QByteArray::number(double n, char f, int prec) \snippet code/src_corelib_tools_qbytearray.cpp 43 \warning A byte array created with fromRawData() is \e not - null-terminated, unless the raw data contains a 0 character at + '\\0'-terminated, unless the raw data contains a 0 character at position \a size. While that does not matter for QDataStream or functions like indexOf(), passing the byte array to a function accepting a \c{const char *} expected to be '\\0'-terminated will diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 1f6fa89136..9d6e0cbdd8 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1468,7 +1468,7 @@ const QString::Null QString::null = { }; In all of the QString functions that take \c{const char *} parameters, the \c{const char *} is interpreted as a classic C-style '\\0'-terminated string encoded in UTF-8. It is legal for - the \c{const char *} parameter to be 0. + the \c{const char *} parameter to be \nullptr. You can also provide string data as an array of \l{QChar}s: @@ -2041,7 +2041,7 @@ const QString::Null QString::null = { }; the size of wchar. If wchar is 4 bytes, the \a string is interpreted as UCS-4, if wchar is 2 bytes it is interpreted as UTF-16. - If \a size is -1 (default), the \a string has to be 0 terminated. + If \a size is -1 (default), the \a string has to be \\0'-terminated. \sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdWString() */ @@ -2107,7 +2107,7 @@ int QString::toUcs4_helper(const ushort *uc, int length, uint *out) If \a unicode is 0, a null string is constructed. - If \a size is negative, \a unicode is assumed to point to a nul-terminated + If \a size is negative, \a unicode is assumed to point to a \\0'-terminated array and its length is determined dynamically. The terminating nul-character is not considered part of the string. @@ -5448,7 +5448,7 @@ static QVector qt_convert_to_ucs4(QStringView string); this string is replaced by the Unicode's replacement character (QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}). - The returned vector is not NUL terminated. + The returned vector is not \\0'-terminated. \sa fromUtf8(), toUtf8(), toLatin1(), toLocal8Bit(), QTextCodec, fromUcs4(), toWCharArray() */ @@ -5480,7 +5480,7 @@ static QVector qt_convert_to_ucs4(QStringView string) this string is replaced by the Unicode's replacement character (QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}). - The returned vector is not NUL terminated. + The returned vector is not \\0'-terminated. \sa QString::toUcs4(), QStringView::toUcs4(), QtPrivate::convertToLatin1(), QtPrivate::convertToLocal8Bit(), QtPrivate::convertToUtf8() @@ -5638,8 +5638,7 @@ QString QString::fromUtf8_helper(const char *str, int size) Returns a QString initialized with the first \a size characters of the Unicode string \a unicode (ISO-10646-UTF-16 encoded). - If \a size is -1 (default), \a unicode must be terminated - with a 0. + If \a size is -1 (default), \a unicode must be \\0'-terminated. This function checks for a Byte Order Mark (BOM). If it is missing, host byte order is assumed. @@ -5670,8 +5669,7 @@ QString QString::fromUtf16(const ushort *unicode, int size) Returns a QString initialized with the first \a size characters of the Unicode string \a str (ISO-10646-UTF-16 encoded). - If \a size is -1 (default), \a str must be terminated - with a 0. + If \a size is -1 (default), \a str must be \\0'-terminated. This function checks for a Byte Order Mark (BOM). If it is missing, host byte order is assumed. @@ -5691,8 +5689,7 @@ QString QString::fromUtf16(const ushort *unicode, int size) Returns a QString initialized with the first \a size characters of the Unicode string \a str (ISO-10646-UCS-4 encoded). - If \a size is -1 (default), \a str must be terminated - with a 0. + If \a size is -1 (default), \a str must be \\0'-terminated. \sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray(), fromStdU32String() */ @@ -5703,8 +5700,7 @@ QString QString::fromUtf16(const ushort *unicode, int size) Returns a QString initialized with the first \a size characters of the Unicode string \a unicode (ISO-10646-UCS-4 encoded). - If \a size is -1 (default), \a unicode must be terminated - with a 0. + If \a size is -1 (default), \a unicode must be \\0'-terminated. \sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray(), fromStdU32String() */ @@ -10354,7 +10350,7 @@ ownership of it, no memory is freed when instances are destroyed. Returns a Unicode representation of the string reference. Since the data stems directly from the referenced string, it is not - null-terminated unless the string reference includes the string's + \\0'-terminated unless the string reference includes the string's null terminator. \sa string() @@ -11896,7 +11892,7 @@ QByteArray QStringRef::toUtf8() const this string is replaced by the Unicode's replacement character (QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}). - The returned vector is not NUL terminated. + The returned vector is not \\0'-terminated. \sa toUtf8(), toLatin1(), toLocal8Bit(), QTextCodec */ -- cgit v1.2.3 From fed9fa171496fd24b264ef66e3e517d988fa3105 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 11 Mar 2019 22:00:27 +0100 Subject: Doc: replace 0 with \nullptr in documentation Replace some more 0 with \nullptr. Change-Id: I2af91bf3712eef5161b11da0c44614bc039ade03 Reviewed-by: Paul Wicking --- src/corelib/codecs/qtextcodec.cpp | 4 ++-- src/corelib/kernel/qobject.cpp | 16 ++++++++-------- src/corelib/plugin/qlibrary.cpp | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 804e0b2935..e2598b7858 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -764,7 +764,7 @@ QList QTextCodec::aliases() const encoding of the subclass to Unicode, and returns the result in a QString. - \a state can be 0, in which case the conversion is stateless and + \a state can be \nullptr, in which case the conversion is stateless and default conversion rules should be used. If state is not 0, the codec should save the state after the conversion in \a state, and adjust the \c remainingChars and \c invalidChars members of the struct. @@ -780,7 +780,7 @@ QList QTextCodec::aliases() const from Unicode to the encoding of the subclass, and returns the result in a QByteArray. - \a state can be 0 in which case the conversion is stateless and + \a state can be \nullptr in which case the conversion is stateless and default conversion rules should be used. If state is not 0, the codec should save the state after the conversion in \a state, and adjust the \c remainingChars and \c invalidChars members of the struct. diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 3a3eb726fa..15955e1665 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -2934,8 +2934,8 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho 0 may be used as a wildcard, meaning "any signal", "any receiving object", or "any slot in the receiving object", respectively. - The \a sender may never be 0. (You cannot disconnect signals from - more than one object in a single call.) + The \a sender may never be \nullptr. (You cannot disconnect signals + from more than one object in a single call.) If \a signal is 0, it disconnects \a receiver and \a method from any signal. If not, only the specified signal is disconnected. @@ -2946,8 +2946,8 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho If \a method is 0, it disconnects anything that is connected to \a receiver. If not, only slots named \a method will be disconnected, - and all other slots are left alone. The \a method must be 0 if \a - receiver is left out, so you cannot disconnect a + and all other slots are left alone. The \a method must be \nullptr + if \a receiver is left out, so you cannot disconnect a specifically-named slot on all objects. \sa connect() @@ -4991,8 +4991,8 @@ bool QObject::disconnect(const QMetaObject::Connection &connection) 0 may be used as a wildcard, meaning "any signal", "any receiving object", or "any slot in the receiving object", respectively. - The \a sender may never be 0. (You cannot disconnect signals from - more than one object in a single call.) + The \a sender may never be \nullptr. (You cannot disconnect signals + from more than one object in a single call.) If \a signal is 0, it disconnects \a receiver and \a method from any signal. If not, only the specified signal is disconnected. @@ -5003,8 +5003,8 @@ bool QObject::disconnect(const QMetaObject::Connection &connection) If \a method is 0, it disconnects anything that is connected to \a receiver. If not, only slots named \a method will be disconnected, - and all other slots are left alone. The \a method must be 0 if \a - receiver is left out, so you cannot disconnect a + and all other slots are left alone. The \a method must be \nullptr + if \a receiver is left out, so you cannot disconnect a specifically-named slot on all objects. \note It is not possible to use this overload to diconnect signals diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index aa63ed1a6b..6635286f76 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -133,8 +133,8 @@ QT_BEGIN_NAMESPACE The following code snippet loads a library, resolves the symbol "mysymbol", and calls the function if everything succeeded. If something goes wrong, e.g. the library file does not exist or the - symbol is not defined, the function pointer will be 0 and won't be - called. + symbol is not defined, the function pointer will be \nullptr and + won't be called. \snippet code/src_corelib_plugin_qlibrary.cpp 0 -- cgit v1.2.3