diff options
Diffstat (limited to 'src/corelib/io/qbuffer.cpp')
-rw-r--r-- | src/corelib/io/qbuffer.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp index c244dacab3..4e513bc7cf 100644 --- a/src/corelib/io/qbuffer.cpp +++ b/src/corelib/io/qbuffer.cpp @@ -267,16 +267,30 @@ 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->assign(data, 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 +400,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"); |