summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qdatastream.cpp1
-rw-r--r--src/corelib/io/qdatastream.h5
-rw-r--r--src/corelib/io/qfileselector.cpp2
-rw-r--r--src/corelib/io/qiodevice.cpp167
-rw-r--r--src/corelib/io/qresource.cpp16
-rw-r--r--src/corelib/io/qstorageinfo_p.h6
-rw-r--r--src/corelib/io/qstorageinfo_unix.cpp4
-rw-r--r--src/corelib/io/qstorageinfo_win.cpp8
-rw-r--r--src/corelib/io/qtemporaryfile.cpp1
-rw-r--r--src/corelib/io/qtextstream.cpp30
-rw-r--r--src/corelib/io/qtextstream_p.h2
11 files changed, 131 insertions, 111 deletions
diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp
index beaafe4762..60f04ce4f1 100644
--- a/src/corelib/io/qdatastream.cpp
+++ b/src/corelib/io/qdatastream.cpp
@@ -525,6 +525,7 @@ void QDataStream::setByteOrder(ByteOrder bo)
\value Qt_5_2 Version 15 (Qt 5.2)
\value Qt_5_3 Same as Qt_5_2
\value Qt_5_4 Version 16 (Qt 5.4)
+ \value Qt_5_5 Same as Qt_5_4
\omitvalue Qt_DefaultCompiledVersion
\sa setVersion(), version()
diff --git a/src/corelib/io/qdatastream.h b/src/corelib/io/qdatastream.h
index 75ffa11543..8e1d777011 100644
--- a/src/corelib/io/qdatastream.h
+++ b/src/corelib/io/qdatastream.h
@@ -82,10 +82,11 @@ public:
Qt_5_2 = 15,
Qt_5_3 = Qt_5_2,
Qt_5_4 = 16,
-#if QT_VERSION >= 0x050500
+ Qt_5_5 = Qt_5_4,
+#if QT_VERSION >= 0x050600
#error Add the datastream version for this Qt version and update Qt_DefaultCompiledVersion
#endif
- Qt_DefaultCompiledVersion = Qt_5_4
+ Qt_DefaultCompiledVersion = Qt_5_5
};
enum ByteOrder {
diff --git a/src/corelib/io/qfileselector.cpp b/src/corelib/io/qfileselector.cpp
index 5d1d5dfe23..95fa970b2d 100644
--- a/src/corelib/io/qfileselector.cpp
+++ b/src/corelib/io/qfileselector.cpp
@@ -335,7 +335,7 @@ void QFileSelectorPrivate::updateSelectors()
if (envSelectors.count())
sharedData->staticSelectors << envSelectors;
- if (!qgetenv(env_override).isEmpty())
+ if (!qEnvironmentVariableIsEmpty(env_override))
return;
sharedData->staticSelectors << sharedData->preloadedStatics; //Potential for static selectors from other modules
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index 0709a93bad..36f88f2774 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -783,27 +783,20 @@ qint64 QIODevice::read(char *data, qint64 maxSize)
CHECK_MAXLEN(read, qint64(-1));
qint64 readSoFar = 0;
- bool moreToRead = true;
- do {
+ bool madeBufferReadsOnly = true;
+ bool deviceAtEof = false;
+ char *readPtr = data;
+ forever {
// Try reading from the buffer.
- qint64 lastReadChunkSize = d->buffer.read(data, maxSize);
- if (lastReadChunkSize > 0) {
- *d->pPos += lastReadChunkSize;
- readSoFar += lastReadChunkSize;
- // fast exit when satisfied by buffer
- if (lastReadChunkSize == maxSize && !(d->openMode & Text)) {
- if (d->buffer.isEmpty()) {
- d->buffer.clear();
- readData(data, 0);
- }
- return readSoFar;
- }
-
- data += lastReadChunkSize;
- maxSize -= lastReadChunkSize;
+ qint64 bufferReadChunkSize = d->buffer.read(data, maxSize);
+ if (bufferReadChunkSize > 0) {
+ *d->pPos += bufferReadChunkSize;
+ readSoFar += bufferReadChunkSize;
+ data += bufferReadChunkSize;
+ maxSize -= bufferReadChunkSize;
#if defined QIODEVICE_DEBUG
- printf("%p \treading %d bytes from buffer into position %d\n", this, lastReadChunkSize,
- int(readSoFar) - lastReadChunkSize);
+ printf("%p \treading %d bytes from buffer into position %d\n", this,
+ bufferReadChunkSize, int(readSoFar) - bufferReadChunkSize);
#endif
} else {
if (d->firstRead) {
@@ -816,100 +809,84 @@ qint64 QIODevice::read(char *data, qint64 maxSize)
d->pDevicePos = &d->seqDumpPos;
}
}
+ }
- if (!maxSize)
- return readSoFar;
-
- if ((d->openMode & Unbuffered) == 0 && maxSize < QIODEVICE_BUFFERSIZE) {
- // 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
- const int bytesToBuffer = QIODEVICE_BUFFERSIZE;
- char *writePointer = d->buffer.reserve(bytesToBuffer);
-
- // Make sure the device is positioned correctly.
- if (d->pos != d->devicePos && !d->isSequential() && !seek(d->pos))
- return readSoFar ? readSoFar : qint64(-1);
- qint64 readFromDevice = readData(writePointer, bytesToBuffer);
- d->buffer.chop(bytesToBuffer - (readFromDevice < 0 ? 0 : int(readFromDevice)));
-
- if (readFromDevice > 0) {
- *d->pDevicePos += readFromDevice;
+ if (maxSize > 0 && !deviceAtEof) {
+ qint64 readFromDevice = 0;
+ // Make sure the device is positioned correctly.
+ if (d->pos == d->devicePos || d->isSequential() || seek(d->pos)) {
+ madeBufferReadsOnly = false; // fix readData attempt
+ if (maxSize >= QIODEVICE_BUFFERSIZE || (d->openMode & Unbuffered)) {
+ // Read big chunk directly to output buffer
+ readFromDevice = readData(data, maxSize);
+ deviceAtEof = (readFromDevice != maxSize);
#if defined QIODEVICE_DEBUG
- printf("%p \treading %d from device into buffer\n", this, int(readFromDevice));
+ printf("%p \treading %d bytes from device (total %d)\n", this,
+ int(readFromDevice), int(readSoFar));
#endif
-
- if (!d->buffer.isEmpty()) {
- lastReadChunkSize = d->buffer.read(data, maxSize);
- readSoFar += lastReadChunkSize;
- data += lastReadChunkSize;
- maxSize -= lastReadChunkSize;
- *d->pPos += lastReadChunkSize;
+ if (readFromDevice > 0) {
+ readSoFar += readFromDevice;
+ data += readFromDevice;
+ maxSize -= readFromDevice;
+ *d->pPos += readFromDevice;
+ *d->pDevicePos += readFromDevice;
+ }
+ } else {
+ const int bytesToBuffer = QIODEVICE_BUFFERSIZE;
+ // Try to fill QIODevice buffer by single read
+ readFromDevice = readData(d->buffer.reserve(bytesToBuffer), bytesToBuffer);
+ deviceAtEof = (readFromDevice != bytesToBuffer);
+ d->buffer.chop(bytesToBuffer - qMax(0, int(readFromDevice)));
+ if (readFromDevice > 0) {
+ *d->pDevicePos += readFromDevice;
#if defined QIODEVICE_DEBUG
- printf("%p \treading %d bytes from buffer at position %d\n", this,
- lastReadChunkSize, int(readSoFar));
+ printf("%p \treading %d from device into buffer\n", this,
+ int(readFromDevice));
#endif
+ continue;
}
}
+ } else {
+ readFromDevice = -1;
}
- }
- // If we need more, try reading from the device.
- if (maxSize > 0) {
- // Make sure the device is positioned correctly.
- if (d->pos != d->devicePos && !d->isSequential() && !seek(d->pos))
- return readSoFar ? readSoFar : qint64(-1);
- qint64 readFromDevice = readData(data, maxSize);
-#if defined QIODEVICE_DEBUG
- printf("%p \treading %d bytes from device (total %d)\n", this, int(readFromDevice), int(readSoFar));
-#endif
- if (readFromDevice == -1 && readSoFar == 0) {
+ if (readFromDevice < 0 && readSoFar == 0) {
// error and we haven't read anything: return immediately
- return -1;
- }
- if (readFromDevice > 0) {
- lastReadChunkSize += int(readFromDevice);
- readSoFar += readFromDevice;
- data += readFromDevice;
- maxSize -= readFromDevice;
- *d->pPos += readFromDevice;
- *d->pDevicePos += readFromDevice;
+ return qint64(-1);
}
}
- // Best attempt has been made to read data, don't try again except for text mode adjustment below
- moreToRead = false;
- if (readSoFar && d->openMode & Text) {
- char *readPtr = data - lastReadChunkSize;
+ if ((d->openMode & Text) && readPtr < data) {
const char *endPtr = data;
- if (readPtr < endPtr) {
- // optimization to avoid initial self-assignment
- while (*readPtr != '\r') {
- if (++readPtr == endPtr)
- return readSoFar;
- }
+ // optimization to avoid initial self-assignment
+ while (*readPtr != '\r') {
+ if (++readPtr == endPtr)
+ break;
+ }
- char *writePtr = readPtr;
+ char *writePtr = readPtr;
- while (readPtr < endPtr) {
- char ch = *readPtr++;
- if (ch != '\r')
- *writePtr++ = ch;
- else {
- --readSoFar;
- --data;
- ++maxSize;
- }
+ while (readPtr < endPtr) {
+ char ch = *readPtr++;
+ if (ch != '\r')
+ *writePtr++ = ch;
+ else {
+ --readSoFar;
+ --data;
+ ++maxSize;
}
-
- // Make sure we get more data if there is room for more. This
- // is very important for when someone seeks to the start of a
- // '\r\n' and reads one character - they should get the '\n'.
- moreToRead = (readPtr != writePtr);
}
+
+ // Make sure we get more data if there is room for more. This
+ // is very important for when someone seeks to the start of a
+ // '\r\n' and reads one character - they should get the '\n'.
+ readPtr = data;
+ continue;
}
- } while (moreToRead);
+
+ break;
+ }
#if defined QIODEVICE_DEBUG
printf("%p \treturning %d, d->pos == %d, d->buffer.size() == %d\n", this,
@@ -917,8 +894,10 @@ qint64 QIODevice::read(char *data, qint64 maxSize)
debugBinaryString(data - readSoFar, readSoFar);
#endif
- if (d->buffer.isEmpty())
+ if (madeBufferReadsOnly && d->buffer.isEmpty()) {
+ d->buffer.clear();
readData(data, 0);
+ }
return readSoFar;
}
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp
index ed6bfb4e0d..9eca0ab8dc 100644
--- a/src/corelib/io/qresource.cpp
+++ b/src/corelib/io/qresource.cpp
@@ -876,7 +876,13 @@ public:
virtual QString mappingRoot() const { return root; }
virtual ResourceRootType type() const { return Resource_Buffer; }
- bool registerSelf(const uchar *b) {
+ // size == -1 means "unknown"
+ bool registerSelf(const uchar *b, int size)
+ {
+ // 5 int "pointers"
+ if (size >= 0 && size < 20)
+ return false;
+
//setup the data now
int offset = 0;
@@ -903,6 +909,10 @@ public:
(b[offset+2] << 8) + (b[offset+3] << 0);
offset += 4;
+ // Some sanity checking for sizes. This is _not_ a security measure.
+ if (size >= 0 && (tree_offset >= size || data_offset >= size || name_offset >= size))
+ return false;
+
if(version == 0x01) {
buffer = b;
setSource(b+tree_offset, b+name_offset, b+data_offset);
@@ -1009,7 +1019,7 @@ public:
}
fromMM = false;
}
- if(data && QDynamicBufferResourceRoot::registerSelf(data)) {
+ if (data && QDynamicBufferResourceRoot::registerSelf(data, data_len)) {
if(fromMM) {
unmapPointer = data;
unmapLength = data_len;
@@ -1124,7 +1134,7 @@ QResource::registerResource(const uchar *rccData, const QString &resourceRoot)
}
QDynamicBufferResourceRoot *root = new QDynamicBufferResourceRoot(r);
- if(root->registerSelf(rccData)) {
+ if (root->registerSelf(rccData, -1)) {
root->ref.ref();
QMutexLocker lock(resourceMutex());
resourceList()->append(root);
diff --git a/src/corelib/io/qstorageinfo_p.h b/src/corelib/io/qstorageinfo_p.h
index 9c8e51f475..dea25d440d 100644
--- a/src/corelib/io/qstorageinfo_p.h
+++ b/src/corelib/io/qstorageinfo_p.h
@@ -73,14 +73,14 @@ public:
protected:
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
- void retreiveVolumeInfo();
- void retreiveDiskFreeSpace();
+ void retrieveVolumeInfo();
+ void retrieveDiskFreeSpace();
#elif defined(Q_OS_MAC)
void retrievePosixInfo();
void retrieveUrlProperties(bool initRootPath = false);
void retrieveLabel();
#elif defined(Q_OS_UNIX)
- void retreiveVolumeInfo();
+ void retrieveVolumeInfo();
#endif
public:
diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp
index e82737c51c..bec7420dc7 100644
--- a/src/corelib/io/qstorageinfo_unix.cpp
+++ b/src/corelib/io/qstorageinfo_unix.cpp
@@ -401,11 +401,11 @@ void QStorageInfoPrivate::doStat()
if (rootPath.isEmpty())
return;
- retreiveVolumeInfo();
+ retrieveVolumeInfo();
name = retrieveLabel(device);
}
-void QStorageInfoPrivate::retreiveVolumeInfo()
+void QStorageInfoPrivate::retrieveVolumeInfo()
{
QT_STATFSBUF statfs_buf;
int result;
diff --git a/src/corelib/io/qstorageinfo_win.cpp b/src/corelib/io/qstorageinfo_win.cpp
index 8c276b2798..51a268f58c 100644
--- a/src/corelib/io/qstorageinfo_win.cpp
+++ b/src/corelib/io/qstorageinfo_win.cpp
@@ -114,12 +114,12 @@ void QStorageInfoPrivate::doStat()
if (rootPath.isEmpty())
return;
- retreiveVolumeInfo();
+ retrieveVolumeInfo();
device = getDevice(rootPath);
- retreiveDiskFreeSpace();
+ retrieveDiskFreeSpace();
}
-void QStorageInfoPrivate::retreiveVolumeInfo()
+void QStorageInfoPrivate::retrieveVolumeInfo()
{
const UINT oldmode = ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
@@ -151,7 +151,7 @@ void QStorageInfoPrivate::retreiveVolumeInfo()
::SetErrorMode(oldmode);
}
-void QStorageInfoPrivate::retreiveDiskFreeSpace()
+void QStorageInfoPrivate::retrieveDiskFreeSpace()
{
const UINT oldmode = ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 4a9aafcf0b..c96d0504f4 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -222,6 +222,7 @@ static bool createFileFromTemplate(NativeFileHandle &file,
}
Q_ASSERT(false);
+ return false;
}
//************* QTemporaryFileEngine
diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp
index 66727e7dc4..6cbe91fab2 100644
--- a/src/corelib/io/qtextstream.cpp
+++ b/src/corelib/io/qtextstream.cpp
@@ -827,6 +827,21 @@ inline void QTextStreamPrivate::write(const QString &data)
/*!
\internal
*/
+inline void QTextStreamPrivate::write(QChar ch)
+{
+ if (string) {
+ // ### What about seek()??
+ string->append(ch);
+ } else {
+ writeBuffer += ch;
+ if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
+ flushWriteBuffer();
+ }
+}
+
+/*!
+ \internal
+*/
inline bool QTextStreamPrivate::getChar(QChar *ch)
{
if ((string && stringOffset == string->size())
@@ -865,6 +880,17 @@ inline void QTextStreamPrivate::ungetChar(QChar ch)
/*!
\internal
*/
+inline void QTextStreamPrivate::putChar(QChar ch)
+{
+ if (params.fieldWidth > 0)
+ putString(QString(ch));
+ else
+ write(ch);
+}
+
+/*!
+ \internal
+*/
inline void QTextStreamPrivate::putString(const QString &s, bool number)
{
QString tmp = s;
@@ -2232,7 +2258,7 @@ QTextStream &QTextStream::operator<<(QChar c)
{
Q_D(QTextStream);
CHECK_VALID_STREAM(*this);
- d->putString(QString(c));
+ d->putChar(c);
return *this;
}
@@ -2245,7 +2271,7 @@ QTextStream &QTextStream::operator<<(char c)
{
Q_D(QTextStream);
CHECK_VALID_STREAM(*this);
- d->putString(QString(QChar::fromLatin1(c)));
+ d->putChar(QChar::fromLatin1(c));
return *this;
}
diff --git a/src/corelib/io/qtextstream_p.h b/src/corelib/io/qtextstream_p.h
index 5f99f44cc2..b7281e42ad 100644
--- a/src/corelib/io/qtextstream_p.h
+++ b/src/corelib/io/qtextstream_p.h
@@ -166,7 +166,9 @@ public:
bool getReal(double *f);
inline void write(const QString &data);
+ inline void write(QChar ch);
inline void putString(const QString &ch, bool number = false);
+ inline void putChar(QChar ch);
void putNumber(qulonglong number, bool negative);
// buffers