From b32698b3a9ffdae5e3995a390c804cfe2c8b7943 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sat, 18 Sep 2021 20:23:15 +0200 Subject: [PATCH] DBus: do not mix QList iterators and raw pointers In Qt 5, QVector::iterator was actually a raw pointer. In Qt 6, QVector = QList, and QList::iterator isn't a pointer, but converts to one (for backwards compatibility). Some code in QtDBus exploits this by mixing iterators and raw pointers. In preparation for deprecating conversions between them, adjust this code by "converting" explicitly when needed. Change-Id: I1efab72b33d27742b339cf848cefd5cc258cd215 Reviewed-by: Thiago Macieira --- src/dbus/qdbusconnection.cpp | 9 +++++---- src/dbus/qdbusintegrator.cpp | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp index c4f5e2a0fa..9438641147 100644 --- a/src/dbus/qdbusconnection.cpp +++ b/src/dbus/qdbusconnection.cpp @@ -895,7 +895,7 @@ bool QDBusConnection::registerObject(const QString &path, const QString &interfa QDBusWriteLocker locker(RegisterObjectAction, d); // lower-bound search for where this object should enter in the tree - QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator node = &d->rootNode; + QDBusConnectionPrivate::ObjectTreeNode *node = &d->rootNode; int i = 1; while (node) { if (pathComponents.count() == i) { @@ -934,7 +934,7 @@ bool QDBusConnection::registerObject(const QString &path, const QString &interfa std::lower_bound(node->children.begin(), node->children.end(), pathComponents.at(i)); if (it != node->children.end() && it->name == pathComponents.at(i)) { // match: this node exists - node = it; + node = &(*it); // are we allowed to go deeper? if (node->flags & ExportChildObjects) { @@ -945,7 +945,8 @@ bool QDBusConnection::registerObject(const QString &path, const QString &interfa } } else { // add entry - node = node->children.insert(it, pathComponents.at(i).toString()); + it = node->children.insert(it, pathComponents.at(i).toString()); + node = &(*it); } // iterate @@ -1017,7 +1018,7 @@ QObject *QDBusConnection::objectRegisteredAt(const QString &path) const if (it == node->children.constEnd() || it->name != pathComponents.at(i)) break; // node not found - node = it; + node = &(*it); ++i; } return nullptr; diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 6bf9ad7786..138c83ce57 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -385,7 +385,7 @@ static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root, start = 1; // walk the object tree - QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator node = root; + const QDBusConnectionPrivate::ObjectTreeNode *node = root; while (start < length && node) { if (node->flags & QDBusConnection::ExportChildObjects) break; @@ -399,7 +399,7 @@ static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root, std::lower_bound(node->children.constBegin(), node->children.constEnd(), pathComponent); if (it != node->children.constEnd() && it->name == pathComponent) // match - node = it; + node = &(*it); else node = nullptr; @@ -624,7 +624,7 @@ static void huntAndUnregister(const QList &pathComponents, int i, if (it == end || it->name != pathComponents.at(i)) return; // node not found - huntAndUnregister(pathComponents, i + 1, mode, it); + huntAndUnregister(pathComponents, i + 1, mode, &(*it)); if (!it->isActive()) node->children.erase(it); }