diff options
Diffstat (limited to 'src/corelib/io/qiodevice.cpp')
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 53019e1ff4..89209e6118 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtCore module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -217,7 +209,7 @@ QIODevicePrivate::~QIODevicePrivate() \li waitFor....() - Subclasses of QIODevice implement blocking functions for device-specific operations. For example, QProcess - has a function called waitForStarted() which suspends operation in + has a function called \l {QProcess::}{waitForStarted()} which suspends operation in the calling thread until the process has started. \endlist @@ -730,8 +722,7 @@ qint64 QIODevice::bytesAvailable() const return d->buffer.size(); } -/*! - For buffered devices, this function returns the number of bytes +/*! For buffered devices, this function returns the number of bytes waiting to be written. For devices with no buffer, this function returns 0. @@ -833,7 +824,7 @@ qint64 QIODevice::read(char *data, qint64 maxSize) // In buffered mode, we try to fill up the QIODevice buffer before // we do anything else. // buffer is empty at this point, try to fill it - int bytesToBuffer = QIODEVICE_BUFFERSIZE; + const int bytesToBuffer = QIODEVICE_BUFFERSIZE; char *writePointer = d->buffer.reserve(bytesToBuffer); // Make sure the device is positioned correctly. @@ -943,9 +934,10 @@ qint64 QIODevice::read(char *data, qint64 maxSize) data read as a QByteArray. This function has no way of reporting errors; returning an empty - QByteArray() can mean either that no data was currently available + QByteArray can mean either that no data was currently available for reading, or that an error occurred. */ + QByteArray QIODevice::read(qint64 maxSize) { Q_D(QIODevice); @@ -994,10 +986,10 @@ QByteArray QIODevice::read(qint64 maxSize) \overload Reads all available data from the device, and returns it as a - QByteArray. + byte array. This function has no way of reporting errors; returning an empty - QByteArray() can mean either that no data was currently available + QByteArray can mean either that no data was currently available for reading, or that an error occurred. */ QByteArray QIODevice::readAll() @@ -1013,6 +1005,8 @@ QByteArray QIODevice::readAll() // flush internal read buffer if (!(d->openMode & Text) && !d->buffer.isEmpty()) { + if (d->buffer.size() >= INT_MAX) + return QByteArray(); result = d->buffer.readAll(); readBytes = result.size(); d->pos += readBytes; @@ -1031,6 +1025,8 @@ QByteArray QIODevice::readAll() } else { // Read it all in one go. // If resize fails, don't read anything. + if (readBytes + theSize - d->pos > INT_MAX) + return QByteArray(); result.resize(int(readBytes + theSize - d->pos)); readBytes += read(result.data() + readBytes, result.size() - readBytes); } @@ -1173,10 +1169,10 @@ qint64 QIODevice::readLine(char *data, qint64 maxSize) \overload Reads a line from the device, but no more than \a maxSize characters, - and returns the result as a QByteArray. + and returns the result as a byte array. This function has no way of reporting errors; returning an empty - QByteArray() can mean either that no data was currently available + QByteArray can mean either that no data was currently available for reading, or that an error occurred. */ QByteArray QIODevice::readLine(qint64 maxSize) @@ -1527,7 +1523,7 @@ qint64 QIODevice::peek(char *data, qint64 maxSize) \snippet code/src_corelib_io_qiodevice.cpp 5 This function has no way of reporting errors; returning an empty - QByteArray() can mean either that no data was currently available + QByteArray can mean either that no data was currently available for peeking, or that an error occurred. \sa read() |