From: Sebastian Lackner Subject: [3/5] comctl32: Allow broken behaviour in StrRStr functions. Message-Id: <546C5387.5000900@fds-team.de> Date: Wed, 19 Nov 2014 09:23:35 +0100 Not sure if any application actually uses those functions (they are not publicly exported), but to avoid regressions because of my CompareString fixes, its probably better to allow the broken behaviour here too. --- dlls/comctl32/string.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) From db6967de24834ff3c817f20b9cc295197237c95f Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Wed, 19 Nov 2014 08:36:22 +0100 Subject: comctl32: Allow broken behaviour in StrRStr functions. --- dlls/comctl32/string.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/dlls/comctl32/string.c b/dlls/comctl32/string.c index 5e28b8f..112d9d3 100644 --- a/dlls/comctl32/string.c +++ b/dlls/comctl32/string.c @@ -674,18 +674,20 @@ LPSTR WINAPI StrRStrIA(LPCSTR lpszStr, LPCSTR lpszEnd, LPCSTR lpszSearch) if (!lpszStr || !lpszSearch || !*lpszSearch) return NULL; - if (!lpszEnd) - lpszEnd = lpszStr + lstrlenA(lpszStr); - if (IsDBCSLeadByte(*lpszSearch)) - ch1 = *lpszSearch << 8 | lpszSearch[1]; + ch1 = *lpszSearch << 8 | (UCHAR)lpszSearch[1]; else ch1 = *lpszSearch; iLen = lstrlenA(lpszSearch); + if (!lpszEnd) + lpszEnd = lpszStr + lstrlenA(lpszStr); + else /* reproduce the broken behaviour on Windows */ + lpszEnd += min(iLen - 1, lstrlenA(lpszEnd)); + while (lpszStr + iLen <= lpszEnd && *lpszStr) { - ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr; + ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | (UCHAR)lpszStr[1] : *lpszStr; if (!COMCTL32_ChrCmpIA(ch1, ch2)) { if (!StrCmpNIA(lpszStr, lpszSearch, iLen)) @@ -711,10 +713,13 @@ LPWSTR WINAPI StrRStrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, LPCWSTR lpszSearch) if (!lpszStr || !lpszSearch || !*lpszSearch) return NULL; + iLen = strlenW(lpszSearch); + if (!lpszEnd) lpszEnd = lpszStr + strlenW(lpszStr); + else /* reproduce the broken behaviour on Windows */ + lpszEnd += min(iLen - 1, lstrlenW(lpszEnd)); - iLen = strlenW(lpszSearch); while (lpszStr + iLen <= lpszEnd && *lpszStr) { -- 2.1.3