From a6442deab2424760208a1b03d04e3c26b82c36a4 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 19 May 2013 17:27:28 -0500 Subject: [PATCH] compare_utf16le_names_case_insensitive(): Use _wcsnicmp() --- src/dentry.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/dentry.c b/src/dentry.c index 04ed1092..d93d8ac7 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -487,11 +487,12 @@ compare_utf16le_names_case_sensitive(const utf16lechar *name1, size_t nbytes1, const utf16lechar *name2, size_t nbytes2) { /* Return the result if the strings differ up to their minimum length. - * Note that we cannot strcmp() or strncmp() here, as the strings are in - * UTF-16LE format. */ + * Note that we cannot use strcmp() or strncmp() here, as the strings + * are in UTF-16LE format. */ int result = memcmp(name1, name2, min(nbytes1, nbytes2)); if (result) return result; + /* The strings are the same up to their minimum length, so return a * result based on their lengths. */ if (nbytes1 < nbytes2) @@ -508,10 +509,13 @@ static int compare_utf16le_names_case_insensitive(const utf16lechar *name1, size_t nbytes1, const utf16lechar *name2, size_t nbytes2) { - /* Only call _wcsicmp() if both strings are of nonzero length; otherwise - * one could be NULL. */ - if (nbytes1 && nbytes2) - return _wcsicmp((const wchar_t*)name1, (const wchar_t*)name2); + /* Return the result if the strings differ up to their minimum length. + * */ + int result = _wcsnicmp((const wchar_t*)name1, (const wchar_t*)name2, + min(nbytes1 / 2, nbytes2 / 2)); + if (result) + return result; + /* The strings are the same up to their minimum length, so return a * result based on their lengths. */ if (nbytes1 < nbytes2) -- 2.43.0