diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-03 20:08:46 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-04 07:52:47 +0900 |
commit | df164cd856a34d8c1462793a40e56d387389b82f (patch) | |
tree | 91e69f92a5ad64b70495bef12fa6449eb32aef3b /lib/connection.cpp | |
parent | eaca25fd5115ab00a29b7d47dfc6e16cbfd5e552 (diff) | |
download | libquotient-df164cd856a34d8c1462793a40e56d387389b82f.tar.gz libquotient-df164cd856a34d8c1462793a40e56d387389b82f.zip |
Connection: Trim raw data in emitted signals
If the payload is too large, an attempt to allocate a QString out of
QByteArray may end with qBadAlloc(). So by default the data emitted in
case of error are trimmed to 64KiB, and this can be overridden to a
different value (or switched off entirely with <n>=0) by adding -
DTRIM_RAW_DATA=<n> to CPP_FLAGS.
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r-- | lib/connection.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index d363b433..1f6cc67a 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -65,6 +65,10 @@ HashT erase_if(HashT& hashMap, Pred pred) return removals; } +#ifndef TRIM_RAW_DATA +#define TRIM_RAW_DATA 65535 +#endif + class Connection::Private { public: @@ -198,7 +202,8 @@ void Connection::doConnectToServer(const QString& user, const QString& password, }); connect(loginJob, &BaseJob::failure, this, [this, loginJob] { - emit loginError(loginJob->errorString(), loginJob->rawData()); + emit loginError(loginJob->errorString(), + loginJob->rawData(TRIM_RAW_DATA)); }); } @@ -274,7 +279,7 @@ void Connection::sync(int timeout) connect( job, &SyncJob::retryScheduled, this, [this,job] (int retriesTaken, int nextInMilliseconds) { - emit networkError(job->errorString(), job->rawData(), + emit networkError(job->errorString(), job->rawData(TRIM_RAW_DATA), retriesTaken, nextInMilliseconds); }); connect( job, &SyncJob::failure, this, [this, job] { @@ -283,10 +288,10 @@ void Connection::sync(int timeout) { qCWarning(SYNCJOB) << "Sync job failed with ContentAccessError - login expired?"; - emit loginError(job->errorString(), job->rawData()); + emit loginError(job->errorString(), job->rawData(TRIM_RAW_DATA)); } else - emit syncError(job->errorString(), job->rawData()); + emit syncError(job->errorString(), job->rawData(TRIM_RAW_DATA)); }); } |