diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2010-06-03 09:03:14 (GMT) |
---|---|---|
committer | Samuli Piippo <samuli.piippo@digia.com> | 2011-06-09 10:06:06 (GMT) |
commit | b31ca7e1384972ebb46e547aa26b8df5ce60cd6e (patch) | |
tree | 57ef0922bd97b8e53f0d9c0330e901ca75d505a0 /src/corelib | |
parent | 0e9b8257e542bb3b6958e90917bad0d1691598e2 (diff) | |
download | Qt-b31ca7e1384972ebb46e547aa26b8df5ce60cd6e.zip Qt-b31ca7e1384972ebb46e547aa26b8df5ce60cd6e.tar.gz Qt-b31ca7e1384972ebb46e547aa26b8df5ce60cd6e.tar.bz2 |
QString: Fix severals bugs when comparing with QStringRef
the internal ucstricmp and ucstrcmp contains different bugs if the
strings are not 0-terminated, as it is with QStringRef.
- in ucstricmp, even if the pointer are the same, the lenght could
be different
- we used to deference the 'end' pointer, that would be 0 if the
string ends with 0, but we cannot do that in the general case
Task-number: QTBUG-10404
Reviewed-by: Denis
(cherry picked from commit cd003bfcf9a05967893099e8948ba3d8f281aa7d)
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 01d3825..3f472d3 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -111,7 +111,7 @@ int qFindStringBoyerMoore(const QChar *haystack, int haystackLen, int from, static int ucstricmp(const ushort *a, const ushort *ae, const ushort *b, const ushort *be) { if (a == b) - return 0; + return (ae - be); if (a == 0) return 1; if (b == 0) @@ -123,7 +123,7 @@ static int ucstricmp(const ushort *a, const ushort *ae, const ushort *b, const u uint alast = 0; uint blast = 0; - while (a != e) { + while (a < e) { // qDebug() << hex << alast << blast; // qDebug() << hex << "*a=" << *a << "alast=" << alast << "folded=" << foldCase (*a, alast); // qDebug() << hex << "*b=" << *b << "blast=" << blast << "folded=" << foldCase (*b, blast); @@ -152,7 +152,7 @@ static int ucstricmp(const ushort *a, const ushort *ae, const uchar *b) if (b == 0) return -1; - while (a != ae && *b) { + while (a < ae && *b) { int diff = foldCase(*a) - foldCase(*b); if ((diff)) return diff; @@ -4532,9 +4532,12 @@ int QString::compare_helper(const QChar *data1, int length1, QLatin1String s2, return length1; if (cs == Qt::CaseSensitive) { - while (uc != e && *c && *uc == *c) + while (uc < e && *c && *uc == *c) uc++, c++; + if (uc == e) + return -*c; + return *uc - *c; } else { return ucstricmp(uc, e, c); |