Commit 91d63c0c authored by Lionel Ulmer's avatar Lionel Ulmer Committed by Alexandre Julliard

Add better NULL checks to lstrcmp[i](A/W) functions.

parent def71887
...@@ -2356,8 +2356,15 @@ INT WINAPI CompareStringA(LCID lcid, DWORD style, ...@@ -2356,8 +2356,15 @@ INT WINAPI CompareStringA(LCID lcid, DWORD style,
*/ */
int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2) int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2)
{ {
int ret = CompareStringA(GetThreadLocale(), 0, str1, -1, str2, -1); int ret;
if ((str1 == NULL) && (str2 == NULL)) return 0;
if (str1 == NULL) return -1;
if (str2 == NULL) return 1;
ret = CompareStringA(GetThreadLocale(), 0, str1, -1, str2, -1);
if (ret) ret -= 2; if (ret) ret -= 2;
return ret; return ret;
} }
...@@ -2378,8 +2385,15 @@ int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2) ...@@ -2378,8 +2385,15 @@ int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2)
*/ */
int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2) int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
{ {
int ret = CompareStringA(GetThreadLocale(), NORM_IGNORECASE, str1, -1, str2, -1); int ret;
if ((str1 == NULL) && (str2 == NULL)) return 0;
if (str1 == NULL) return -1;
if (str2 == NULL) return 1;
ret = CompareStringA(GetThreadLocale(), NORM_IGNORECASE, str1, -1, str2, -1);
if (ret) ret -= 2; if (ret) ret -= 2;
return ret; return ret;
} }
...@@ -2390,8 +2404,15 @@ int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2) ...@@ -2390,8 +2404,15 @@ int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
*/ */
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2) int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
{ {
int ret = CompareStringW(GetThreadLocale(), 0, str1, -1, str2, -1); int ret;
if ((str1 == NULL) && (str2 == NULL)) return 0;
if (str1 == NULL) return -1;
if (str2 == NULL) return 1;
ret = CompareStringW(GetThreadLocale(), 0, str1, -1, str2, -1);
if (ret) ret -= 2; if (ret) ret -= 2;
return ret; return ret;
} }
...@@ -2402,8 +2423,15 @@ int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2) ...@@ -2402,8 +2423,15 @@ int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
*/ */
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2) int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
{ {
int ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, -1, str2, -1); int ret;
if ((str1 == NULL) && (str2 == NULL)) return 0;
if (str1 == NULL) return -1;
if (str2 == NULL) return 1;
ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, -1, str2, -1);
if (ret) ret -= 2; if (ret) ret -= 2;
return ret; return ret;
} }
......
...@@ -795,8 +795,17 @@ static void test_CompareStringA() ...@@ -795,8 +795,17 @@ static void test_CompareStringA()
ok(!ret, "CompareStringA must fail with invalid flag\n"); ok(!ret, "CompareStringA must fail with invalid flag\n");
ret = lstrcmpA("", ""); ret = lstrcmpA("", "");
ok (!ret, "lstrcmpA(\"\", \"\") should return 0, got %d\n", ret); ok (ret == 0, "lstrcmpA(\"\", \"\") should return 0, got %d\n", ret);
ret = lstrcmpA(NULL, NULL);
ok (ret == 0, "lstrcmpA(NULL, NULL) should return 0, got %d\n", ret);
ret = lstrcmpA("", NULL);
ok (ret == 1, "lstrcmpA(\"\", NULL) should return 1, got %d\n", ret);
ret = lstrcmpA(NULL, "");
ok (ret == -1, "lstrcmpA(NULL, \"\") should return -1, got %d\n", ret);
ret = CompareStringA(LOCALE_SYSTEM_DEFAULT,0,"EndDialog",-1,"_Property",-1); ret = CompareStringA(LOCALE_SYSTEM_DEFAULT,0,"EndDialog",-1,"_Property",-1);
ok( ret == 3, "EndDialog vs _Property ... expected 3, got %d\n", ret); ok( ret == 3, "EndDialog vs _Property ... expected 3, got %d\n", ret);
......
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