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 <thiago.macieira@intel.com>
This commit is contained in:
Giuseppe D'Angelo 2021-09-18 20:23:15 +02:00
parent 710842f075
commit b32698b3a9
2 changed files with 8 additions and 7 deletions

View File

@ -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;

View File

@ -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<QStringView> &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);
}