From 8f52ad9fe084eee26869e4a94a678076845a6f58 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 8 Mar 2017 11:08:32 +0100 Subject: [PATCH] ucstricmp: compare null and empty strings equal For consistency with ucstrcmp(), which does the same. Before, the two overloads would sort null before empty strings. This behavior was removed in Qt 3.0, IIRC- This does not yet change anything, as all callers seem to work around the problem by handling null strings before calling this function (directly or indirectly). We would have seen a failure crop up if it wasn't so. As soon as we use these functions to compare QStringViews, however, the functions need to deal correctly with a nullptr lhs and/or rhs, so fix them. Change-Id: Ie4e417aade993213169b96b5e7351850c52ae733 Reviewed-by: Thiago Macieira --- src/corelib/tools/qstring.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index ab9d3dbb3a..6bd2aad8da 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -379,9 +379,9 @@ static int ucstricmp(const ushort *a, const ushort *ae, const ushort *b, const u if (a == b) return (ae - be); if (a == 0) - return 1; + return be - b; if (b == 0) - return -1; + return a - ae; const ushort *e = ae; if (be - b < ae - a) @@ -410,13 +410,10 @@ static int ucstricmp(const ushort *a, const ushort *ae, const ushort *b, const u // Case-insensitive comparison between a Unicode string and a QLatin1String static int ucstricmp(const ushort *a, const ushort *ae, const uchar *b, const uchar *be) { - if (a == 0) { - if (b == 0) - return 0; - return 1; - } - if (b == 0) - return -1; + if (!a) + return be - b; + if (!b) + return a - ae; const ushort *e = ae; if (be - b < ae - a)