QRegExp: fix crash
Fixes a crash when invoking various QRegExp methods on an object *before* doing any match. For instance fixes: QRegExp re; re.matchedLength(); // crash Task-number: QTBUG-23352 Change-Id: I9c239ff790a139c7820ef1aeced89d31320ae6b0 Reviewed-by: Andy Shaw <andy.shaw@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
568e714fdf
commit
136c2bf184
@ -3934,6 +3934,7 @@ static void invalidateEngine(QRegExpPrivate *priv)
|
||||
QRegExp::QRegExp()
|
||||
{
|
||||
priv = new QRegExpPrivate;
|
||||
prepareEngine(priv);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -3949,6 +3950,7 @@ QRegExp::QRegExp()
|
||||
QRegExp::QRegExp(const QString &pattern, Qt::CaseSensitivity cs, PatternSyntax syntax)
|
||||
{
|
||||
priv = new QRegExpPrivate(QRegExpEngineKey(pattern, syntax, cs));
|
||||
prepareEngine(priv);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -79,6 +79,8 @@ private slots:
|
||||
void posAndCapConsistency_data();
|
||||
void posAndCapConsistency();
|
||||
void interval();
|
||||
void validityCheck_data();
|
||||
void validityCheck();
|
||||
};
|
||||
|
||||
// Testing get/set functions
|
||||
@ -1344,6 +1346,33 @@ void tst_QRegExp::interval()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QRegExp::validityCheck_data()
|
||||
{
|
||||
QTest::addColumn<QString>("pattern");
|
||||
QTest::addColumn<bool>("validity");
|
||||
QTest::newRow("validity01") << QString() << true;
|
||||
QTest::newRow("validity02") << QString("abc.*abc") << true;
|
||||
QTest::newRow("validity03") << QString("[a-z") << false;
|
||||
QTest::newRow("validity04") << QString("a(b") << false;
|
||||
}
|
||||
|
||||
void tst_QRegExp::validityCheck()
|
||||
{
|
||||
QFETCH(QString, pattern);
|
||||
|
||||
QRegExp rx(pattern);
|
||||
QTEST(rx.isValid(), "validity");
|
||||
QCOMPARE(rx.matchedLength(), -1);
|
||||
QCOMPARE(rx.pos(), -1);
|
||||
QCOMPARE(rx.cap(), QString(""));
|
||||
|
||||
QRegExp rx2(rx);
|
||||
QTEST(rx2.isValid(), "validity");
|
||||
QCOMPARE(rx2.matchedLength(), -1);
|
||||
QCOMPARE(rx2.pos(), -1);
|
||||
QCOMPARE(rx2.cap(), QString(""));
|
||||
}
|
||||
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_QRegExp)
|
||||
#include "tst_qregexp.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user