diff options
-rw-r--r-- | src/corelib/text/qbytearray.h | 2 | ||||
-rw-r--r-- | tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index 9374843a5b..61f381409f 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -489,7 +489,7 @@ inline qsizetype QByteArray::capacity() const inline void QByteArray::reserve(qsizetype asize) { - if (d->needsDetach() || asize > capacity()) { + if (d->needsDetach() || asize > capacity() - d->freeSpaceAtBegin()) { reallocData(qMax(size_t(size()), size_t(asize)) + 1u, d->detachFlags() | Data::CapacityReserved); } else { d->setFlag(Data::CapacityReserved); diff --git a/tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp b/tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp index b811c63036..e0a261efd0 100644 --- a/tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp +++ b/tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp @@ -344,6 +344,14 @@ void runScenario() QByteArray ba2 = withZero; ba2 += ba2 P withZero; QCOMPARE(ba2, QByteArray(withZero + withZero + withZero)); + + // With space allocated in front, mirroring what happens with QHttpMultiPart in QNAM + QByteArray byteArray; + byteArray.reserve(70); + byteArray.insert(0, "multipart/"); + byteArray.insert(byteArray.size(), "mixed"); + byteArray += "; boundary=\"" P QByteArray(30, 'o') P '"'; + QCOMPARE(byteArray, "multipart/mixed; boundary=\"oooooooooooooooooooooooooooooo\""); } } |