Juan Lang : kernel: Use the WinXP method for comparing strings with embedded NULLs. Update tests.
Module: wine Branch: refs/heads/master Commit: 22d7f141449a4981073b78d1c933a8cded0e7684 URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=22d7f141449a4981073b78d1... Author: Juan Lang <juan_lang(a)yahoo.com> Date: Wed Jun 21 14:53:45 2006 -0700 kernel: Use the WinXP method for comparing strings with embedded NULLs. Update tests. --- dlls/kernel/tests/locale.c | 14 ++++++++++++-- libs/unicode/sortkey.c | 5 ++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dlls/kernel/tests/locale.c b/dlls/kernel/tests/locale.c index c099930..d7c0eee 100644 --- a/dlls/kernel/tests/locale.c +++ b/dlls/kernel/tests/locale.c @@ -928,11 +928,21 @@ static void test_CompareStringA(void) ret = CompareStringA(LOCALE_USER_DEFAULT, 0, "aLuZkUtZ", 7, "aLuZkUtZ\0A", 10); ok(ret == 1, "aLuZkUtZ vs aLuZkUtZ\\0A expected 1, got %d\n", ret); + /* WinXP handles embedded NULLs differently than earlier versions */ ret = CompareStringA(LOCALE_USER_DEFAULT, 0, "aLuZkUtZ", 8, "aLuZkUtZ\0A", 10); - ok(ret == 2, "aLuZkUtZ vs aLuZkUtZ\\0A expected 2, got %d\n", ret); + ok(ret == 1 || ret == 2, "aLuZkUtZ vs aLuZkUtZ\\0A expected 1 or 2, got %d\n", ret); ret = CompareStringA(LOCALE_USER_DEFAULT, 0, "aLu\0ZkUtZ", 8, "aLu\0ZkUtZ\0A", 10); - ok(ret == 2, "aLu\\0ZkUtZ vs aLu\\0ZkUtZ\\0A expected 2, got %d\n", ret); + ok(ret == 1 || ret == 2, "aLu\\0ZkUtZ vs aLu\\0ZkUtZ\\0A expected 1 or 2, got %d\n", ret); + + ret = CompareStringA(lcid, 0, "a\0b", -1, "a", -1); + ok(ret == 2, "a vs a expected 2, got %d\n", ret); + + ret = CompareStringA(lcid, 0, "a\0b", 4, "a", 2); + ok(ret == 3, "a\\0b vs a expected 3, got %d\n", ret); + + ret = CompareStringA(lcid, 0, "\1\0\2", 4, "\1\0\1", 4); + todo_wine ok(ret != 2, "\\1\\0\\2 vs \\1\\0\\1 expected unequal\n"); } static void test_LCMapStringA(void) diff --git a/libs/unicode/sortkey.c b/libs/unicode/sortkey.c index 67c2e8d..17b5537 100644 --- a/libs/unicode/sortkey.c +++ b/libs/unicode/sortkey.c @@ -326,9 +326,8 @@ static inline int compare_case_weights(i static inline int real_length(const WCHAR *str, int len) { - int real_len = 0; - while (len-- && *str++) real_len++; - return real_len; + while (len && !str[len - 1]) len--; + return len; } int wine_compare_string(int flags, const WCHAR *str1, int len1,
participants (1)
-
Alexandre Julliard