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.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp
index 595fcd2724..8771ac3764 100644
--- a/src/corelib/io/qbuffer.cpp
+++ b/src/corelib/io/qbuffer.cpp
@@ -41,6 +41,8 @@
#include <QtCore/qmetaobject.h>
#include "private/qiodevice_p.h"
+#include <limits>
+
QT_BEGIN_NAMESPACE
/** QBufferPrivate **/
@@ -212,7 +214,7 @@ QBuffer::~QBuffer()
}
/*!
- Makes QBuffer uses the QByteArray pointed to by \a
+ Makes QBuffer use the QByteArray pointed to by \a
byteArray as its internal buffer. The caller is responsible for
ensuring that \a byteArray remains valid until the QBuffer is
destroyed, or until setBuffer() is called to change the buffer.
@@ -317,6 +319,10 @@ void QBuffer::setData(const QByteArray &data)
/*!
\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)
{
@@ -366,7 +372,9 @@ qint64 QBuffer::size() const
bool QBuffer::seek(qint64 pos)
{
Q_D(QBuffer);
- if (pos > d->buf->size() && isWritable()) {
+ const auto oldBufSize = d->buf->size();
+ constexpr qint64 MaxSeekPos = (std::numeric_limits<decltype(oldBufSize)>::max)();
+ if (pos <= MaxSeekPos && pos > oldBufSize && isWritable()) {
if (seek(d->buf->size())) {
const qint64 gapSize = pos - d->buf->size();
if (write(QByteArray(gapSize, 0)) != gapSize) {
@@ -377,7 +385,7 @@ bool QBuffer::seek(qint64 pos)
return false;
}
} else if (pos > d->buf->size() || pos < 0) {
- qWarning("QBuffer::seek: Invalid pos: %d", int(pos));
+ qWarning("QBuffer::seek: Invalid pos: %lld", pos);
return false;
}
return QIODevice::seek(pos);