summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qiodevice_p.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-09-19 14:17:46 -0700
committerThiago Macieira <thiago.macieira@intel.com>2014-10-31 03:56:11 +0100
commit85da1625e47cadf0b41e24863e8988e771e50943 (patch)
tree892b2a86a0951e4521c6c3fd4a311005d0baf127 /src/corelib/io/qiodevice_p.h
parentf91b81ca398c64a22fd6fb2006dbec39a3e3b2c0 (diff)
Attempt to make QFile I/O 64-bit safe
Use qint64 wherever possible. The linear buffer is never requested to allocate that much memory (always limited), but at least we ensure we're not dropping bits where we shouldn't. Windows's POSIX compatibility layer is never largefile enabled, so it is always necessary to chunk large reads and writes. On Unix, this will be rare, unless someone passed -no-largefile to configure, for some weird reason. Unfortunately, this is not testable, unless we can allocate a buffer with 4 GB or more in size. The test for this would be to open a file we know to be small, then try to read 4 GB + 1 byte. If everything works correctly, we'll read the full file; if there was a truncation, we'd read one byte. Change-Id: If3ee511bf1de17e0123c85bbcaa463b9972746ce Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qiodevice_p.h')
-rw-r--r--src/corelib/io/qiodevice_p.h18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/corelib/io/qiodevice_p.h b/src/corelib/io/qiodevice_p.h
index 10d92a896d..d764cb0fbb 100644
--- a/src/corelib/io/qiodevice_p.h
+++ b/src/corelib/io/qiodevice_p.h
@@ -98,19 +98,19 @@ public:
first++;
return ch;
}
- int read(char* target, qint64 size) {
- int r = qMin(size, len);
+ qint64 read(char* target, qint64 size) {
+ qint64 r = qMin(size, len);
memcpy(target, first, r);
len -= r;
first += r;
return r;
}
- int peek(char* target, qint64 size) {
- int r = qMin(size, len);
+ qint64 peek(char* target, qint64 size) {
+ qint64 r = qMin(size, len);
memcpy(target, first, r);
return r;
}
- char* reserve(int size) {
+ char* reserve(qint64 size) {
makeSpace(size + len, freeSpaceAtEnd);
char* writePtr = first + len;
len += size;
@@ -128,16 +128,16 @@ public:
clear();
return retVal;
}
- int readLine(char* target, qint64 size) {
- int r = qMin(size, len);
+ qint64 readLine(char* target, qint64 size) {
+ qint64 r = qMin(size, len);
char* eol = static_cast<char*>(memchr(first, '\n', r));
if (eol)
r = 1+(eol-first);
memcpy(target, first, r);
len -= r;
first += r;
- return int(r);
- }
+ return r;
+ }
bool canReadLine() const {
return memchr(first, '\n', len);
}