Andrew Nguyen : shlwapi: Fix handling of an empty search string in StrStrW.
Alexandre Julliard
julliard at winehq.org
Mon Jul 19 11:05:43 CDT 2010
Module: wine
Branch: master
Commit: 9bcdb1c423070d5ed387ba3efc767adea2d2930b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9bcdb1c423070d5ed387ba3efc767adea2d2930b
Author: Andrew Nguyen <anguyen at codeweavers.com>
Date: Sun Jul 18 19:33:36 2010 -0500
shlwapi: Fix handling of an empty search string in StrStrW.
---
dlls/shlwapi/string.c | 4 ++-
dlls/shlwapi/tests/string.c | 55 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 1 deletions(-)
diff --git a/dlls/shlwapi/string.c b/dlls/shlwapi/string.c
index a0269b6..5647a35 100644
--- a/dlls/shlwapi/string.c
+++ b/dlls/shlwapi/string.c
@@ -584,7 +584,9 @@ LPSTR WINAPI StrStrA(LPCSTR lpszStr, LPCSTR lpszSearch)
*/
LPWSTR WINAPI StrStrW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
{
- if (!lpszStr || !lpszSearch) return NULL;
+ TRACE("(%s, %s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
+
+ if (!lpszStr || !lpszSearch || !*lpszSearch) return NULL;
return strstrW( lpszStr, lpszSearch );
}
diff --git a/dlls/shlwapi/tests/string.c b/dlls/shlwapi/tests/string.c
index a4e8d45..0eaaafb 100644
--- a/dlls/shlwapi/tests/string.c
+++ b/dlls/shlwapi/tests/string.c
@@ -1007,6 +1007,60 @@ static void test_StrStrA(void)
}
}
+static void test_StrStrW(void)
+{
+ static const WCHAR emptyW[] = {0};
+ static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
+ static const WCHAR deadW[] = {'D','e','A','d',0};
+ static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
+ static const WCHAR adbeW[] = {'A','d','B','e',0};
+ static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
+ static const WCHAR beefW[] = {'B','e','E','f',0};
+ static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
+
+ const struct
+ {
+ const WCHAR *search;
+ const WCHAR *expect;
+ } StrStrW_cases[] =
+ {
+ {emptyW, NULL},
+ {deadW, deadbeefW},
+ {dead_lowerW, NULL},
+ {adbeW, deadbeefW + 2},
+ {adbe_lowerW, NULL},
+ {beefW, deadbeefW + 4},
+ {beef_lowerW, NULL},
+ };
+
+ LPWSTR ret;
+ int i;
+
+ /* Tests crash on Win9x. */
+ if (0)
+ {
+ ret = StrStrW(NULL, NULL);
+ ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
+
+ ret = StrStrW(NULL, emptyW);
+ ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
+
+ ret = StrStrW(emptyW, NULL);
+ ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
+ }
+
+ ret = StrStrW(emptyW, emptyW);
+ ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
+
+ for (i = 0; i < sizeof(StrStrW_cases)/sizeof(StrStrW_cases[0]); i++)
+ {
+ ret = StrStrW(deadbeefW, StrStrW_cases[i].search);
+ ok(ret == StrStrW_cases[i].expect,
+ "[%d] Expected StrStrW to return %p, got %p\n",
+ i, StrStrW_cases[i].expect, ret);
+ }
+}
+
START_TEST(string)
{
HMODULE hShlwapi;
@@ -1077,6 +1131,7 @@ START_TEST(string)
test_SHUnicodeToUnicode();
test_StrXXX_overflows();
test_StrStrA();
+ test_StrStrW();
CoUninitialize();
}
More information about the wine-cvs
mailing list