diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-07-26 17:03:37 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-07-27 19:57:27 +0200 |
commit | 08de1fb28153d8170b592796a84032897afa4206 (patch) | |
tree | 9b23bbc67376d62ba37944b1099455fd5004b644 /src/corelib/thread | |
parent | 3b8127c3fcf07905180e274c7e554aaa757963c3 (diff) |
Don't report results when the results list is empty
When inserting items into the result store, a ResultItem is created,
which stores a pointer to the results list and their size. If the size
of the ResultItem is set to 0, it means that a single result is stored.
In case of trying to report results via an empty list, the size is 0, so
result store treats it as a single result.
Added checks before storing the results to make sure that the result
list isn't empty. Note that empty lists are allowed in some cases for
the filter mode, because ResultStoreBase::addResults() knows how to
handle those cases correctly.
Task-number: QTBUG-80957
Pick-to: 5.15 6.1 6.2
Change-Id: I399af4c3eef6adf82fea5df031fe9a9075006b1f
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r-- | src/corelib/thread/qresultstore.cpp | 1 | ||||
-rw-r--r-- | src/corelib/thread/qresultstore.h | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/thread/qresultstore.cpp b/src/corelib/thread/qresultstore.cpp index a239954dbe..5982ae5454 100644 --- a/src/corelib/thread/qresultstore.cpp +++ b/src/corelib/thread/qresultstore.cpp @@ -235,6 +235,7 @@ int ResultStoreBase::addResult(int index, const void *result) int ResultStoreBase::addResults(int index, const void *results, int vectorSize, int totalCount) { if (m_filterMode == false || vectorSize == totalCount) { + Q_ASSERT(vectorSize != 0); ResultItem resultItem(results, vectorSize); return insertResultItem(index, resultItem); } else { diff --git a/src/corelib/thread/qresultstore.h b/src/corelib/thread/qresultstore.h index fb9151fcc6..ced181a91d 100644 --- a/src/corelib/thread/qresultstore.h +++ b/src/corelib/thread/qresultstore.h @@ -194,6 +194,9 @@ public: template<typename T> int addResults(int index, const QList<T> *results) { + if (results->empty()) // reject if results are empty + return -1; + if (containsValidResultItem(index)) // reject if already present return -1; @@ -203,6 +206,10 @@ public: template<typename T> int addResults(int index, const QList<T> *results, int totalCount) { + // reject if results are empty, and nothing is filtered away + if ((m_filterMode == false || results->count() == totalCount) && results->empty()) + return -1; + if (containsValidResultItem(index)) // reject if already present return -1; |