summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qbuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qbuffer.cpp')
-rw-r--r--src/corelib/io/qbuffer.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp
index c244dacab3..763620692c 100644
--- a/src/corelib/io/qbuffer.cpp
+++ b/src/corelib/io/qbuffer.cpp
@@ -267,16 +267,31 @@ void QBuffer::setData(const QByteArray &data)
}
/*!
- \fn void QBuffer::setData(const char *data, int size)
-
\overload
Sets the contents of the internal buffer to be the first \a size
bytes of \a data.
+
+ \note In Qt versions prior to 6.5, this function took the length as
+ an \c{int} parameter, potentially truncating sizes.
*/
+void QBuffer::setData(const char *data, qsizetype size)
+{
+ Q_D(QBuffer);
+ if (isOpen()) {
+ qWarning("QBuffer::setData: Buffer is open");
+ return;
+ }
+ d->buf->replace(qsizetype(0), d->buf->size(), // ### QByteArray lacks assign(ptr, n)
+ data, size);
+}
/*!
\reimp
+
+ Unlike QFile, opening a QBuffer QIODevice::WriteOnly does not truncate it.
+ However, pos() is set to 0. Use QIODevice::Append or QIODevice::Truncate to
+ change either behavior.
*/
bool QBuffer::open(OpenMode flags)
{
@@ -386,7 +401,7 @@ qint64 QBuffer::writeData(const char *data, qint64 len)
if (required > quint64(d->buf->size())) { // capacity exceeded
// The following must hold, since qsizetype covers half the virtual address space:
- Q_ASSUME(required <= quint64((std::numeric_limits<qsizetype>::max)()));
+ Q_ASSERT(required <= quint64((std::numeric_limits<qsizetype>::max)()));
d->buf->resize(qsizetype(required));
if (quint64(d->buf->size()) != required) { // could not resize
qWarning("QBuffer::writeData: Memory allocation error");