From: Thiago Macieira Date: Fri, 20 Apr 2012 12:59:30 +0000 (+0200) Subject: Don't use the QRegExp methods that modify the object [QtGui] X-Git-Tag: 071012110112~1425 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=092118855ba47a0061e5b54198c49c3ad05b5aed;p=profile%2Fivi%2Fqtbase.git Don't use the QRegExp methods that modify the object [QtGui] 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: If119e06221ca99e57c5ad1a1d4cc6468e9f68c7b Reviewed-by: Gunnar Sletta --- diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index a8991d5..f9fe166 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -1281,7 +1281,7 @@ QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &fro static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int offset, QTextDocument::FindFlags options, QTextCursor &cursor) { - const QRegExp expr(expression); + QRegExp expr(expression); QString text = block.text(); text.replace(QChar::Nbsp, QLatin1Char(' ')); diff --git a/src/gui/util/qvalidator.cpp b/src/gui/util/qvalidator.cpp index d0bd1cf..3103cc7 100644 --- a/src/gui/util/qvalidator.cpp +++ b/src/gui/util/qvalidator.cpp @@ -871,10 +871,11 @@ QRegExpValidator::~QRegExpValidator() QValidator::State QRegExpValidator::validate(QString &input, int& pos) const { - if (r.exactMatch(input)) { + QRegExp copy = r; + if (copy.exactMatch(input)) { return Acceptable; } else { - if (const_cast(r).matchedLength() == input.size()) { + if (copy.matchedLength() == input.size()) { return Intermediate; } else { pos = input.size(); diff --git a/tests/auto/other/lancelot/paintcommands.cpp b/tests/auto/other/lancelot/paintcommands.cpp index 969db62..4e45c75 100644 --- a/tests/auto/other/lancelot/paintcommands.cpp +++ b/tests/auto/other/lancelot/paintcommands.cpp @@ -694,7 +694,7 @@ void PaintCommands::runCommand(const QString &scriptLine) QString firstWord = scriptLine.section(QRegExp("\\s"), 0, 0); QList indices = s_commandHash.values(firstWord); foreach(int idx, indices) { - const PaintCommandInfos &command = s_commandInfoTable.at(idx); + PaintCommandInfos command = s_commandInfoTable.at(idx); if (command.regExp.indexIn(scriptLine) >= 0) { (this->*(command.paintMethod))(command.regExp); return;