From 80d98683d02977f93def88254414b3210af558c9 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Wed, 19 Nov 2014 08:17:58 +0100 Subject: [PATCH] shlwapi: Fix incorrect usage of CompareString in StrRStrIA. --- dlls/shlwapi/string.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/dlls/shlwapi/string.c b/dlls/shlwapi/string.c index eaaaf3bd2ab..316dd3f3e7d 100644 --- a/dlls/shlwapi/string.c +++ b/dlls/shlwapi/string.c @@ -585,6 +585,7 @@ LPWSTR WINAPI StrStrW(LPCWSTR lpszStr, LPCWSTR lpszSearch) */ LPSTR WINAPI StrRStrIA(LPCSTR lpszStr, LPCSTR lpszEnd, LPCSTR lpszSearch) { + LPSTR lpszRet = NULL; WORD ch1, ch2; INT iLen; @@ -593,28 +594,28 @@ LPSTR WINAPI StrRStrIA(LPCSTR lpszStr, LPCSTR lpszEnd, LPCSTR lpszSearch) if (!lpszStr || !lpszSearch || !*lpszSearch) return NULL; - if (!lpszEnd) - lpszEnd = lpszStr + lstrlenA(lpszStr); - if (lpszEnd == lpszStr) - return NULL; - if (IsDBCSLeadByte(*lpszSearch)) ch1 = *lpszSearch << 8 | (UCHAR)lpszSearch[1]; else ch1 = *lpszSearch; iLen = lstrlenA(lpszSearch); - do + if (!lpszEnd) + lpszEnd = lpszStr + lstrlenA(lpszStr); + else /* reproduce the broken behaviour on Windows */ + lpszEnd += min(iLen - 1, lstrlenA(lpszEnd)); + + while (lpszStr + iLen <= lpszEnd && *lpszStr) { - lpszEnd = CharPrevA(lpszStr, lpszEnd); - ch2 = IsDBCSLeadByte(*lpszEnd)? *lpszEnd << 8 | (UCHAR)lpszEnd[1] : *lpszEnd; + ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | (UCHAR)lpszStr[1] : *lpszStr; if (!ChrCmpIA(ch1, ch2)) { - if (!StrCmpNIA(lpszEnd, lpszSearch, iLen)) - return (LPSTR)lpszEnd; + if (!StrCmpNIA(lpszStr, lpszSearch, iLen)) + lpszRet = (LPSTR)lpszStr; } - } while (lpszEnd > lpszStr); - return NULL; + lpszStr = CharNextA(lpszStr); + } + return lpszRet; } /*************************************************************************