summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2020-10-09 11:01:16 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2020-10-13 17:04:16 +0200
commitba511b2fa4782d6618a5261bbbd50f0c57266a3a (patch)
tree62dd28d3ce8a8fd540e50726b648c989be818424 /tests/auto/corelib/thread/qpromise/tst_qpromise.cpp
parent1ae15edd7e7ec4bd96d3a9a4d6b5793c7f7e8830 (diff)
Reject overwrites by the same index in QPromise::addResult()
One can call addResult(value, index) twice and consequently set the value twice by the same index. This seems rather strange and probably should not be allowed. This commit rejects setting results when there's already a valid result by that index. Consequently, this fixes memory leaks caused by N-times-called addResult(..., index) Fixes: QTBUG-86828 Change-Id: I77494f2cb73ce727ffad721cfcdcaa420899eb25 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'tests/auto/corelib/thread/qpromise/tst_qpromise.cpp')
-rw-r--r--tests/auto/corelib/thread/qpromise/tst_qpromise.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp b/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp
index 2b8853ccd7..62e3711d42 100644
--- a/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp
+++ b/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp
@@ -169,12 +169,12 @@ void tst_QPromise::addResult()
auto f = promise.future();
// add as lvalue
+ int resultAt0 = 456;
{
- int result = 456;
- promise.addResult(result);
+ promise.addResult(resultAt0);
QCOMPARE(f.resultCount(), 1);
- QCOMPARE(f.result(), result);
- QCOMPARE(f.resultAt(0), result);
+ QCOMPARE(f.result(), resultAt0);
+ QCOMPARE(f.resultAt(0), resultAt0);
}
// add as rvalue
{
@@ -190,13 +190,20 @@ void tst_QPromise::addResult()
QCOMPARE(f.resultCount(), 3);
QCOMPARE(f.resultAt(2), result);
}
- // add at position and overwrite
+ // add as lvalue at position and overwrite
{
int result = -1;
const auto originalCount = f.resultCount();
promise.addResult(result, 0);
QCOMPARE(f.resultCount(), originalCount);
- QCOMPARE(f.resultAt(0), result);
+ QCOMPARE(f.resultAt(0), resultAt0); // overwrite does not work
+ }
+ // add as rvalue at position and overwrite
+ {
+ const auto originalCount = f.resultCount();
+ promise.addResult(-1, 0);
+ QCOMPARE(f.resultCount(), originalCount);
+ QCOMPARE(f.resultAt(0), resultAt0); // overwrite does not work
}
}