From 7fc63dd0ff368a637dcd17e692b9d6b26278b538 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 2 Mar 2010 16:41:05 +0100 Subject: QString::section: Fix crash with SectionIncludeLeadingSep flag And start is out of bounds. Reviewed-by: Thiago Reviewed-by: Joao Task-number: QTBUG-4306 --- src/corelib/tools/qstring.cpp | 2 +- tests/auto/qstring/tst_qstring.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 3ef0e66..03bc053 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -3185,7 +3185,7 @@ QString QString::section(const QRegExp ®, int start, int end, SectionFlags fl if (!empty || !(flags & SectionSkipEmpty)) x++; } - if((flags & SectionIncludeLeadingSep)) { + if((flags & SectionIncludeLeadingSep) && first_i < sections.size()) { const qt_section_chunk §ion = sections.at(first_i); ret.prepend(section.string.left(section.length)); } diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp index c9b3436..4ebcade 100644 --- a/tests/auto/qstring/tst_qstring.cpp +++ b/tests/auto/qstring/tst_qstring.cpp @@ -3503,7 +3503,10 @@ void tst_QString::section_data() << QString("\\b") << 3 << 3 << int(QString::SectionDefault) << QString("is") << true; - + QTest::newRow( "task257941-rx" ) << QString("99.0 42.3") + << QString("\\s*[AaBb]\\s*") << 1 << 1 + << int(QString::SectionIncludeLeadingSep) + << QString() << true; } void tst_QString::section() -- cgit v0.12