summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2020-06-11 12:15:36 -0700
committerMårten Nordheim <marten.nordheim@qt.io>2020-06-23 00:29:50 +0000
commit727fab7d291d8d6e1b61a7faec4b4318f714d1e0 (patch)
tree596b3b57f51fc9e2f5d59ba842af73eac327ad2f /src
parentcdcb75c46b968dbfeb1992c6bee19aceda27da38 (diff)
QCborMap: remove the optimization not to detach from non-const find()
All our tests were find() == end() or !=, which depends on the evaluation order of the arguments to operator==(). If end() is called first, then the detach happens before find() and all is well. But if find() is called first, it may return end() before end() detaches. [ChangeLog][QCborMap] Fixed a bug that could cause the iterator returned from a failing key search with find() not to match end(). Now, every call to find() will detach in shared QCborMaps; to avoid this, use constFind() and constEnd(). Fixes: QTBUG-84583 Pick-to: 5.15 5.12 Change-Id: I552d244076a447ab92d7fffd161793496a8d03a8 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/serialization/qcbormap.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/corelib/serialization/qcbormap.cpp b/src/corelib/serialization/qcbormap.cpp
index f3218c680d..9179ed81b6 100644
--- a/src/corelib/serialization/qcbormap.cpp
+++ b/src/corelib/serialization/qcbormap.cpp
@@ -834,9 +834,8 @@ QCborValueRef QCborMap::operator[](const QCborValue &key)
*/
QCborMap::iterator QCborMap::find(qint64 key)
{
+ detach();
auto it = constFind(key);
- if (it != constEnd())
- detach();
return { d.data(), it.item.i };
}
@@ -860,9 +859,8 @@ QCborMap::iterator QCborMap::find(qint64 key)
*/
QCborMap::iterator QCborMap::find(QLatin1String key)
{
+ detach();
auto it = constFind(key);
- if (it != constEnd())
- detach();
return { d.data(), it.item.i };
}
@@ -886,9 +884,8 @@ QCborMap::iterator QCborMap::find(QLatin1String key)
*/
QCborMap::iterator QCborMap::find(const QString & key)
{
+ detach();
auto it = constFind(key);
- if (it != constEnd())
- detach();
return { d.data(), it.item.i };
}
@@ -912,9 +909,8 @@ QCborMap::iterator QCborMap::find(const QString & key)
*/
QCborMap::iterator QCborMap::find(const QCborValue &key)
{
+ detach();
auto it = constFind(key);
- if (it != constEnd())
- detach();
return { d.data(), it.item.i };
}