summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2021-10-12 09:42:23 -0700
committerOswald Buddenhagen <oswald.buddenhagen@gmx.de>2021-10-22 04:30:53 +0000
commitf9139b19bff2f1bc5cbc937c779a5e584dcdafc7 (patch)
tree52129de3e774fabded166c999bf28250ab738e39 /src
parent5bc315fbe204de6e629896e19d7297bcb8c01802 (diff)
QLatin1String: harmonize null byte handling with the rest of QString
After the introduction of QByteArrayView, all the QString::fromXxx overloads and the constructor will include the null bytes inside QByteArrays and so will QLatin1Strings created from QByteArrayViews. This was the lone stand-out that wasn't fixed in 6.0, so do it now. [ChangeLog][Important Behavior Changes] Since Qt 6.0, all QString and QLatin1String methods consuming QByteArray and QByteArrayView objects will include any embedded null bytes and treat them as U+0000 Unicode characters, whereas in Qt 4.x and 5.x, they would stop at the first null byte like bare C strings. Qt 6.3 contains a fix for a couple of the methods that mistakenly persisted the old behavior in 6.0-6.2, namely the QLatin1String constructor from QByteArray and the equality and inequality operators between QByteArray and QString. Task-number: QTBUG-97451 Change-Id: Icb2516126f674e7b8bb3fffd16ad5621cf3e64ec Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qstring.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index b6060530fb..5229c030e2 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -88,7 +88,7 @@ public:
constexpr explicit QLatin1String(const char *f, const char *l)
: QLatin1String(f, qsizetype(l - f)) {}
constexpr inline explicit QLatin1String(const char *s, qsizetype sz) noexcept : m_size(sz), m_data(s) {}
- explicit QLatin1String(const QByteArray &s) noexcept : m_size(qsizetype(qstrnlen(s.constData(), s.size()))), m_data(s.constData()) {}
+ explicit QLatin1String(const QByteArray &s) noexcept : m_size(s.size()), m_data(s.constData()) {}
constexpr explicit QLatin1String(QByteArrayView s) noexcept : m_size(s.size()), m_data(s.data()) {}
inline QString toString() const;
@@ -1424,9 +1424,9 @@ QT_ASCII_CAST_WARN inline bool QString::operator>=(const QByteArray &s) const
{ return QString::compare_helper(constData(), size(), s.constData(), s.size()) >= 0; }
inline bool QByteArray::operator==(const QString &s) const
-{ return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) == 0; }
+{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) == 0; }
inline bool QByteArray::operator!=(const QString &s) const
-{ return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) != 0; }
+{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) != 0; }
inline bool QByteArray::operator<(const QString &s) const
{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) > 0; }
inline bool QByteArray::operator>(const QString &s) const