From 727fab7d291d8d6e1b61a7faec4b4318f714d1e0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 11 Jun 2020 12:15:36 -0700 Subject: QCborMap: remove the optimization not to detach from non-const find() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/serialization/qcbormap.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/corelib/serialization/qcbormap.cpp') 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 }; } -- cgit v1.2.3