From da2c170aa25bc6e8fd6cd0788fae14ee455ce359 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 20 Apr 2012 14:59:30 +0200 Subject: [PATCH] Don't use the QRegExp methods that modify the object [QtCore] QRegExp matching methods modify the object, which we don't want to. In particular, when we receive a QRegExp from the user or we store in a context that might require thread-safety, make sure we make a copy before using it. QRegularExpression has no such shortcoming. Task-number: QTBUG-25064 Change-Id: Icf22986cd5f6fd086518c78a7d56e6cadfe9f5f6 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Lars Knoll --- src/corelib/io/qdiriterator.cpp | 3 ++- src/corelib/kernel/qobject.cpp | 3 ++- src/corelib/mimetypes/qmimeglobpattern.cpp | 2 +- src/corelib/xml/qxmlutils.cpp | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp index f2a259b..67ea1c9 100644 --- a/src/corelib/io/qdiriterator.cpp +++ b/src/corelib/io/qdiriterator.cpp @@ -338,7 +338,8 @@ bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInf end = nameRegExps.constEnd(); iter != end; ++iter) { - if (iter->exactMatch(fileName)) { + QRegExp copy = *iter; + if (copy.exactMatch(fileName)) { matched = true; break; } diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 35b46b2..2b2a3c6 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1654,10 +1654,11 @@ void qt_qFindChildren_helper(const QObject *parent, const QRegExp &re, if (!parent || !list) return; const QObjectList &children = parent->children(); + QRegExp reCopy = re; QObject *obj; for (int i = 0; i < children.size(); ++i) { obj = children.at(i); - if (mo.cast(obj) && re.indexIn(obj->objectName()) != -1) + if (mo.cast(obj) && reCopy.indexIn(obj->objectName()) != -1) list->append(obj); if (options & Qt::FindChildrenRecursively) diff --git a/src/corelib/mimetypes/qmimeglobpattern.cpp b/src/corelib/mimetypes/qmimeglobpattern.cpp index de26dba..77d688d 100644 --- a/src/corelib/mimetypes/qmimeglobpattern.cpp +++ b/src/corelib/mimetypes/qmimeglobpattern.cpp @@ -135,7 +135,7 @@ bool QMimeGlobPattern::matchFileName(const QString &inputFilename) const return (m_pattern == filename); // Other (quite rare) patterns, like "*.anim[1-9j]": use slow but correct method - const QRegExp rx(m_pattern, Qt::CaseSensitive, QRegExp::WildcardUnix); + QRegExp rx(m_pattern, Qt::CaseSensitive, QRegExp::WildcardUnix); return rx.exactMatch(filename); } diff --git a/src/corelib/xml/qxmlutils.cpp b/src/corelib/xml/qxmlutils.cpp index 89912b4..44a56de 100644 --- a/src/corelib/xml/qxmlutils.cpp +++ b/src/corelib/xml/qxmlutils.cpp @@ -236,7 +236,7 @@ bool QXmlUtils::isEncName(const QString &encName) * replace that regexp is probably a 70 lines so I prioritize this to when * the dependency is considered alarming, or when the rest of the bugs * are fixed. */ - const QRegExp encNameRegExp(QLatin1String("[A-Za-z][A-Za-z0-9._\\-]*")); + QRegExp encNameRegExp(QLatin1String("[A-Za-z][A-Za-z0-9._\\-]*")); Q_ASSERT(encNameRegExp.isValid()); return encNameRegExp.exactMatch(encName); -- 2.7.4