From b0859bd13bbe7d90b8d0453981719e5160d136a0 Mon Sep 17 00:00:00 2001 From: Sergii Lisovenko <2522054+s-lisovenko@users.noreply.github.com> Date: Sun, 15 Oct 2023 08:29:48 +0300 Subject: [PATCH] Optimize map provider iteration to prevent app crashes Changed from QHashIterator to using a constant iterator for iterating through the map providers in _providersTable. This change prevents application crashes during a map download session caused by the potential modification of an implicitly shared hash. --- src/QtLocationPlugin/QGCMapUrlEngine.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/QtLocationPlugin/QGCMapUrlEngine.cpp b/src/QtLocationPlugin/QGCMapUrlEngine.cpp index 7f4cbfd..b41002f 100644 --- a/src/QtLocationPlugin/QGCMapUrlEngine.cpp +++ b/src/QtLocationPlugin/QGCMapUrlEngine.cpp @@ -156,13 +156,9 @@ quint32 UrlFactory::averageSizeForType(const QString& type) { } QString UrlFactory::getTypeFromId(int id) { - - QHashIterator i(_providersTable); - - while (i.hasNext()) { - i.next(); - if ((int)(qHash(i.key())>>1) == id) { - return i.key(); + for (auto it = _providersTable.constBegin(); it != _providersTable.constEnd(); ++it) { + if ((int)(qHash(it.key()) >> 1) == id) { + return it.key(); } } qCDebug(QGCMapUrlEngineLog) << "getTypeFromId : id not found" << id;