diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2018-09-20 14:09:36 +0300 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2018-09-20 14:09:36 +0300 |
commit | 00984b6738ee66225857a8808fc2efff78bc3868 (patch) | |
tree | 109cc0d948fb960c40c878f56a4550c1b67a892e /test/syncenginetestutils.h | |
parent | 9f4597b7272d37b0eae9ccb7ba0a2e3d713e91ce (diff) |
Fix crash in delta sync test.
The test was accessing dangling char* payload, as the QByteArray was
going out of scope
Diffstat (limited to 'test/syncenginetestutils.h')
-rw-r--r-- | test/syncenginetestutils.h | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index 14f173ba4..1a78614b7 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -651,8 +651,7 @@ class FakeGetWithDataReply : public QNetworkReply Q_OBJECT public: const FileInfo *fileInfo; - const char *payload; - quint64 size; + QByteArray payload; quint64 offset = 0; bool aborted = false; @@ -665,8 +664,7 @@ public: open(QIODevice::ReadOnly); Q_ASSERT(!data.isEmpty()); - payload = data.data(); - size = data.length(); + payload = data; QString fileName = getFilePathFromUrl(request.url()); Q_ASSERT(!fileName.isEmpty()); fileInfo = remoteRootFileInfo.find(fileName); @@ -678,8 +676,7 @@ public: const char *r = range.constData(); int res = sscanf(r, "bytes=%llu-%llu", &start, &end); if (res == 2) { - payload += start; - size = end - start + 1; + payload = payload.mid(start, end - start + 1); } } } @@ -692,7 +689,7 @@ public: emit finished(); return; } - setHeader(QNetworkRequest::ContentLengthHeader, size); + setHeader(QNetworkRequest::ContentLengthHeader, payload.size()); setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 200); setRawHeader("OC-ETag", fileInfo->etag.toLatin1()); setRawHeader("ETag", fileInfo->etag.toLatin1()); @@ -712,14 +709,13 @@ public: { if (aborted) return 0; - return size + QIODevice::bytesAvailable(); + return payload.size() - offset + QIODevice::bytesAvailable(); } qint64 readData(char *data, qint64 maxlen) override { - qint64 len = std::min(size, quint64(maxlen)); - std::memcpy(data, payload + offset, len); - size -= len; + qint64 len = std::min(payload.size() - offset, quint64(maxlen)); + std::memcpy(data, payload.constData() + offset, len); offset += len; return len; } |