Commit fedc888d authored by David Palacio's avatar David Palacio

Fix invalid index access:

FilePathA is a substring of FilePathB: E.g:
/foo/bar
/foo/barr

A Filepath ends in space
/foo/bar
/foo/ba_  <- _ is a space

In debug build this code fails this assert:
qstring.h:
inline const QChar QString::operator[](int i) const
{ Q_ASSERT(i >= 0 && i < size()); return d->data[i]; }

REVIEW: 6672


svn path=/trunk/KDE/kdegraphics/okular/; revision=1230522
parent 4aa3ebe4
......@@ -83,16 +83,18 @@ static int natural_order_compare( const QString &leftStr, const QString &rightSt
int fractional, result;
ai = bi = 0;
const int aSize = leftStr.size();
const int bSize = rightStr.size();
while ( true ) {
ca = leftStr[ ai ]; cb = rightStr[ bi ];
/* skip over leading spaces or zeros */
while ( ca.isSpace() )
ca = leftStr[ ++ai ];
while ( ca.isSpace() && ++ai < aSize )
ca = leftStr[ ai ];
while ( cb.isSpace() )
cb = rightStr[ ++bi ];
while ( cb.isSpace() && ++bi < bSize )
cb = rightStr[ bi ];
/* process run of digits */
if ( ca.isDigit() && cb.isDigit() ) {
......@@ -124,6 +126,12 @@ static int natural_order_compare( const QString &leftStr, const QString &rightSt
return +1;
++ai; ++bi;
if( aSize == ai ) {
return aSize <= bSize ? -1 : 1;
}
if ( bSize == bi ) {
return bSize <= aSize ? 1 : -1;
}
}
}
......@@ -136,3 +144,4 @@ bool caseInsensitiveNaturalOrderLessThen( const QString &left, const QString &ri
{
return (natural_order_compare( left, right, true ) < 0);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment