[dlls/devenum/parsedisplayname.c] Strncpy elimation.

Peter Berg Larsen pebl at math.ku.dk
Sun Mar 27 11:47:27 CST 2005


I have been checking the usage of strncpy, replacing where apropriate with
a memcpy or lstrcpyn[AW]. The first raw diff was 100kb, so there is bound
to be one or two slips. These are the first batch which I found to be
obvious, correct, and didnt need a special comment. Note with correct I
mean if there was a \0 bug before then it still there.

Changelog:
	Janitorial Task: Check the usage of strncpy/strncpyW.


Index: dlls/devenum/parsedisplayname.c
===================================================================
RCS file: /home/wine/wine/dlls/devenum/parsedisplayname.c,v
retrieving revision 1.8
diff -u -r1.8 parsedisplayname.c
--- dlls/devenum/parsedisplayname.c     7 Dec 2004 14:37:11 -0000
1.8
+++ dlls/devenum/parsedisplayname.c     27 Mar 2005 15:41:56 -0000
@@ -94,6 +94,7 @@
     MediaCatMoniker * pMoniker = NULL;
     CLSID clsidDevice;
     HRESULT res = S_OK;
+    int classlen;

     TRACE("(%p, %s, %p, %p)\n", pbc, debugstr_w(pszDisplayName),
pchEaten, ppmkOut);

@@ -107,12 +108,13 @@
     /* size = pszBetween - pszDisplayName - 1 (for '\\' after CLSID)
      * + 1 (for NULL character)
      */
-    pszClass = CoTaskMemAlloc((int)(pszBetween - pszDisplayName) *
sizeof(WCHAR));
+    classlen = (int)(pszBetween - pszDisplayName);
+    pszClass = CoTaskMemAlloc(classlen * sizeof(WCHAR));
     if (!pszClass)
         return E_OUTOFMEMORY;

-    strncpyW(pszClass, pszDisplayName, (int)(pszBetween - pszDisplayName)
- 1);
-    pszClass[(int)(pszBetween - pszDisplayName) - 1] = 0;
+    memcpy(pszClass, pszDisplayName, (classlen - 1)* sizeof(WCHAR));
+    pszClass[classlen - 1] = 0;

     TRACE("Device CLSID: %s\n", debugstr_w(pszClass));






More information about the wine-patches mailing list