[dlls/ipsapi/psapi_main.c] Strncpy elimination.

Peter Berg Larsen pebl at math.ku.dk
Sun Mar 27 12:07:38 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/psapi/psapi_main.c
===================================================================
RCS file: /home/wine/wine/dlls/psapi/psapi_main.c,v
retrieving revision 1.22
diff -u -r1.22 psapi_main.c
--- dlls/psapi/psapi_main.c	20 Jan 2005 19:59:48 -0000	1.22
+++ dlls/psapi/psapi_main.c	26 Mar 2005 09:40:57 -0000
@@ -338,6 +338,7 @@
 {
     WCHAR  tmp[MAX_PATH];
     WCHAR* ptr;
+    int    ptrlen;

     if(!lpBaseName || !nSize) {
         SetLastError(ERROR_INVALID_PARAMETER);
@@ -349,8 +350,9 @@
         return 0;
     TRACE("%s\n", debugstr_w(tmp));
     if ((ptr = strrchrW(tmp, '\\')) != NULL) ptr++; else ptr = tmp;
-    strncpyW(lpBaseName, ptr, nSize);
-    return min(strlenW(ptr), nSize);
+    ptrlen = strlenW(ptr);
+    memcpy(lpBaseName, ptr, min(ptrlen+1,nSize) * sizeof(WCHAR));
+    return min(ptrlen, nSize);
 }

 /***********************************************************************





More information about the wine-patches mailing list