[dlls/commdlg/filedlg.c] Strncpy elimination.

Peter Berg Larsen pebl at math.ku.dk
Sun Mar 27 12:33:07 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/commdlg/filedlg.c
===================================================================
RCS file: /home/wine/wine/dlls/commdlg/filedlg.c,v
retrieving revision 1.100
diff -u -r1.100 filedlg.c
--- dlls/commdlg/filedlg.c	24 Mar 2005 21:01:39 -0000	1.100
+++ dlls/commdlg/filedlg.c	26 Mar 2005 09:40:06 -0000
@@ -462,16 +462,17 @@
   if(ofn->lpstrFile)
   {
     fodInfos.filename = MemAlloc(ofn->nMaxFile*sizeof(WCHAR));
-    strncpyW(fodInfos.filename,ofn->lpstrFile,ofn->nMaxFile);
+    lstrcpynW(fodInfos.filename,ofn->lpstrFile,ofn->nMaxFile);
   }
   else
     fodInfos.filename = NULL;

   if(ofn->lpstrInitialDir)
   {
-    DWORD len = strlenW(ofn->lpstrInitialDir);
-    fodInfos.initdir = MemAlloc((len+1)*sizeof(WCHAR));
-    strcpyW(fodInfos.initdir,ofn->lpstrInitialDir);
+    /* fodInfos.initdir = strdupW(ofn->lpstrInitialDir); */
+    DWORD len = strlenW(ofn->lpstrInitialDir)+1;
+    fodInfos.initdir = MemAlloc(len*sizeof(WCHAR));
+    memcpy(fodInfos.initdir,ofn->lpstrInitialDir,len*sizeof(WCHAR));
   }
   else
     fodInfos.initdir = NULL;
@@ -853,7 +854,7 @@

         /* Prepend the current path */
         n = strlenW(lpstrCurrentDir) + 1;
-        strncpyW( bufW, lpstrCurrentDir, size );
+        memcpy( bufW, lpstrCurrentDir, min(n,size) * sizeof(WCHAR));
         if(n<size)
         {
             /* 'n' includes trailing \0 */
@@ -2034,7 +2035,7 @@
              {
                LPOPENFILENAMEW ofn = fodInfos->ofnInfos;

-               strncpyW(ofn->lpstrFile, lpstrPathAndFile, ofn->nMaxFile);
+               lstrcpynW(ofn->lpstrFile, lpstrPathAndFile, ofn->nMaxFile);
                if (ofn->Flags & OFN_ALLOWMULTISELECT)
                  ofn->lpstrFile[lstrlenW(ofn->lpstrFile) + 1] = '\0';
              }





More information about the wine-patches mailing list