diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index 88101c0b06..8989eb27a6 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -249,9 +249,9 @@ public: QByteArray &append(char c); inline QByteArray &append(qsizetype count, char c); QByteArray &append(const char *s) - { return append(QByteArrayView(s, qsizetype(qstrlen(s)))); } + { return append(s, -1); } QByteArray &append(const char *s, qsizetype len) - { return append(QByteArrayView(s, len)); } + { return append(QByteArrayView(s, len < 0 ? qsizetype(qstrlen(s)) : len)); } QByteArray &append(const QByteArray &a); QByteArray &append(QByteArrayView a) { return insert(size(), a); } diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp index cecd0f1584..ae65b8d27e 100644 --- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp @@ -957,6 +957,7 @@ void tst_QByteArray::append() QCOMPARE(QByteArray().append(2, 'a'), QByteArray("aa")); QCOMPARE(QByteArray().append(QByteArray("data")), QByteArray("data")); QCOMPARE(QByteArray().append(data), QByteArray("data")); + QCOMPARE(QByteArray().append(data, -1), QByteArray("data")); QCOMPARE(QByteArray().append(data, 2), QByteArray("da")); QCOMPARE(QByteArray().append(QByteArrayView(data)), QByteArray("data"));