From 1b672e55ce738c5e02bd8c77df5dbf4668b7e30f Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Wed, 19 Nov 2014 08:31:40 +0100 Subject: [PATCH] shlwapi: Fix incorrect usage of CompareString in StrRStrIW. --- dlls/shlwapi/string.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/dlls/shlwapi/string.c b/dlls/shlwapi/string.c index 316dd3f3e7d..9ba603804a8 100644 --- a/dlls/shlwapi/string.c +++ b/dlls/shlwapi/string.c @@ -625,6 +625,7 @@ LPSTR WINAPI StrRStrIA(LPCSTR lpszStr, LPCSTR lpszEnd, LPCSTR lpszSearch) */ LPWSTR WINAPI StrRStrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, LPCWSTR lpszSearch) { + LPWSTR lpszRet = NULL; INT iLen; TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch)); @@ -632,18 +633,23 @@ LPWSTR WINAPI StrRStrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, LPCWSTR lpszSearch) if (!lpszStr || !lpszSearch || !*lpszSearch) return NULL; - if (!lpszEnd) - lpszEnd = lpszStr + strlenW(lpszStr); - iLen = strlenW(lpszSearch); - while (lpszEnd > lpszStr) + if (!lpszEnd) + lpszEnd = lpszStr + strlenW(lpszStr); + else /* reproduce the broken behaviour on Windows */ + lpszEnd += min(iLen - 1, lstrlenW(lpszEnd)); + + while (lpszStr + iLen <= lpszEnd && *lpszStr) { - lpszEnd--; - if (!StrCmpNIW(lpszEnd, lpszSearch, iLen)) - return (LPWSTR)lpszEnd; + if (!ChrCmpIW(*lpszSearch, *lpszStr)) + { + if (!StrCmpNIW(lpszStr, lpszSearch, iLen)) + lpszRet = (LPWSTR)lpszStr; + } + lpszStr++; } - return NULL; + return lpszRet; } /*************************************************************************