[PATCH] [shell32] tests run through valgrind lenses

Eric Pouech eric.pouech at wanadoo.fr
Thu Feb 16 04:56:54 CST 2006


Fixes for bugs found by valgrind on shell32 tests harness:
- read strings from left to right (PathGetDriveNumberW)
- don't access buffers before they are filled (SHGetPathFromIDListW)
- fill buffers & variables on all paths (SHELL_FindExecutable)
- handle error condition (unix_fs)
- don't shoot in the blind for AW APIs (tests/shelllink.c)

A+
---

 dlls/shell32/pidl.c            |    2 +-
 dlls/shell32/shfldr_unixfs.c   |    3 ++-
 dlls/shell32/shlexec.c         |    5 +++++
 dlls/shell32/tests/shelllink.c |   20 ++++++++++----------
 dlls/shlwapi/path.c            |    9 ++++++---
 5 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/dlls/shell32/pidl.c b/dlls/shell32/pidl.c
index 6ec496f..a3f9574 100644
--- a/dlls/shell32/pidl.c
+++ b/dlls/shell32/pidl.c
@@ -1259,7 +1259,7 @@ BOOL WINAPI SHGetPathFromIDListW(LPCITEM
     DWORD dwAttributes;
     STRRET strret;
 
-    TRACE_(shell)("(pidl=%p,%p)\n", pidl, debugstr_w(pszPath));
+    TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath);
     pdump(pidl);
 
     if (!pidl)
diff --git a/dlls/shell32/shfldr_unixfs.c b/dlls/shell32/shfldr_unixfs.c
index c0d7f87..7780adc 100644
--- a/dlls/shell32/shfldr_unixfs.c
+++ b/dlls/shell32/shfldr_unixfs.c
@@ -701,6 +701,7 @@ static BOOL UNIXFS_path_to_pidl(UnixFold
             
         if (!pNextPathElement) {
             SHFree(*ppidl);
+            *ppidl = NULL;
             return FALSE;
         }
         pidl = ILGetNext(pidl);
@@ -1753,7 +1754,7 @@ static HRESULT WINAPI UnixFolder_ISFHelp
                 ILFree(pidlRelative);
             SHChangeNotify(SHCNE_MKDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
             ILFree(pidlAbsolute);
-        }
+        } else return E_FAIL;
         return S_OK;
     }
 }
diff --git a/dlls/shell32/shlexec.c b/dlls/shell32/shlexec.c
index 14739d6..f5b1e88 100644
--- a/dlls/shell32/shlexec.c
+++ b/dlls/shell32/shlexec.c
@@ -597,6 +597,11 @@ UINT SHELL_FindExecutable(LPCWSTR lpPath
             filetype[filetypelen] = '\0';
             TRACE("File type: %s\n", debugstr_w(filetype));
         }
+        else
+        {
+            *filetype = '\0';
+            filetypelen = 0;
+        }
     }
 
     if (*filetype)
diff --git a/dlls/shell32/tests/shelllink.c b/dlls/shell32/tests/shelllink.c
index 7d45ef3..84d325d 100644
--- a/dlls/shell32/tests/shelllink.c
+++ b/dlls/shell32/tests/shelllink.c
@@ -38,28 +38,28 @@
 static const WCHAR lnkfile[]= { 'C',':','\\','t','e','s','t','.','l','n','k',0 };
 static const WCHAR notafile[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
 
-
+static LPITEMIDLIST path_to_pidl(const char* path)
+{
 /* For some reason SHILCreateFromPath does not work on Win98 and
  * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
  * get what we want on all platforms.
  */
-static LPITEMIDLIST (WINAPI *pSHSimpleIDListFromPathA)(LPCSTR)=NULL;
+    static LPITEMIDLIST (WINAPI *pSHSimpleIDListFromPathAW)(LPCVOID)=NULL;
 
-static LPITEMIDLIST path_to_pidl(const char* path)
-{
     LPITEMIDLIST pidl;
 
-    if (!pSHSimpleIDListFromPathA)
+    if (!pSHSimpleIDListFromPathAW)
     {
         HMODULE hdll=LoadLibraryA("shell32.dll");
-        pSHSimpleIDListFromPathA=(void*)GetProcAddress(hdll, (char*)162);
-        if (!pSHSimpleIDListFromPathA)
-            trace("SHSimpleIDListFromPathA not found in shell32.dll\n");
+        pSHSimpleIDListFromPathAW=(void*)GetProcAddress(hdll, (char*)162);
+        if (!pSHSimpleIDListFromPathAW)
+            trace("SHSimpleIDListFromPathAW not found in shell32.dll\n");
     }
 
     pidl=NULL;
-    if (pSHSimpleIDListFromPathA)
-        pidl=pSHSimpleIDListFromPathA(path);
+    /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
+    if (pSHSimpleIDListFromPathAW && (GetVersion() & 0x80000000))
+        pidl=pSHSimpleIDListFromPathAW(path);
 
     if (!pidl)
     {
diff --git a/dlls/shlwapi/path.c b/dlls/shlwapi/path.c
index 93c7fe8..bf9abf9 100644
--- a/dlls/shlwapi/path.c
+++ b/dlls/shlwapi/path.c
@@ -506,9 +506,12 @@ int WINAPI PathGetDriveNumberW(LPCWSTR l
 {
   TRACE ("(%s)\n",debugstr_w(lpszPath));
 
-  if (lpszPath && lpszPath[1] == ':' &&
-      tolowerW(*lpszPath) >= 'a' && tolowerW(*lpszPath) <= 'z')
-    return tolowerW(*lpszPath) - 'a';
+  if (lpszPath)
+  {
+      WCHAR tl = tolowerW(lpszPath[0]);
+      if (tl >= 'a' && tl <= 'z' && lpszPath[1] == ':')
+          return tl - 'a';
+  }
   return -1;
 }
 





More information about the wine-patches mailing list