[Qt-interest] Bug in QString::section with QRegExp and SectionIncludeLeadingSep
Markus Wagner
markus at mwagner.info
Wed May 20 11:08:10 CEST 2009
Hi all,
I am not sure if I found a bug, or if the crash is "defined" behaviour.
When using
QString section ( const QRegExp & reg, int start, int end = -1,
SectionFlags flags = SectionDefault ) const
with QString::SectionIncludeLeadingSep as flags and accessing an
element which is non-existing (e.g. start=1 and end=1, where the reg
will result in only a single result), the method call will crash; see
example code below.
Expected behaviour would be to retrive an empty or null string.
Should I file a bug report, or am I missing something?!
Greetings, Markus
===== Example-code:=====
#include <QtCore/QCoreApplication>
#include <QtCore/QRegExp>
#include <QtCore/QString>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString splitMe1 = "A1234 B5678";
QString splitMe2 = "99.0 42.3";
QRegExp rx("\\s*[AaBb]\\s*");
QString split;
split = splitMe1.section(rx,0,0,QString::SectionIncludeLeadingSep);
qDebug(split.toAscii().data()); // empty string
split = splitMe1.section(rx,1,1,QString::SectionIncludeLeadingSep);
qDebug(split.toAscii().data()); // "A1234"
split = splitMe1.section(rx,2,2,QString::SectionIncludeLeadingSep);
qDebug(split.toAscii().data()); // " B5678"
split = splitMe2.section(rx,0,0,QString::SectionIncludeLeadingSep);
qDebug(split.toAscii().data()); // "99.0 42.3"
split =
splitMe2.section(rx,1,1,QString::SectionIncludeLeadingSep); // crash -
expecting at least an empty string
if (!split.isNull())
qDebug(split.toAscii().data());
return a.exec();
}
--
Markus Wagner
Römerstraße 39
64291 Darmstadt
markus at mwagner.info
+49-6151-3929440
+49-179-5481432
More information about the Qt-interest-old
mailing list