[Qt-interest] Bug in QString::section with QRegExp and SectionIncludeLeadingSep
Stephen Jackson
spjackson42 at gmail.com
Wed May 20 13:18:22 CEST 2009
On Wed, May 20, 2009 at 10:08 AM, Markus Wagner wrote:
> 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?!
>
In my opinion, you should file a bug report.
It crashes in the following section from qstring.cpp because
sections.at(first_i) is out of range.
if((flags & SectionIncludeLeadingSep)) {
const qt_section_chunk §ion = sections.at(first_i);
ret.prepend(section.string.left(section.length));
}
I'm not sure what it should be doing though. You suggest returning an
empty string, but if you pass a separator rather than a regex, and the
start parameter is greater than the number of elements, a string
containing only the separator is returned. With a regex, I'm unclear
about the intent in these circumstances.
Regards,
Stephen Jackson
More information about the Qt-interest-old
mailing list