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>bb10
parent
b347d48704
commit
a116b2ddfc
|
|
@ -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(); }
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue