summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-12-06 09:03:30 -0800
committerThiago Macieira <thiago.macieira@intel.com>2023-12-21 11:13:32 -0800
commita116b2ddfc9e91736b1ec4edda6500e9c8f5f301 (patch)
tree8bd237ec5aa389c379bef43f879d1ef8b72ee9d6
parentb347d487048cf36d609dd31952dbef1813b5b0e5 (diff)
QByteArray: allow begin() to return nullptr, like QString
That is, don't call QByteArray::data() because that one is still under QT5_NULL_STRINGS conditional. Instead, like QString, call d.data() directly, which is allowed to return a null pointer. This necessitated a fix to QStringBuilder's QConcatenable because it was iterating from &QByteArray::_empty to nullptr. [ChangeLog][Important Behavior Changes] Calling begin() or end() in a const QByteArray will return a null pointer if isNull() is true. This is the same behavior as QString. This is important for code attempting to iterate from data() to end() instead of begin() to end(). Change-Id: Ica7a43f6147b49c187ccfffd179e4cda75bd1031 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
-rw-r--r--src/corelib/text/qbytearray.h2
-rw-r--r--src/corelib/text/qstringbuilder.h8
2 files changed, 5 insertions, 5 deletions
diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h
index 06d310856b..ad4264036b 100644
--- a/src/corelib/text/qbytearray.h
+++ b/src/corelib/text/qbytearray.h
@@ -476,7 +476,7 @@ public:
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
iterator begin() { return data(); }
- const_iterator begin() const noexcept { return data(); }
+ const_iterator begin() const noexcept { return d.data(); }
const_iterator cbegin() const noexcept { return begin(); }
const_iterator constBegin() const noexcept { return begin(); }
iterator end() { return begin() + size(); }
diff --git a/src/corelib/text/qstringbuilder.h b/src/corelib/text/qstringbuilder.h
index 17160c65b6..dfe9863b74 100644
--- a/src/corelib/text/qstringbuilder.h
+++ b/src/corelib/text/qstringbuilder.h
@@ -374,10 +374,10 @@ template <> struct QConcatenable<QByteArray> : private QAbstractConcatenable
#endif
static inline void appendTo(const QByteArray &ba, char *&out)
{
- const char *a = ba.constData();
- const char * const end = ba.end();
- while (a != end)
- *out++ = *a++;
+ const qsizetype n = ba.size();
+ if (n)
+ memcpy(out, ba.begin(), n);
+ out += n;
}
};