Sebastian Lackner : shlwapi: Fix incorrect usage of CompareString in StrRStrIA.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Nov 19 10:07:50 CST 2014


Module: wine
Branch: master
Commit: 80d98683d02977f93def88254414b3210af558c9
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=80d98683d02977f93def88254414b3210af558c9

Author: Sebastian Lackner <sebastian at fds-team.de>
Date:   Wed Nov 19 08:17:58 2014 +0100

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 eaaaf3b..316dd3f 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;
 }
 
 /*************************************************************************




More information about the wine-cvs mailing list