Fix 64 bit issues in QIODevicePrivateLinearBuffer
The API was using int, not qint64 leading to implicit truncation of numbers in a few places Task-number: QTBUG-40974 Change-Id: I13aedc84557a19b6f74fe6825764e7b5827f27b0 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
This commit is contained in:
parent
0f92875891
commit
0c748fb7b1
@ -833,7 +833,7 @@ qint64 QIODevice::read(char *data, qint64 maxSize)
|
|||||||
// In buffered mode, we try to fill up the QIODevice buffer before
|
// In buffered mode, we try to fill up the QIODevice buffer before
|
||||||
// we do anything else.
|
// we do anything else.
|
||||||
// buffer is empty at this point, try to fill it
|
// 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);
|
char *writePointer = d->buffer.reserve(bytesToBuffer);
|
||||||
|
|
||||||
// Make sure the device is positioned correctly.
|
// Make sure the device is positioned correctly.
|
||||||
@ -1013,6 +1013,8 @@ QByteArray QIODevice::readAll()
|
|||||||
|
|
||||||
// flush internal read buffer
|
// flush internal read buffer
|
||||||
if (!(d->openMode & Text) && !d->buffer.isEmpty()) {
|
if (!(d->openMode & Text) && !d->buffer.isEmpty()) {
|
||||||
|
if (d->buffer.size() >= INT_MAX)
|
||||||
|
return QByteArray();
|
||||||
result = d->buffer.readAll();
|
result = d->buffer.readAll();
|
||||||
readBytes = result.size();
|
readBytes = result.size();
|
||||||
d->pos += readBytes;
|
d->pos += readBytes;
|
||||||
@ -1031,6 +1033,8 @@ QByteArray QIODevice::readAll()
|
|||||||
} else {
|
} else {
|
||||||
// Read it all in one go.
|
// Read it all in one go.
|
||||||
// If resize fails, don't read anything.
|
// If resize fails, don't read anything.
|
||||||
|
if (readBytes + theSize - d->pos > INT_MAX)
|
||||||
|
return QByteArray();
|
||||||
result.resize(int(readBytes + theSize - d->pos));
|
result.resize(int(readBytes + theSize - d->pos));
|
||||||
readBytes += read(result.data() + readBytes, result.size() - readBytes);
|
readBytes += read(result.data() + readBytes, result.size() - readBytes);
|
||||||
}
|
}
|
||||||
|
@ -84,13 +84,13 @@ public:
|
|||||||
first = buf;
|
first = buf;
|
||||||
capacity = 0;
|
capacity = 0;
|
||||||
}
|
}
|
||||||
int size() const {
|
qint64 size() const {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
bool isEmpty() const {
|
bool isEmpty() const {
|
||||||
return len == 0;
|
return len == 0;
|
||||||
}
|
}
|
||||||
void skip(int n) {
|
void skip(qint64 n) {
|
||||||
if (n >= len) {
|
if (n >= len) {
|
||||||
clear();
|
clear();
|
||||||
} else {
|
} else {
|
||||||
@ -106,14 +106,14 @@ public:
|
|||||||
first++;
|
first++;
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
int read(char* target, int size) {
|
int read(char* target, qint64 size) {
|
||||||
int r = qMin(size, len);
|
int r = qMin(size, len);
|
||||||
memcpy(target, first, r);
|
memcpy(target, first, r);
|
||||||
len -= r;
|
len -= r;
|
||||||
first += r;
|
first += r;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
int peek(char* target, int size) {
|
int peek(char* target, qint64 size) {
|
||||||
int r = qMin(size, len);
|
int r = qMin(size, len);
|
||||||
memcpy(target, first, r);
|
memcpy(target, first, r);
|
||||||
return r;
|
return r;
|
||||||
@ -124,7 +124,7 @@ public:
|
|||||||
len += size;
|
len += size;
|
||||||
return writePtr;
|
return writePtr;
|
||||||
}
|
}
|
||||||
void chop(int size) {
|
void chop(qint64 size) {
|
||||||
if (size >= len) {
|
if (size >= len) {
|
||||||
clear();
|
clear();
|
||||||
} else {
|
} else {
|
||||||
@ -136,7 +136,7 @@ public:
|
|||||||
clear();
|
clear();
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
int readLine(char* target, int size) {
|
int readLine(char* target, qint64 size) {
|
||||||
int r = qMin(size, len);
|
int r = qMin(size, len);
|
||||||
char* eol = static_cast<char*>(memchr(first, '\n', r));
|
char* eol = static_cast<char*>(memchr(first, '\n', r));
|
||||||
if (eol)
|
if (eol)
|
||||||
@ -158,7 +158,7 @@ public:
|
|||||||
len++;
|
len++;
|
||||||
*first = c;
|
*first = c;
|
||||||
}
|
}
|
||||||
void ungetBlock(const char* block, int size) {
|
void ungetBlock(const char* block, qint64 size) {
|
||||||
if ((first - buf) < size) {
|
if ((first - buf) < size) {
|
||||||
// underflow, the existing valid data needs to move to the end of the (potentially bigger) buffer
|
// underflow, the existing valid data needs to move to the end of the (potentially bigger) buffer
|
||||||
makeSpace(len + size, freeSpaceAtStart);
|
makeSpace(len + size, freeSpaceAtStart);
|
||||||
@ -191,7 +191,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// length of the unread data
|
// length of the unread data
|
||||||
int len;
|
qint64 len;
|
||||||
// start of the unread data
|
// start of the unread data
|
||||||
char* first;
|
char* first;
|
||||||
// the allocated buffer
|
// the allocated buffer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user