Janitorial: Get rid of strncpy/strncpyW.
authorPeter Berg Larsen <pebl@math.ku.dk>
Mon, 28 Mar 2005 14:17:51 +0000 (14:17 +0000)
committerAlexandre Julliard <julliard@winehq.org>
Mon, 28 Mar 2005 14:17:51 +0000 (14:17 +0000)
50 files changed:
dlls/commdlg/filedlg.c
dlls/dbghelp/dbghelp.c
dlls/dbghelp/module.c
dlls/dbghelp/symbol.c
dlls/dmband/band.c
dlls/dmcompos/chordmap.c
dlls/dmime/audiopath.c
dlls/dmime/graph.c
dlls/dmime/segment.c
dlls/dsound/capture.c
dlls/dsound/dsound_main.c
dlls/dsound/propset.c
dlls/dswave/dswave.c
dlls/gdi/env.c
dlls/iphlpapi/ifenum.c
dlls/iphlpapi/iphlpapi_main.c
dlls/kernel/atom16.c
dlls/kernel/profile.c
dlls/kernel/tests/process.c
dlls/msi/action.c
dlls/msi/appsearch.c
dlls/msi/dialog.c
dlls/msi/format.c
dlls/msvcrt/dir.c
dlls/msvideo/msvideo16.c
dlls/opengl32/wgl.c
dlls/quartz/dsoundrender.c
dlls/quartz/parser.c
dlls/quartz/transform.c
dlls/quartz/videorenderer.c
dlls/quartz/waveparser.c
dlls/rsaenh/rsaenh.c
dlls/setupapi/devinst.c
dlls/setupapi/setupcab.c
dlls/shlwapi/path.c
dlls/shlwapi/string.c
dlls/shlwapi/url.c
dlls/tapi32/assisted.c
dlls/wineps/afm2c.c
dlls/wininet/cookie.c
dlls/wininet/ftp.c
dlls/wininet/http.c
dlls/wininet/internet.c
dlls/winsock/socket.c
programs/msiexec/msiexec.c
programs/regedit/regproc.c
programs/winecfg/drive.c
programs/winedbg/memory.c
programs/winemine/main.c
windows/spy.c

index ab91498abcbb6fbec963e0888ce2376fa2e6a2ad..a2c13a9fc7dfc93ed805c5afa33f460eb92b6c3b 100644 (file)
@@ -462,16 +462,17 @@ BOOL  WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
   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 @@ HRESULT FILEDLG95_Handle_GetFilePath(HWND hwnd, DWORD size, LPVOID buffer)
 
         /* 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 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
              {
                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';
              }
index 6dffc593c7744dc41058abdab3f09c1537f23ac3..cf0e28653bd78c43ba88bbc51fcded94d8717c29 100644 (file)
@@ -126,8 +126,7 @@ BOOL WINAPI SymGetSearchPath(HANDLE hProcess, LPSTR szSearchPath,
     struct process* pcs = process_find_by_handle(hProcess);
     if (!pcs) return FALSE;
 
-    strncpy(szSearchPath, pcs->search_path, SearchPathLength);
-    szSearchPath[SearchPathLength - 1] = '\0';
+    lstrcpynA(szSearchPath, pcs->search_path, SearchPathLength);
     return TRUE;
 }
 
index 063cbcd4b5516b251c8284234180f2832124ae53..8d62759fd4da61794e34c4bf422b205dfcd52f4f 100644 (file)
@@ -42,8 +42,7 @@ static void module_fill_module(const char* in, char* out, unsigned size)
          *ptr != '/' && *ptr != '\\' && ptr >= in; 
          ptr--);
     if (ptr < in || *ptr == '/' || *ptr == '\\') ptr++;
-    strncpy(out, ptr, size);
-    out[size - 1] = '\0';
+    lstrcpynA(out, ptr, size);
     len = strlen(out);
     if (len > 4 && 
         (!strcasecmp(&out[len - 4], ".dll") || !strcasecmp(&out[len - 4], ".exe")))
@@ -51,7 +50,7 @@ static void module_fill_module(const char* in, char* out, unsigned size)
     else if (((len > 12 && out[len - 13] == '/') || len == 12) && 
              (!strcasecmp(out + len - 12, "wine-pthread") || 
               !strcasecmp(out + len - 12, "wine-kthread")))
-        strcpy(out, "<wine-loader>");
+        lstrcpynA(out, "<wine-loader>",size);
     else
     {
         if (len > 7 && 
@@ -96,9 +95,7 @@ struct module* module_new(struct process* pcs, const char* name,
     module->module.ImageSize = size;
     module_fill_module(name, module->module.ModuleName, sizeof(module->module.ModuleName));
     module->module.ImageName[0] = '\0';
-    strncpy(module->module.LoadedImageName, name, 
-            sizeof(module->module.LoadedImageName));
-    module->module.LoadedImageName[sizeof(module->module.LoadedImageName) - 1] = '\0';
+    lstrcpynA(module->module.LoadedImageName, name, sizeof(module->module.LoadedImageName));
     module->module.SymType = SymNone;
     module->module.NumSyms = 0;
     module->module.TimeDateStamp = stamp;
@@ -360,13 +357,8 @@ done:
      * of ImageName. Overwrite it, if we have better information
      */
     if (ModuleName)
-    {
-        strncpy(module->module.ModuleName, ModuleName, 
-                sizeof(module->module.ModuleName));
-        module->module.ModuleName[sizeof(module->module.ModuleName) - 1] = '\0';
-    }
-    strncpy(module->module.ImageName, ImageName, sizeof(module->module.ImageName));
-    module->module.ImageName[sizeof(module->module.ImageName) - 1] = '\0';
+        lstrcpynA(module->module.ModuleName, ModuleName, sizeof(module->module.ModuleName));
+    lstrcpynA(module->module.ImageName, ImageName, sizeof(module->module.ImageName));
 
     return module->module.BaseOfImage;
 }
index 1cfa584f223232d5c4666bc46c7179fdf615d438..e6a475e436564aeea04fe025321e5defada5d298 100644 (file)
@@ -536,7 +536,7 @@ static void symt_fill_sym_info(const struct module* module,
                                                       sym_info->MaxNameLen, UNDNAME_COMPLETE) == 0))
         {
             sym_info->NameLen = min(strlen(name), sym_info->MaxNameLen - 1);
-            strncpy(sym_info->Name, name, sym_info->NameLen);
+            memcpy(sym_info->Name, name, sym_info->NameLen);
             sym_info->Name[sym_info->NameLen] = '\0';
         }
     }
@@ -916,8 +916,7 @@ BOOL WINAPI SymGetSymFromAddr(HANDLE hProcess, DWORD Address,
     Symbol->Size    = si->Size;
     Symbol->Flags   = si->Flags;
     len = min(Symbol->MaxNameLength, si->MaxNameLen);
-    strncpy(Symbol->Name, si->Name, len);
-    Symbol->Name[len - 1] = '\0';
+    lstrcpynA(Symbol->Name, si->Name, len);
     return TRUE;
 }
 
@@ -992,8 +991,7 @@ BOOL WINAPI SymGetSymFromName(HANDLE hProcess, LPSTR Name, PIMAGEHLP_SYMBOL Symb
     Symbol->Size    = si->Size;
     Symbol->Flags   = si->Flags;
     len = min(Symbol->MaxNameLength, si->MaxNameLen);
-    strncpy(Symbol->Name, si->Name, len);
-    Symbol->Name[len - 1] = '\0';
+    lstrcpynA(Symbol->Name, si->Name, len);
     return TRUE;
 }
 
index a72e7fa2329094a9c91cdff993084748a2478fbb..122a70dae0327a73b25f77fba9076d175acda406 100644 (file)
@@ -165,9 +165,9 @@ HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMU
        if (pDesc->dwValidData & DMUS_OBJ_NAME)
                strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
        if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
-               strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);             
+               strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
        if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
-               strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);             
+               strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
        if (pDesc->dwValidData & DMUS_OBJ_VERSION)
                memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));                            
        if (pDesc->dwValidData & DMUS_OBJ_DATE)
index aef51cdee80b6285aae8ba71445f121e034e47fe..0e390e3c8bef162f0c9fb8a1bbcddc17d256d5e6 100644 (file)
@@ -149,9 +149,9 @@ HRESULT WINAPI IDirectMusicChordMapImpl_IDirectMusicObject_SetDescriptor (LPDIRE
        if (pDesc->dwValidData & DMUS_OBJ_NAME)
                strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
        if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
-               strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);             
+               strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
        if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
-               strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);             
+               strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
        if (pDesc->dwValidData & DMUS_OBJ_VERSION)
                memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));                            
        if (pDesc->dwValidData & DMUS_OBJ_DATE)
index 49580c44d5a37e573d884c2464e130f188f49eb5..6256ed63128e1a4572ca0be6bf1331370af53ee6 100644 (file)
@@ -264,9 +264,9 @@ HRESULT WINAPI IDirectMusicAudioPathImpl_IDirectMusicObject_SetDescriptor (LPDIR
        if (pDesc->dwValidData & DMUS_OBJ_NAME)
                strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
        if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
-               strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);             
+               strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
        if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
-               strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);             
+               strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
        if (pDesc->dwValidData & DMUS_OBJ_VERSION)
                memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));                            
        if (pDesc->dwValidData & DMUS_OBJ_DATE)
index e3b59c1b31386911c18b3754d2eabefea3c9e064..ea45f7a352930f17a9e2ee81e7c9e5072e640803 100644 (file)
@@ -230,9 +230,9 @@ HRESULT WINAPI IDirectMusicGraphImpl_IDirectMusicObject_SetDescriptor (LPDIRECTM
        if (pDesc->dwValidData & DMUS_OBJ_NAME)
                strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
        if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
-               strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);             
+               strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
        if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
-               strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);             
+               strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
        if (pDesc->dwValidData & DMUS_OBJ_VERSION)
                memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));                            
        if (pDesc->dwValidData & DMUS_OBJ_DATE)
index b3d469017614b18195fd54857083b19a05dc021d..118238ffd76a313df173ca85529b70a779706550 100644 (file)
@@ -550,9 +550,9 @@ HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor (LPDIRE
        if (pDesc->dwValidData & DMUS_OBJ_NAME)
                strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
        if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
-               strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);             
+               strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
        if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
-               strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);             
+               strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
        if (pDesc->dwValidData & DMUS_OBJ_VERSION)
                memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));                            
        if (pDesc->dwValidData & DMUS_OBJ_DATE)
index e6f8095575e9efcc77a984195b33d4f7b658c4a6..d391d97961ce8a624af3a88d22a62eb0f796fb77 100644 (file)
@@ -567,8 +567,8 @@ IDirectSoundCaptureImpl_Initialize(
 
             if (err == DS_OK) {
                 This->drvcaps.dwFlags = 0;
-                strncpy(This->drvdesc.szDrvname, wic.szPname,
-                    sizeof(This->drvdesc.szDrvname));
+                lstrcpynA(This->drvdesc.szDrvname, wic.szPname,
+                          sizeof(This->drvdesc.szDrvname));
 
                 This->drvcaps.dwFlags |= DSCCAPS_EMULDRIVER;
                 This->drvcaps.dwFormats = wic.dwFormats;
index 7ed1e9c0a653500304b951f3f499907f2b0ee3d0..97a7f05c436971192d1a5da809c0f0730bb2e90d 100644 (file)
@@ -149,8 +149,7 @@ void setup_dsound_options(void)
            char appname[MAX_PATH+16];
            char *p = strrchr( buffer, '\\' );
            if (p!=NULL) {
-                   appname[MAX_PATH]='\0';
-                   strncpy(appname,p+1,MAX_PATH);
+                   lstrcpynA(appname,p+1,MAX_PATH);
                    strcat(appname,"\\dsound");
                    TRACE("appname = [%s] \n",appname);
                    if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
index d93ab33acfa792904fb460428a4e7bcef9010fb9..a0fa16f825105e78773e287d0e38bc246da228cb 100644 (file)
@@ -384,8 +384,8 @@ static HRESULT WINAPI DSPROPERTY_Description1(
                 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&(desc),0));
                 if (err == DS_OK) {
                     PIDSDRIVER drv = NULL;
-                    strncpy(ppd->DescriptionA, desc.szDesc, sizeof(ppd->DescriptionA) - 1);
-                    strncpy(ppd->ModuleA, desc.szDrvname, sizeof(ppd->ModuleA) - 1);
+                    lstrcpynA(ppd->DescriptionA, desc.szDesc, sizeof(ppd->DescriptionA));
+                    lstrcpynA(ppd->ModuleA, desc.szDrvname, sizeof(ppd->ModuleA));
                     MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, ppd->DescriptionW, sizeof(ppd->DescriptionW)/sizeof(WCHAR) );
                     MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, ppd->ModuleW, sizeof(ppd->ModuleW)/sizeof(WCHAR) );
                     err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD)&drv, 0));
@@ -415,8 +415,8 @@ static HRESULT WINAPI DSPROPERTY_Description1(
                 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&(desc),0));
                 if (err == DS_OK) {
                     PIDSCDRIVER drv;
-                    strncpy(ppd->DescriptionA, desc.szDesc, sizeof(ppd->DescriptionA) - 1);
-                    strncpy(ppd->ModuleA, desc.szDrvname, sizeof(ppd->ModuleA) - 1);
+                    lstrcpynA(ppd->DescriptionA, desc.szDesc, sizeof(ppd->DescriptionA));
+                    lstrcpynA(ppd->ModuleA, desc.szDrvname, sizeof(ppd->ModuleA));
                     MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, ppd->DescriptionW, sizeof(ppd->DescriptionW)/sizeof(WCHAR) );
                     MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, ppd->ModuleW, sizeof(ppd->ModuleW)/sizeof(WCHAR) );
                     err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDIFACE,(DWORD)&drv,0));
@@ -447,8 +447,8 @@ static HRESULT WINAPI DSPROPERTY_Description1(
                 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&(desc),0));
                 if (err == DS_OK) {
                     PIDSDRIVER drv = NULL;
-                    strncpy(ppd->DescriptionA, desc.szDesc, sizeof(ppd->DescriptionA) - 1);
-                    strncpy(ppd->ModuleA, desc.szDrvname, sizeof(ppd->ModuleA) - 1);
+                    lstrcpynA(ppd->DescriptionA, desc.szDesc, sizeof(ppd->DescriptionA));
+                    lstrcpynA(ppd->ModuleA, desc.szDrvname, sizeof(ppd->ModuleA));
                     MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, ppd->DescriptionW, sizeof(ppd->DescriptionW)/sizeof(WCHAR) );
                     MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, ppd->ModuleW, sizeof(ppd->ModuleW)/sizeof(WCHAR) );
                     err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD)&drv, 0));
@@ -480,8 +480,8 @@ static HRESULT WINAPI DSPROPERTY_Description1(
                     err = mmErr(waveInMessage((HWAVEIN)wod,DRV_QUERYDSOUNDDESC,(DWORD)&(desc),0));
                     if (err == DS_OK) {
                         PIDSDRIVER drv = NULL;
-                        strncpy(ppd->DescriptionA, desc.szDesc, sizeof(ppd->DescriptionA) - 1);
-                        strncpy(ppd->ModuleA, desc.szDrvname, sizeof(ppd->ModuleA) - 1);
+                        lstrcpynA(ppd->DescriptionA, desc.szDesc, sizeof(ppd->DescriptionA));
+                        lstrcpynA(ppd->ModuleA, desc.szDrvname, sizeof(ppd->ModuleA));
                         MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, ppd->DescriptionW, sizeof(ppd->DescriptionW)/sizeof(WCHAR) );
                         MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, ppd->ModuleW, sizeof(ppd->ModuleW)/sizeof(WCHAR) );
                         err = mmErr(waveInMessage((HWAVEIN)wod, DRV_QUERYDSOUNDIFACE, (DWORD)&drv, 0));
@@ -1005,8 +1005,8 @@ static HRESULT WINAPI DSPROPERTY_Enumerate1(
                         data.DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
                         data.WaveDeviceId = wod;
                         data.DeviceId = DSOUND_renderer_guids[wod];
-                        strncpy(data.DescriptionA, desc.szDesc, sizeof(data.DescriptionA));
-                        strncpy(data.ModuleA, desc.szDrvname, sizeof(data.ModuleA));
+                        lstrcpynA(data.DescriptionA, desc.szDesc, sizeof(data.DescriptionA));
+                        lstrcpynA(data.ModuleA, desc.szDrvname, sizeof(data.ModuleA));
 
                         MultiByteToWideChar( CP_ACP, 0, data.DescriptionA, -1, data.DescriptionW, sizeof(data.DescriptionW) );
                         MultiByteToWideChar( CP_ACP, 0, data.ModuleA, -1, data.ModuleW, sizeof(data.ModuleW) );
@@ -1024,8 +1024,8 @@ static HRESULT WINAPI DSPROPERTY_Enumerate1(
                         data.DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
                         data.WaveDeviceId = wod;
                         data.DeviceId = DSOUND_renderer_guids[wod];
-                        strncpy(data.DescriptionA, desc.szDesc, sizeof(data.DescriptionA));
-                        strncpy(data.ModuleA, desc.szDrvname, sizeof(data.ModuleA));
+                        lstrcpynA(data.DescriptionA, desc.szDesc, sizeof(data.DescriptionA));
+                        lstrcpynA(data.ModuleA, desc.szDrvname, sizeof(data.ModuleA));
 
                         MultiByteToWideChar( CP_ACP, 0, data.DescriptionA, -1, data.DescriptionW, sizeof(data.DescriptionW) );
                         MultiByteToWideChar( CP_ACP, 0, data.ModuleA, -1, data.ModuleW, sizeof(data.ModuleW) );
index 08c076df51cf06b72d9258091ed96c22f5f59e8a..05b7c4b6a0761696f763b2fb75d6275625b6ec08 100644 (file)
@@ -346,11 +346,11 @@ HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMU
        if (pDesc->dwValidData & DMUS_OBJ_CLASS)
                memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass));         
        if (pDesc->dwValidData & DMUS_OBJ_NAME)
-               strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
+               lstrcpynW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
        if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
-               strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);             
+               lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
        if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
-               strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);             
+               lstrcpynW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
        if (pDesc->dwValidData & DMUS_OBJ_VERSION)
                memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));                            
        if (pDesc->dwValidData & DMUS_OBJ_DATE)
index eab4107fbe1f713ffbcc34d4b7957d51be246319..f3a3af38d1c007bd1fc4b1d00b2307e6455acdcf 100644 (file)
@@ -67,8 +67,7 @@ static ATOM PortNameToAtom(LPCSTR lpPortName, BOOL16 add)
 {
     char buffer[256];
 
-    strncpy( buffer, lpPortName, sizeof(buffer) );
-    buffer[sizeof(buffer)-1] = 0;
+    lstrcpynA( buffer, lpPortName, sizeof(buffer) );
 
     if (buffer[0] && buffer[strlen(buffer)-1] == ':') buffer[strlen(buffer)-1] = 0;
 
index 51b0ead4b9ce250608ca24939795c204b9d7be54..e015daea4803115ee43f60fc9e1294506a18938f 100644 (file)
@@ -191,8 +191,7 @@ static int isLoopbackInterface(int fd, const char *name)
   if (name) {
     struct ifreq ifr;
 
-    strncpy(ifr.ifr_name, name, IFNAMSIZ);
-    ifr.ifr_name[IFNAMSIZ-1] = '\0';
+    lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
     if (ioctl(fd, SIOCGIFFLAGS, &ifr) == 0)
       ret = ifr.ifr_flags & IFF_LOOPBACK;
   }
@@ -245,8 +244,7 @@ static void storeInterfaceInMap(InterfaceNameMap *map, const char *name)
     /* look for new slot */
     for (ndx = 0; !stored && ndx < map->numAllocated; ndx++) {
       if (!map->table[ndx].inUse) {
-        strncpy(map->table[ndx].name, name, IFNAMSIZ);
-        map->table[ndx].name[IFNAMSIZ-1] = '\0';
+        lstrcpynA(map->table[ndx].name, name, IFNAMSIZ);
         map->table[ndx].inUse = TRUE;
         stored = TRUE;
         if (ndx >= map->nextAvailable)
@@ -467,8 +465,7 @@ DWORD getInterfaceIPAddrByName(const char *name)
     if (fd != -1) {
       struct ifreq ifr;
 
-      strncpy(ifr.ifr_name, name, IFNAMSIZ);
-      ifr.ifr_name[IFNAMSIZ-1] = '\0';
+      lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
       if (ioctl(fd, SIOCGIFADDR, &ifr) == 0)
         memcpy(&ret, ifr.ifr_addr.sa_data + 2, sizeof(DWORD));
       close(fd);
@@ -499,8 +496,7 @@ DWORD getInterfaceBCastAddrByName(const char *name)
     if (fd != -1) {
       struct ifreq ifr;
 
-      strncpy(ifr.ifr_name, name, IFNAMSIZ);
-      ifr.ifr_name[IFNAMSIZ-1] = '\0';
+      lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
       if (ioctl(fd, SIOCGIFBRDADDR, &ifr) == 0)
         memcpy(&ret, ifr.ifr_addr.sa_data + 2, sizeof(DWORD));
       close(fd);
@@ -531,8 +527,7 @@ DWORD getInterfaceMaskByName(const char *name)
     if (fd != -1) {
       struct ifreq ifr;
 
-      strncpy(ifr.ifr_name, name, IFNAMSIZ);
-      ifr.ifr_name[IFNAMSIZ-1] = '\0';
+      lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
       if (ioctl(fd, SIOCGIFNETMASK, &ifr) == 0)
         memcpy(&ret, ifr.ifr_addr.sa_data + 2, sizeof(DWORD));
       close(fd);
@@ -568,8 +563,7 @@ DWORD getInterfacePhysicalByName(const char *name, PDWORD len, PBYTE addr,
     struct ifreq ifr;
 
     memset(&ifr, 0, sizeof(struct ifreq));
-    strncpy(ifr.ifr_name, name, IFNAMSIZ);
-    ifr.ifr_name[IFNAMSIZ-1] = '\0';
+    lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
     if ((ioctl(fd, SIOCGIFHWADDR, &ifr)))
       ret = ERROR_INVALID_DATA;
     else {
@@ -813,8 +807,7 @@ DWORD getInterfaceMtuByName(const char *name, PDWORD mtu)
   if (fd != -1) {
     struct ifreq ifr;
 
-    strncpy(ifr.ifr_name, name, IFNAMSIZ);
-    ifr.ifr_name[IFNAMSIZ-1] = '\0';
+    lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
     if ((ioctl(fd, SIOCGIFMTU, &ifr)))
       ret = ERROR_INVALID_DATA;
     else {
@@ -855,8 +848,7 @@ DWORD getInterfaceStatusByName(const char *name, PDWORD status)
   if (fd != -1) {
     struct ifreq ifr;
 
-    strncpy(ifr.ifr_name, name, IFNAMSIZ);
-    ifr.ifr_name[IFNAMSIZ-1] = '\0';
+    lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
     if ((ioctl(fd, SIOCGIFFLAGS, &ifr)))
       ret = ERROR_INVALID_DATA;
     else {
@@ -940,8 +932,7 @@ char *toIPAddressString(unsigned int addr, char string[16])
 
     iAddr.s_addr = addr;
     /* extra-anal, just to make auditors happy */
-    strncpy(string, inet_ntoa(iAddr), 16);
-    string[16] = '\0';
+    lstrcpynA(string, inet_ntoa(iAddr), sizeof(string));
   }
   return string;
 }
index e7c1460cc8828bfce83d1ba763337891970541ba..838e2e91a087b7cd011311292ef11dc9b67111e2 100644 (file)
@@ -643,10 +643,9 @@ DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
               DWORD addrLen = sizeof(ptr->Address), type;
 
               /* on Win98 this is left empty, but whatever */
-              strncpy(ptr->AdapterName,
+              lstrcpynA(ptr->AdapterName,
                getInterfaceNameByIndex(table->indexes[ndx]),
-               sizeof(ptr->AdapterName));
-              ptr->AdapterName[MAX_ADAPTER_NAME_LENGTH] = '\0';
+               MAX_ADAPTER_NAME_LENGTH+1);
               getInterfacePhysicalByIndex(table->indexes[ndx], &addrLen,
                ptr->Address, &type);
               /* MS defines address length and type as UINT in some places and
index e8aa1b04e4d1ab3fedeacf35985ae93da3cb4ec8..ff9521e7fe9da2d72660180957fb4c5ca4ed16b0 100644 (file)
@@ -210,14 +210,14 @@ ATOM WINAPI AddAtom16( LPCSTR str )
 
     if (ATOM_IsIntAtomA( str, &iatom )) return iatom;
 
-    TRACE("%s\n",debugstr_a(buffer));
+    TRACE("%s\n",debugstr_a(str));
+
+    if (!(table = ATOM_GetTable( TRUE ))) return 0;
 
     /* Make a copy of the string to be sure it doesn't move in linear memory. */
     lstrcpynA( buffer, str, sizeof(buffer) );
 
     len = strlen( buffer );
-    if (!(table = ATOM_GetTable( TRUE ))) return 0;
-
     hash = ATOM_Hash( table->size, buffer, len );
     entry = table->entries[hash];
     while (entry)
@@ -242,9 +242,10 @@ ATOM WINAPI AddAtom16( LPCSTR str )
     entryPtr->next = table->entries[hash];
     entryPtr->refCount = 1;
     entryPtr->length = len;
-    /* Some applications _need_ the '\0' padding provided by this strncpy */
-    strncpy( entryPtr->str, buffer, ae_len - sizeof(ATOMENTRY) + 1 );
-    entryPtr->str[ae_len - sizeof(ATOMENTRY)] = '\0';
+    memcpy( entryPtr->str, buffer, len);
+    /* Some applications _need_ the '\0' padding provided by memset */
+    /* Note that 1 byte of the str is accounted for in the ATOMENTRY struct */
+    memset( entryPtr->str+len, 0, ae_len - sizeof(ATOMENTRY) - (len - 1));
     table->entries[hash] = entry;
     TRACE("-- new 0x%x\n", entry);
     return HANDLETOATOM( entry );
index 15f0309dcafcd681ee1d49b81131424ef8b79bbc..087cf0f53d6c1cf5865ff23cb3a7fbe36b0cd15b 100644 (file)
@@ -899,7 +899,7 @@ static INT PROFILE_GetSection( PROFILESECTION *section, LPCWSTR section_name,
 static INT PROFILE_GetSectionNames( LPWSTR buffer, UINT len )
 {
     LPWSTR buf;
-    UINT f,l;
+    UINT buflen,tmplen;
     PROFILESECTION *section;
 
     TRACE("(%p, %d)\n", buffer, len);
@@ -911,24 +911,24 @@ static INT PROFILE_GetSectionNames( LPWSTR buffer, UINT len )
         return 0;
     }
 
-    f=len-1;
+    buflen=len-1;
     buf=buffer;
     section = CurProfile->section;
     while ((section!=NULL)) {
         if (section->name[0]) {
-            l = strlenW(section->name)+1;
-            if (l > f) {
-                if (f>0) {
-                    strncpyW(buf, section->name, f-1);
-                    buf += f-1;
+            tmplen = strlenW(section->name)+1;
+            if (tmplen > buflen) {
+                if (buflen > 0) {
+                    memcpy(buf, section->name, (buflen-1) * sizeof(WCHAR));
+                    buf += buflen-1;
                     *buf++='\0';
                 }
                 *buf='\0';
                 return len-2;
             }
-            strcpyW(buf, section->name);
-            buf += l;
-            f -= l;
+            memcpy(buf, section->name, tmplen * sizeof(WCHAR));
+            buf += tmplen;
+            buflen -= tmplen;
         }
         section = section->next;
     }
@@ -1109,7 +1109,7 @@ static int PROFILE_GetPrivateProfileString( LPCWSTR section, LPCWSTR entry,
             LPWSTR p;
 
            p = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
-           strncpyW(p, def_val, len);
+           memcpy(p, def_val, len * sizeof(WCHAR));
            p[len] = '\0';
             pDefVal = p;
        }
index 83c0e7da9ba96fcac993341849c8cd8f2b470c8b..87328d652acaa8e98f387523c3e4e6177ec78c59 100644 (file)
@@ -268,8 +268,7 @@ static void     doChild(const char* file, const char* option)
         i = 0;
         while (*ptrA)
         {
-            strncpy(env_var, ptrA, MAX_LISTED_ENV_VAR - 1);
-            env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
+            lstrcpynA(env_var, ptrA, MAX_LISTED_ENV_VAR);
             childPrintf(hFile, "env%d=%s\n", i, encodeA(env_var));
             i++;
             ptrA += strlen(ptrA) + 1;
index bee75f7ae3857601434fff3ec4e4a35f1284a4c5..efe1e4814e81b0e3d3f28470c7abe05e5d9dcf9f 100644 (file)
@@ -922,7 +922,7 @@ UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
                 while (*ptr == ' ') ptr++;
                 len = ptr2-ptr;
                 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
-                strncpyW(prop,ptr,len);
+                memcpy(prop,ptr,len*sizeof(WCHAR));
                 prop[len]=0;
                 ptr2++;
            
@@ -942,7 +942,7 @@ UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
                     len -= 2;
                 }
                 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
-                strncpyW(val,ptr2,len);
+                memcpy(val,ptr2,len*sizeof(WCHAR));
                 val[len] = 0;
 
                 if (strlenW(prop) > 0)
index a6d4ab02b7983e6d9392c97745f550a0e66730b0..ca9fc65a3059a40e992e7c95fac2761fd6da44b3 100644 (file)
@@ -672,8 +672,8 @@ static UINT ACTION_SearchDirectory(MSIPACKAGE *package, MSISIGNATURE *sig,
                 pathWithDrive[0] = 'A' + i;
                 if (GetDriveTypeW(pathWithDrive) == DRIVE_FIXED)
                 {
-                    strncpyW(pathWithDrive + 3, expanded,
-                     sizeof(pathWithDrive) / sizeof(pathWithDrive[0]) - 3);
+                    lstrcpynW(pathWithDrive + 3, expanded,
+                              sizeof(pathWithDrive) / sizeof(pathWithDrive[0]) - 3);
                     if (sig->File)
                         rc = ACTION_RecurseSearchDirectory(package, &found, sig,
                          pathWithDrive, depth);
index c8cd847fc290cab8c6160dc22f5e564441662fe1..c48a6b52cde3e5feb51e45467c3122e37c1dc704 100644 (file)
@@ -131,7 +131,7 @@ static LPWSTR msi_dialog_get_style( LPCWSTR *text )
     ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
     if( !ret )
         return ret;
-    strncpyW( ret, p, len );
+    memcpy( ret, p, len*sizeof(WCHAR) );
     ret[len-1] = 0;
     return ret;
 }
index b40fe5f738e0172aabe336d46f9d05acdadba4b6..44ab9fea3d031fcaedffc54d5cc323d3108ca348 100644 (file)
@@ -252,7 +252,7 @@ static BOOL find_next_outermost_key(LPCWSTR source, DWORD len_remaining,
     *key = HeapAlloc(GetProcessHeap(),0,i*sizeof(WCHAR));
     /* do not have the [] in the key */
     i -= 1;
-    strncpyW(*key,&(*mark)[1],i);
+    memcpy(*key,&(*mark)[1],i*sizeof(WCHAR));
     (*key)[i] = 0;
 
     TRACE("Found Key %s\n",debugstr_w(*key));
index 6355066169c8d9d0d7cca8725d61eb6911bfb45d..ee95fd65f4bb1dba00830669fda0156a38ac2a95 100644 (file)
@@ -1233,7 +1233,7 @@ void _searchenv(const char* file, const char* env, char *buf)
       msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
       return;
     }
-    strncpy(curPath, penv, end - penv);
+    memcpy(curPath, penv, end - penv);
     if (curPath[end - penv] != '/' || curPath[end - penv] != '\\')
     {
       curPath[end - penv] = '\\';
index 2d5596e9b9f31c0387253880720e6f8c5cc82572..fa3b11adcf2ba2b9529a361dffe87e461e85a654 100644 (file)
@@ -821,17 +821,15 @@ DWORD WINAPI VideoCapDriverDescAndVer16(WORD nr, LPSTR buf1, WORD buf1len,
     infobuf = HeapAlloc(GetProcessHeap(), 0, infosize);
     if (GetFileVersionInfoA(fn, verhandle, infosize, infobuf)) 
     {
-        char   vbuf[200];
         /* Yes, two space behind : */
         /* FIXME: test for buflen */
-        sprintf(vbuf, "Version:  %d.%d.%d.%d\n", 
+        snprintf(buf2, buf2len, "Version:  %d.%d.%d.%d\n",
                 ((WORD*)infobuf)[0x0f],
                 ((WORD*)infobuf)[0x0e],
                 ((WORD*)infobuf)[0x11],
                 ((WORD*)infobuf)[0x10]
            );
-        TRACE("version of %s is %s\n", fn, vbuf);
-        strncpy(buf2, vbuf, buf2len);
+        TRACE("version of %s is %s\n", fn, buf2);
     }
     else 
     {
index aa579a52a4bfb159685525d603426a8b0e0052a3..f7df50aefd4638d9d29ad350550b234b6f13dcc9 100644 (file)
@@ -390,7 +390,7 @@ void* WINAPI wglGetProcAddress(LPCSTR  lpszProc) {
         OpenGL drivers (moreover, it is only useful for old 1.0 apps
         that query the glBindTextureEXT extension).
       */
-      strncpy(buf, ext_ret->glx_name, strlen(ext_ret->glx_name) - 3);
+      memcpy(buf, ext_ret->glx_name, strlen(ext_ret->glx_name) - 3);
       buf[strlen(ext_ret->glx_name) - 3] = '\0';
       TRACE(" extension not found in the Linux OpenGL library, checking against libGL bug with %s..\n", buf);
 
index 847b989f14b8017733062a4243869858cb90bd81..c1acc21001e4bd165779912605269338dd459034 100644 (file)
@@ -307,7 +307,7 @@ HRESULT DSoundRender_create(IUnknown * pUnkOuter, LPVOID * ppv)
     /* construct input pin */
     piInput.dir = PINDIR_INPUT;
     piInput.pFilter = (IBaseFilter *)pDSoundRender;
-    strncpyW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
+    lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
     hr = DSoundRender_InputPin_Construct(&piInput, DSoundRender_Sample, (LPVOID)pDSoundRender, DSoundRender_QueryAccept, &pDSoundRender->csFilter, (IPin **)&pDSoundRender->pInputPin);
 
     if (SUCCEEDED(hr))
index f14192e40e509c5929f29ad6e476f34e474eb897..1334e33e5f12e52275ccb796d1281ea955399068 100644 (file)
@@ -78,7 +78,7 @@ HRESULT Parser_Create(ParserImpl* pParser, const CLSID* pClsid, PFN_PROCESS_SAMP
     /* construct input pin */
     piInput.dir = PINDIR_INPUT;
     piInput.pFilter = (IBaseFilter *)pParser;
-    strncpyW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
+    lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
 
     hr = Parser_InputPin_Construct(&piInput, fnProcessSample, (LPVOID)pParser, fnQueryAccept, &pParser->csFilter, (IPin **)&pParser->pInputPin);
 
index ca857a1e0d4593deeb3fe7190e259125dca6b9b0..3536b967e2e15bb0f82ee974db0a5c30d0a73fb5 100644 (file)
@@ -196,10 +196,10 @@ HRESULT TransformFilter_Create(TransformFilterImpl* pTransformFilter, const CLSI
     /* construct input pin */
     piInput.dir = PINDIR_INPUT;
     piInput.pFilter = (IBaseFilter *)pTransformFilter;
-    strncpyW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
+    lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
     piOutput.dir = PINDIR_OUTPUT;
     piOutput.pFilter = (IBaseFilter *)pTransformFilter;
-    strncpyW(piOutput.achName, wcsOutputPinName, sizeof(piOutput.achName) / sizeof(piOutput.achName[0]));
+    lstrcpynW(piOutput.achName, wcsOutputPinName, sizeof(piOutput.achName) / sizeof(piOutput.achName[0]));
 
     hr = TransformFilter_InputPin_Construct(&piInput, TransformFilter_Sample, (LPVOID)pTransformFilter, TransformFilter_Input_QueryAccept, &pTransformFilter->csFilter, &pTransformFilter->ppPins[0]);
 
index 3c98af0b4cb0650582b8ff46cda40e95be5e0773..fd738c40c266959fa0aac5445ab339748f8d2d86 100644 (file)
@@ -352,7 +352,7 @@ HRESULT VideoRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
     /* construct input pin */
     piInput.dir = PINDIR_INPUT;
     piInput.pFilter = (IBaseFilter *)pVideoRenderer;
-    strncpyW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
+    lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
 
     hr = VideoRenderer_InputPin_Construct(&piInput, VideoRenderer_Sample, (LPVOID)pVideoRenderer, VideoRenderer_QueryAccept, &pVideoRenderer->csFilter, (IPin **)&pVideoRenderer->pInputPin);
 
index eb885b1905cc4248766483f943711c88be48715c..49a205ebf1c15cea8c1965b03904c49447e68671 100644 (file)
@@ -228,7 +228,7 @@ static HRESULT WAVEParser_InputPin_PreConnect(IPin * iface, IPin * pConnectPin)
 
     piOutput.dir = PINDIR_OUTPUT;
     piOutput.pFilter = (IBaseFilter *)This;
-    strncpyW(piOutput.achName, wcsOutputPinName, sizeof(piOutput.achName) / sizeof(piOutput.achName[0]));
+    lstrcpynW(piOutput.achName, wcsOutputPinName, sizeof(piOutput.achName) / sizeof(piOutput.achName[0]));
     
     hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(list), (BYTE *)&list);
     pos += sizeof(list);
index dc63ef5ed3439396e4c9f6fbf12f65545314c4a8..a2f47c79002b5ee9e03ede042248822972636c50 100644 (file)
@@ -959,15 +959,13 @@ static HCRYPTPROV new_key_container(PCHAR pszContainerName, DWORD dwFlags, PVTab
                                            destroy_key_container, (OBJECTHDR**)&pKeyContainer);
     if (hKeyContainer != (HCRYPTPROV)INVALID_HANDLE_VALUE)
     {
-        strncpy(pKeyContainer->szName, pszContainerName, MAX_PATH);
-        pKeyContainer->szName[MAX_PATH-1] = '\0';
+        lstrcpynA(pKeyContainer->szName, pszContainerName, MAX_PATH);
         pKeyContainer->dwFlags = dwFlags;
         pKeyContainer->dwEnumAlgsCtr = 0;
         pKeyContainer->hKeyExchangeKeyPair = (HCRYPTKEY)INVALID_HANDLE_VALUE;
         pKeyContainer->hSignatureKeyPair = (HCRYPTKEY)INVALID_HANDLE_VALUE;
         if (pVTable && pVTable->pszProvName) {
-            strncpy(pKeyContainer->szProvName, pVTable->pszProvName, MAX_PATH);
-            pKeyContainer->szProvName[MAX_PATH-1] = '\0';
+            lstrcpynA(pKeyContainer->szProvName, pVTable->pszProvName, MAX_PATH);
             if (!strcmp(pVTable->pszProvName, MS_DEF_PROV_A)) {
                 pKeyContainer->dwPersonality = RSAENH_PERSONALITY_BASE;
             } else if (!strcmp(pVTable->pszProvName, MS_ENHANCED_PROV_A)) {
index 820dec2e0d24e52f1f1e0dc8d443d6fd6178a68a..ed4241d59e9c70d6134e4acaa1c7467c1020a445 100644 (file)
@@ -891,7 +891,7 @@ static HDEVINFO SETUP_CreateSerialDeviceList(void)
             {
                 if (!strncmpW(comW, ptr, sizeof(comW) / sizeof(comW[0]) - 1))
                 {
-                    strncpyW(list->names[list->numPorts].name, ptr,
+                    lstrcpynW(list->names[list->numPorts].name, ptr,
                      sizeof(list->names[list->numPorts].name) /
                      sizeof(list->names[list->numPorts].name[0]));
                     TRACE("Adding %s to list\n",
index b95f75d75e66e933964763a739ce9106c52ef8ca..cc02102cb51cb488df2dfa373ebaf49552c4be08 100644 (file)
@@ -363,9 +363,7 @@ static INT_PTR sc_FNNOTIFY_A(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
     } else {
       if (mysterio[0]) {
         /* some easy paranoia.  no such carefulness exists on the wide API IIRC */
-        mysterio[SIZEOF_MYSTERIO - 1] = '\0';
-        strncpy(pfdin->psz3, &(mysterio[0]), 255);
-        mysterio[255] = '\0';
+        lstrcpynA(pfdin->psz3, &(mysterio[0]), SIZEOF_MYSTERIO);
       }
       return 0;
     }
index 30b103ed03984531efbf44ad032fd938b0375626..2ca7a584f2ab70b94c274a3ff05fec70a9874ba8 100644 (file)
@@ -168,14 +168,14 @@ LPWSTR WINAPI PathCombineW(LPWSTR lpszDest, LPCWSTR lpszDir, LPCWSTR lpszFile)
   if (!lpszFile || !*lpszFile)
   {
     /* Use dir only */
-    strncpyW(szTemp, lpszDir, MAX_PATH);
+    lstrcpynW(szTemp, lpszDir, MAX_PATH);
   }
   else if (!lpszDir || !*lpszDir || !PathIsRelativeW(lpszFile))
   {
     if (!lpszDir || !*lpszDir || *lpszFile != '\\' || PathIsUNCW(lpszFile))
     {
       /* Use file only */
-      strncpyW(szTemp, lpszFile, MAX_PATH);
+      lstrcpynW(szTemp, lpszFile, MAX_PATH);
     }
     else
     {
@@ -188,7 +188,7 @@ LPWSTR WINAPI PathCombineW(LPWSTR lpszDest, LPCWSTR lpszDir, LPCWSTR lpszFile)
 
   if (bUseBoth)
   {
-    strncpyW(szTemp, lpszDir, MAX_PATH);
+    lstrcpynW(szTemp, lpszDir, MAX_PATH);
     if (bStrip)
     {
       PathStripToRootW(szTemp);
@@ -2845,7 +2845,7 @@ BOOL WINAPI PathCompactPathW(HDC hDC, LPWSTR lpszPath, UINT dx)
        * the file name as possible, allowing for the ellipses, e.g:
        * c:\some very long path\filename ==> c:\some v...\filename
        */
-      strncpyW(buff, sFile, MAX_PATH);
+      lstrcpynW(buff, sFile, MAX_PATH);
 
       do
       {
@@ -3397,8 +3397,8 @@ BOOL WINAPI PathRelativePathToW(LPWSTR lpszPath, LPCWSTR lpszFrom, DWORD dwAttrF
     return FALSE;
 
   *lpszPath = '\0';
-  strncpyW(szFrom, lpszFrom, MAX_PATH);
-  strncpyW(szTo, lpszTo, MAX_PATH);
+  lstrcpynW(szFrom, lpszFrom, MAX_PATH);
+  lstrcpynW(szTo, lpszTo, MAX_PATH);
 
   if(!(dwAttrFrom & FILE_ATTRIBUTE_DIRECTORY))
     PathRemoveFileSpecW(szFrom);
@@ -3746,7 +3746,7 @@ BOOL WINAPI PathIsDirectoryEmptyW(LPCWSTR lpszPath)
   if (!lpszPath || !PathIsDirectoryW(lpszPath))
       return FALSE;
 
-  strncpyW(szSearch, lpszPath, MAX_PATH);
+  lstrcpynW(szSearch, lpszPath, MAX_PATH);
   PathAddBackslashW(szSearch);
   dwLen = strlenW(szSearch);
   if (dwLen > MAX_PATH - 4)
index 69894008e133a4bb0aafb03c415448d7dffce3c7..494a7e174256d70f9414177eb0821010c5d1b255 100644 (file)
@@ -1577,7 +1577,7 @@ LPSTR WINAPI StrFormatKBSizeA(LONGLONG llBytes, LPSTR lpszDest, UINT cchMax)
     ulKB = (ulKB - ulNextDigit) / 10;
   } while (ulKB > 0);
 
-  strncpy(lpszDest, szOut + 1, cchMax);
+  lstrcpynA(lpszDest, szOut + 1, cchMax);
   return lpszDest;
 }
 
@@ -1605,7 +1605,7 @@ LPWSTR WINAPI StrFormatKBSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
     ulKB = (ulKB - ulNextDigit) / 10;
   } while (ulKB > 0);
 
-  strncpyW(lpszDest, szOut + 1, cchMax);
+  lstrcpynW(lpszDest, szOut + 1, cchMax);
   return lpszDest;
 }
 
@@ -2027,7 +2027,7 @@ INT WINAPI StrFromTimeIntervalW(LPWSTR lpszStr, UINT cchMax, DWORD dwMS,
     if (iDigits) /* Always write seconds if we have significant digits */
       SHLWAPI_WriteTimeClass(szCopy, dwMS, szSec, iDigits);
 
-    strncpyW(lpszStr, szCopy, cchMax);
+    lstrcpynW(lpszStr, szCopy, cchMax);
     iRet = strlenW(lpszStr);
   }
   return iRet;
@@ -2301,7 +2301,7 @@ LPWSTR WINAPI StrFormatByteSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
   sprintfW(wszBuff, bfFormats[i].lpwszFormat, dBytes);
   wszAdd[1] = bfFormats[i].wPrefix;
   strcatW(wszBuff, wszAdd);
-  strncpyW(lpszDest, wszBuff, cchMax);
+  lstrcpynW(lpszDest, wszBuff, cchMax);
   return lpszDest;
 }
 
@@ -2638,9 +2638,6 @@ DWORD WINAPI SHAnsiToAnsi(LPCSTR lpszSrc, LPSTR lpszDst, int iLen)
 
     TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszSrc), lpszDst, iLen);
 
-    /* Our original version used lstrncpy/lstrlen, incorrectly filling up all
-     * of lpszDst with extra NULs. This version is correct, and faster too.
-     */
     lpszRet = StrCpyNXA(lpszDst, lpszSrc, iLen);
     return lpszRet - lpszDst + 1;
 }
index 3a091414242e6718a7d85c70a9f0335fbd8fa228..045f102a0c371b03a9aca83afe901af5dccf4a09 100644 (file)
@@ -329,7 +329,7 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
     DWORD EscapeFlags;
     LPWSTR lpszUrlCpy, wk1, wk2, mp, root;
     INT nByteLen, state;
-    DWORD nLen;
+    DWORD nLen, nWkLen;
 
     TRACE("(%s %p %p 0x%08lx)\n", debugstr_w(pszUrl), pszCanonicalized,
          pcchCanonicalized, dwFlags);
@@ -379,9 +379,10 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
                state = 4;
                break;
            case 3:
-               strcpyW(wk2, wk1);
-               wk1 += strlenW(wk1);
-               wk2 += strlenW(wk2);
+               nWkLen = strlenW(wk1);
+               memcpy(wk2, wk1, (nWkLen + 1) * sizeof(WCHAR));
+               wk1 += nWkLen;
+               wk2 += nWkLen;
                break;
            case 4:
                if (!isalnumW(*wk1) && (*wk1 != L'-') && (*wk1 != L'.')) {state = 3; break;}
@@ -401,13 +402,14 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
                    TRACE("wk1=%c\n", (CHAR)*wk1);
                    mp = strchrW(wk1, L'/');
                    if (!mp) {
-                       strcpyW(wk2, wk1);
-                       wk1 += strlenW(wk1);
-                       wk2 += strlenW(wk2);
+                       nWkLen = strlenW(wk1);
+                       memcpy(wk2, wk1, (nWkLen + 1) * sizeof(WCHAR));
+                       wk1 += nWkLen;
+                       wk2 += nWkLen;
                        continue;
                    }
                    nLen = mp - wk1 + 1;
-                   strncpyW(wk2, wk1, nLen);
+                   memcpy(wk2, wk1, nLen * sizeof(WCHAR));
                    wk2 += nLen;
                    wk1 += nLen;
                    if (*wk1 == L'.') {
index df50de990ae8fab763d5e9bb6becf3a55950ab45..352cbec3daf89e0a9913273173934ba782e2cf8d 100644 (file)
@@ -53,8 +53,7 @@ DWORD WINAPI tapiGetLocationInfoA(LPSTR lpszCountryCode, LPSTR lpszCityCode)
                     bufsize=sizeof(buf);
                     if( !RegQueryValueExA( hsubkey, "AreaCode", 0, &type, buf,
                                 &bufsize) && type == REG_SZ) {
-                        strncpy( lpszCityCode, (char *) buf, 8);
-                        if(bufsize > 8) lpszCityCode[7] = '\0';
+                       lstrcpynA( lpszCityCode, (char *) buf, 8);
                     } else 
                         lpszCityCode[0] = '\0';
                 }
index 10de740d8cfc8a41117112bd2840b1136574e79c..8ffc8ee2c1b82505166e5efdee34df61d7a4bd00 100644 (file)
@@ -189,8 +189,7 @@ void PSDRV_AFM2C(const AFM *afm)
     FILE    *of;
     int     i;
 
-    strncpy(buffer, afm->FontName, sizeof(buffer) - 3);
-    buffer[sizeof(buffer) - 3] = '\0';
+    lstrcpynA(buffer, afm->FontName, sizeof(buffer) - 2);
 
     for (i = 0; i < strlen(buffer); ++i)
        if (buffer[i] == '-')
index 36333b82a4713a169d84baca6890d35d232160c4..80bd8ea58b0f5b67dfbad987e916f8cbe67cff16 100644 (file)
@@ -410,6 +410,7 @@ BOOL WINAPI InternetSetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
        WCHAR *ourCookieName, *ourCookieData;
        int ourCookieNameSize;
         BOOL ret;
+
        if (!(ourCookieData = strchrW(lpCookieData, '=')))
        {
             TRACE("something terribly wrong with cookie data %s\n", 
@@ -420,7 +421,7 @@ BOOL WINAPI InternetSetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
        ourCookieData += 1;
        ourCookieName = HeapAlloc(GetProcessHeap(), 0, 
                               (ourCookieNameSize + 1)*sizeof(WCHAR));
-       strncpyW(ourCookieName, ourCookieData, ourCookieNameSize);
+       memcpy(ourCookieName, ourCookieData, ourCookieNameSize * sizeof(WCHAR));
        ourCookieName[ourCookieNameSize] = '\0';
        TRACE("setting (hacked) cookie of %s, %s\n",
                debugstr_w(ourCookieName), debugstr_w(ourCookieData));
index 6f84a717a9e3c81b1bb4a20b0342d868fc28229c..77f16a0d0759a0ba8a7047b711b54c6eaf8b7b8a 100644 (file)
@@ -2777,7 +2777,7 @@ BOOL FTP_ConvertFileProp(LPFILEPROPERTIESW lpafp, LPWIN32_FIND_DATAW lpFindFileD
            lpFindFileData->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
 
         if (lpafp->lpszName)
-            strncpyW(lpFindFileData->cFileName, lpafp->lpszName, MAX_PATH);
+            lstrcpynW(lpFindFileData->cFileName, lpafp->lpszName, MAX_PATH);
 
        bSuccess = TRUE;
     }
index e3d9f6619522d959a664d78b4508ebf779055a69..1536dc08008d189aa5b1e6802512a549f04a995e 100644 (file)
@@ -178,8 +178,7 @@ static BOOL WINAPI HTTP_HttpAddRequestHeadersW(LPWININETHTTPREQW lpwhr,
     else
         len = dwHeaderLength;
     buffer = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR)*(len+1) );
-    strncpyW( buffer, lpszHeader, len );
-    buffer[len]=0;
+    lstrcpynW( buffer, lpszHeader, len + 1);
 
     lpszStart = buffer;
 
@@ -1722,14 +1721,12 @@ BOOL WINAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
                         nDomainPosStart = strlenW(szDomain);
                         nDomainLength = (nDomainPosEnd - nDomainPosStart) + 1;
                         domain = HeapAlloc(GetProcessHeap(), 0, (nDomainLength + 1)*sizeof(WCHAR));
-                        strncpyW(domain, &lpszDomain[nDomainPosStart], nDomainLength);
-                        domain[nDomainLength] = '\0';
+                        lstrcpynW(domain, &lpszDomain[nDomainPosStart], nDomainLength + 1);
                     }
                 }
                 if (setCookieHeader->lpszValue[nPosEnd] == '\0') break;
                 buf_cookie = HeapAlloc(GetProcessHeap(), 0, ((nPosEnd - nPosStart) + 1)*sizeof(WCHAR));
-                strncpyW(buf_cookie, &setCookieHeader->lpszValue[nPosStart], (nPosEnd - nPosStart));
-                buf_cookie[(nPosEnd - nPosStart)] = '\0';
+                lstrcpynW(buf_cookie, &setCookieHeader->lpszValue[nPosStart], (nPosEnd - nPosStart) + 1);
                 TRACE("%s\n", debugstr_w(buf_cookie));
                 while (buf_cookie[nEqualPos] != '=' && buf_cookie[nEqualPos] != '\0')
                 {
@@ -1742,8 +1739,7 @@ BOOL WINAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
                 }
 
                 cookie_name = HeapAlloc(GetProcessHeap(), 0, (nEqualPos + 1)*sizeof(WCHAR));
-                strncpyW(cookie_name, buf_cookie, nEqualPos);
-                cookie_name[nEqualPos] = '\0';
+                lstrcpynW(cookie_name, buf_cookie, nEqualPos + 1);
                 cookie_data = &buf_cookie[nEqualPos + 1];
 
 
index 8c69c461d3a962e10b643e6e4956cfbf42f001a0..5044264dd908fc941f91acfe61c68c48774c25ad 100644 (file)
@@ -1163,8 +1163,7 @@ static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
         return INTERNET_SCHEME_UNKNOWN;
 
     tempBuffer=HeapAlloc(GetProcessHeap(),0,(nMaxCmp+1)*sizeof(WCHAR));
-    strncpyW(tempBuffer,lpszScheme,nMaxCmp);
-    tempBuffer[nMaxCmp]=0;
+    lstrcpynW(tempBuffer,lpszScheme,nMaxCmp+1);
     strlwrW(tempBuffer);
     if (nMaxCmp==strlenW(lpszFtp) && !strncmpW(lpszFtp, tempBuffer, nMaxCmp))
         iScheme=INTERNET_SCHEME_FTP;
index ba49a52cfd1c02aa52be63302ec9c0cb546d39fa..478dbb107cd03b5ee6c24c0d636508e98e61fb99 100644 (file)
@@ -1959,8 +1959,7 @@ INT WINAPI WSAIoctl(SOCKET s,
                         struct ifreq ifInfo;
 
                         /* Socket Status Flags */
-                        strncpy(ifInfo.ifr_name, ptr->AdapterName, IFNAMSIZ);
-                        ifInfo.ifr_name[IFNAMSIZ-1] = '\0';
+                        lstrcpynA(ifInfo.ifr_name, ptr->AdapterName, IFNAMSIZ);
                         if (ioctl(fd, SIOCGIFFLAGS, &ifInfo) < 0)
                         {
                            ERR("Error obtaining status flags for socket!\n");
index fbd51e8f088a3c31a3ac8aaaa58e7f5516cee0e0..cecb7a78ed2334f13bcdc51806f6fd1de6e3c41d 100644 (file)
@@ -145,7 +145,7 @@ static LPWSTR build_properties(struct string_list *property_list)
                        continue;
                len = value - list->str;
                *p++ = ' ';
-               strncpyW(p, list->str, len);
+               memcpy(p, list->str, len * sizeof(WCHAR));
                p += len;
                *p++ = '=';
 
@@ -155,7 +155,7 @@ static LPWSTR build_properties(struct string_list *property_list)
                if(needs_quote)
                        *p++ = '"';
                len = lstrlenW(value);
-               strncpyW(p, value, len);
+               memcpy(p, value, len * sizeof(WCHAR));
                p += len;
                if(needs_quote)
                        *p++ = '"';
index a225fc538fbd7b925b77f0584b2ef720eb2f1058..00df2bfcb554f34bc97c4978223288e6f361d8d2 100644 (file)
@@ -528,7 +528,7 @@ HKEY getRegClass(LPSTR lpClass)
     if (lpClass == NULL)
         return (HKEY)ERROR_INVALID_PARAMETER;
 
-    strncpy(lpClassCopy, lpClass, KEY_MAX_LEN);
+    lstrcpynA(lpClassCopy, lpClass, KEY_MAX_LEN);
 
     classNameEnd  = strchr(lpClassCopy, '\\');    /* The class name ends by '\' */
     if (!classNameEnd)                            /* or the whole string */
@@ -792,8 +792,7 @@ void processQueryValue(LPSTR cmdline)
 
         if (hRes == ERROR_SUCCESS) {
             lpsRes = HeapAlloc( GetProcessHeap(), 0, lLen);
-            strncpy(lpsRes, lpsData, lLen);
-            lpsRes[lLen-1]='\0';
+            lstrcpynA(lpsRes, lpsData, lLen);
         }
     } else {
         DWORD  dwLen  = KEY_MAX_LEN;
@@ -823,8 +822,7 @@ void processQueryValue(LPSTR cmdline)
             case REG_SZ:
             case REG_EXPAND_SZ: {
                     lpsRes = HeapAlloc( GetProcessHeap(), 0, dwLen);
-                    strncpy(lpsRes, lpbData, dwLen);
-                    lpsRes[dwLen-1]='\0';
+                    lstrcpynA(lpsRes, lpbData, dwLen);
                     break;
                 }
             case REG_DWORD: {
index e1f52452d3ed4af14ca14225964278291a8500f8..d81b8d2e3c68ac57ded3c894b9d6612fc92f910e 100644 (file)
@@ -230,7 +230,7 @@ void load_drives()
         WINE_TRACE("serial: '0x%lX'\n", serial);
 
         /* build rootpath for GetDriveType() */
-        strncpy(rootpath, devices, sizeof(rootpath));
+        lstrcpynA(rootpath, devices, sizeof(rootpath));
         pathlen = strlen(rootpath);
 
         /* ensure that we have a backslash on the root path */
@@ -240,8 +240,8 @@ void load_drives()
             rootpath[pathlen + 1] = 0;
         }
 
-        strncpy(simplepath, devices, 2); /* QueryDosDevice() requires no trailing backslash */
-        simplepath[2] = 0;
+       /* QueryDosDevice() requires no trailing backslash */
+        lstrcpynA(simplepath, devices, 3);
         QueryDosDevice(simplepath, targetpath, sizeof(targetpath));
 
         /* targetpath may have forward slashes rather than backslashes, so correct */
index 8065920626645961e0a3f76d6781b3d5794795f7..a9d0f5f3f19e23eb688a7bc3dd4d25a990b8f187 100644 (file)
@@ -242,8 +242,7 @@ BOOL memory_get_string(HANDLE hp, void* addr, BOOL in_debuggee, BOOL unicode,
     }
     else
     {
-        strncpy(buffer, addr, size);
-        buffer[size - 1] = 0;
+        lstrcpynA(buffer, addr, size);
     }
     return TRUE;
 }
index 13d29e441d01f64855935a012de0c2568af257db..746645599b60501283ab817da5556f28f2727907 100644 (file)
@@ -390,7 +390,7 @@ void SaveBoard( BOARD *p_board )
 
     for( i = 0; i < 3; i++ ) {
         wsprintf( key_name, "Name%u", i );
-        strncpy( data, p_board->best_name[i], sizeof( data ) );
+        lstrcpyn( data, p_board->best_name[i], sizeof( data ) );
         RegSetValueEx( hkey, key_name, 0, REG_SZ, (LPBYTE) data, strlen(data)+1 );
     }
 
index ca737050143529ebc8262a90c2cd3e16071db9a6..3f7cdbc66eb4f5b88ac4e64e59d815de9cecb03f 100644 (file)
@@ -2047,7 +2047,7 @@ static void SPY_GetMsgStuff( SPY_INSTANCE *sp_e )
             p = SPY_Bsearch_Msg (cc_array[i].classmsg, cc_array[i].lastmsg,
                                  sp_e->msgnum);
             if (p) {
-                strncpy (sp_e->msg_name, p->name, sizeof(sp_e->msg_name)-1);
+                lstrcpynA (sp_e->msg_name, p->name, sizeof(sp_e->msg_name));
                 sp_e->data_len = p->len;
                 return;
             }
@@ -2059,8 +2059,7 @@ static void SPY_GetMsgStuff( SPY_INSTANCE *sp_e )
     }
     else
     {
-        strncpy(sp_e->msg_name, msg_name, sizeof(sp_e->msg_name)-1);
-        sp_e->msg_name[sizeof(sp_e->msg_name)-1] = 0;
+        lstrcpynA(sp_e->msg_name, msg_name, sizeof(sp_e->msg_name));
     }
 }