diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2015-02-26 16:07:49 +0200 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2015-03-12 05:33:20 +0000 |
commit | 9dd0bb851b34fcfea5e9be106d8f4209d59d5bf5 (patch) | |
tree | 238e1b1a79919103da6d1d127b8e785767509409 /src/corelib/io | |
parent | 2d5210a684b266e71fc6f7efbd81fbfd720b341c (diff) |
Make QRingBuffer a 64-bit safe
According to I/O API, QIODevice and its inherited classes should be
able to process a full 64-bit offsets and lengths. This requires
64-bit parameters in operations with internal buffers. Rework
QRingBuffer to avoid implicit truncation of numbers and fix some
64-bit issues in code.
Change-Id: Iadd6fd5fefd2d64e6c084e2feebb4dc2d6df66de
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qfiledevice.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qprocess.cpp | 6 | ||||
-rw-r--r-- | src/corelib/io/qwindowspipereader.cpp | 8 | ||||
-rw-r--r-- | src/corelib/io/qwindowspipereader_p.h | 4 |
4 files changed, 10 insertions, 10 deletions
diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp index 3ee0e33573..4c5ed0aef6 100644 --- a/src/corelib/io/qfiledevice.cpp +++ b/src/corelib/io/qfiledevice.cpp @@ -481,7 +481,7 @@ bool QFileDevicePrivate::putCharHelper(char c) #else // Cutoff for code that doesn't only touch the buffer. - int writeBufferSize = writeBuffer.size(); + qint64 writeBufferSize = writeBuffer.size(); if ((openMode & QIODevice::Unbuffered) || writeBufferSize + 1 >= QFILE_WRITEBUFFER_SIZE #ifdef Q_OS_WIN || ((openMode & QIODevice::Text) && c == '\n' && writeBufferSize + 2 >= QFILE_WRITEBUFFER_SIZE) diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 6451bae0ba..d5c861f9ad 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1912,12 +1912,12 @@ qint64 QProcess::readData(char *data, qint64 maxlen) return 1; } - qint64 bytesToRead = qint64(qMin(readBuffer->size(), (int)maxlen)); + qint64 bytesToRead = qMin(readBuffer->size(), maxlen); qint64 readSoFar = 0; while (readSoFar < bytesToRead) { const char *ptr = readBuffer->readPointer(); - int bytesToReadFromThisBlock = qMin<qint64>(bytesToRead - readSoFar, - readBuffer->nextDataBlockSize()); + qint64 bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar, + readBuffer->nextDataBlockSize()); memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock); readSoFar += bytesToReadFromThisBlock; readBuffer->free(bytesToReadFromThisBlock); diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp index ab2025ee5c..1502e5dada 100644 --- a/src/corelib/io/qwindowspipereader.cpp +++ b/src/corelib/io/qwindowspipereader.cpp @@ -45,8 +45,8 @@ QWindowsPipeReader::QWindowsPipeReader(QObject *parent) handle(INVALID_HANDLE_VALUE), readBufferMaxSize(0), actualReadBufferSize(0), - readSequenceStarted(false), emitReadyReadTimer(new QTimer(this)), + readSequenceStarted(false), pipeBroken(false), readyReadEmitted(false) { @@ -133,12 +133,12 @@ qint64 QWindowsPipeReader::read(char *data, qint64 maxlen) actualReadBufferSize--; readSoFar = 1; } else { - qint64 bytesToRead = qMin(qint64(actualReadBufferSize), maxlen); + qint64 bytesToRead = qMin(actualReadBufferSize, maxlen); readSoFar = 0; while (readSoFar < bytesToRead) { const char *ptr = readBuffer.readPointer(); - int bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar, - qint64(readBuffer.nextDataBlockSize())); + qint64 bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar, + readBuffer.nextDataBlockSize()); memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock); readSoFar += bytesToReadFromThisBlock; readBuffer.free(bytesToReadFromThisBlock); diff --git a/src/corelib/io/qwindowspipereader_p.h b/src/corelib/io/qwindowspipereader_p.h index 7904f116cb..53872e2552 100644 --- a/src/corelib/io/qwindowspipereader_p.h +++ b/src/corelib/io/qwindowspipereader_p.h @@ -98,9 +98,9 @@ private: QWinOverlappedIoNotifier *dataReadNotifier; qint64 readBufferMaxSize; QRingBuffer readBuffer; - int actualReadBufferSize; - bool readSequenceStarted; + qint64 actualReadBufferSize; QTimer *emitReadyReadTimer; + bool readSequenceStarted; bool pipeBroken; bool readyReadEmitted; }; |