diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2020-06-11 12:15:36 -0700 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-06-30 20:32:09 +0000 |
commit | 8a4cac976044e925d938a9106bd299b7627ede20 (patch) | |
tree | 383329ca8f477ef9317669148ad5c427da8f9e06 /src/corelib/serialization | |
parent | f3319f8a1820710a60e0cfb6a1a4ac76f411c110 (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
Change-Id: I552d244076a447ab92d7fffd161793496a8d03a8
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 727fab7d291d8d6e1b61a7faec4b4318f714d1e0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib/serialization')
-rw-r--r-- | src/corelib/serialization/qcbormap.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/corelib/serialization/qcbormap.cpp b/src/corelib/serialization/qcbormap.cpp index 4b28ca4a2e..d669c7bf49 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 }; } |