[dlls/dm*] Strncpy elimation.
Peter Berg Larsen
pebl at math.ku.dk
Sun Mar 27 11:53:59 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/dmband/band.c
===================================================================
RCS file: /home/wine/wine/dlls/dmband/band.c,v
retrieving revision 1.16
diff -u -r1.16 band.c
--- dlls/dmband/band.c 23 Mar 2005 13:15:20 -0000 1.16
+++ dlls/dmband/band.c 26 Mar 2005 09:40:12 -0000
@@ -163,11 +163,11 @@
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: dlls/dmcompos/chordmap.c
===================================================================
RCS file: /home/wine/wine/dlls/dmcompos/chordmap.c,v
retrieving revision 1.11
diff -u -r1.11 chordmap.c
--- dlls/dmcompos/chordmap.c 12 Jan 2005 19:26:42 -0000 1.11
+++ dlls/dmcompos/chordmap.c 26 Mar 2005 09:40:13 -0000
@@ -147,11 +147,11 @@
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: dlls/dmime/audiopath.c
===================================================================
RCS file: /home/wine/wine/dlls/dmime/audiopath.c,v
retrieving revision 1.15
diff -u -r1.15 audiopath.c
--- dlls/dmime/audiopath.c 2 Feb 2005 09:31:07 -0000 1.15
+++ dlls/dmime/audiopath.c 26 Mar 2005 09:40:14 -0000
@@ -262,11 +262,11 @@
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: dlls/dmime/graph.c
===================================================================
RCS file: /home/wine/wine/dlls/dmime/graph.c,v
retrieving revision 1.12
diff -u -r1.12 graph.c
--- dlls/dmime/graph.c 2 Feb 2005 09:31:07 -0000 1.12
+++ dlls/dmime/graph.c 26 Mar 2005 09:40:16 -0000
@@ -228,11 +228,11 @@
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: dlls/dmime/segment.c
===================================================================
RCS file: /home/wine/wine/dlls/dmime/segment.c,v
retrieving revision 1.22
diff -u -r1.22 segment.c
--- dlls/dmime/segment.c 2 Feb 2005 09:31:07 -0000 1.22
+++ dlls/dmime/segment.c 26 Mar 2005 09:40:18 -0000
@@ -548,11 +548,11 @@
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: dlls/dmloader/container.c
===================================================================
RCS file: /home/wine/wine/dlls/dmloader/container.c,v
retrieving revision 1.12
diff -u -r1.12 container.c
--- dlls/dmloader/container.c 9 Jan 2005 16:42:53 -0000 1.12
+++ dlls/dmloader/container.c 26 Mar 2005 09:40:19 -0000
@@ -77,7 +77,7 @@
ICOM_THIS_MULTI(IDirectMusicContainerImpl, ContainerVtbl, iface);
struct list *pEntry;
LPWINE_CONTAINER_ENTRY pContainedObject;
- DWORD dwCount = 0;
+ DWORD dwLength, dwCount = 0;
TRACE("(%p, %s, %ld, %p, %p)\n", This, debugstr_dmguid(rguidClass), dwIndex, pDesc, pwszAlias);
@@ -111,8 +111,9 @@
if (dwCount == dwIndex) {
HRESULT result = S_OK;
if (pwszAlias) {
- strncpyW (pwszAlias, pContainedObject->wszAlias, DMUS_MAX_FILENAME);
- if (strlenW (pContainedObject->wszAlias) > DMUS_MAX_FILENAME)
+ dwLength = strlenW (pContainedObject->wszAlias);
+ memcpy (pwszAlias, pContainedObject->wszAlias, min(dwLength+1,DMUS_MAX_FILENAME) * sizeof(WCHAR));
+ if (dwLength > DMUS_MAX_FILENAME)
result = DMUS_S_STRING_TRUNCATED;
}
if (pDesc)
@@ -199,15 +200,15 @@
dwNewFlags |= DMUS_OBJ_OBJECT;
}
if (pDesc->dwValidData & DMUS_OBJ_NAME) {
- strncpyW (This->Desc.wszName, pDesc->wszName, DMUS_MAX_NAME);
+ lstrcpynW (This->Desc.wszName, pDesc->wszName, DMUS_MAX_NAME);
dwNewFlags |= DMUS_OBJ_NAME;
}
if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) {
- strncpyW (This->Desc.wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
+ lstrcpynW (This->Desc.wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
dwNewFlags |= DMUS_OBJ_CATEGORY;
}
if (pDesc->dwValidData & (DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH))
{
- strncpyW (This->Desc.wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
+ lstrcpynW (This->Desc.wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
dwNewFlags |= (pDesc->dwValidData & (DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH));
}
if (pDesc->dwValidData & DMUS_OBJ_VERSION) {
Index: dlls/dmloader/loaderstream.c
===================================================================
RCS file: /home/wine/wine/dlls/dmloader/loaderstream.c,v
retrieving revision 1.13
diff -u -r1.13 loaderstream.c
--- dlls/dmloader/loaderstream.c 22 Dec 2004 15:13:20 -0000 1.13
+++ dlls/dmloader/loaderstream.c 26 Mar 2005 09:40:20 -0000
@@ -67,7 +67,7 @@
}
/* create IDirectMusicGetLoader */
This->pLoader = (LPDIRECTMUSICLOADER8)pLoader;
- strncpyW (This->wzFileName, wzFile, MAX_PATH);
+ lstrcpynW (This->wzFileName, wzFile, MAX_PATH);
TRACE(": succeeded\n");
return S_OK;
}
Index: dlls/dmscript/script.c
===================================================================
RCS file: /home/wine/wine/dlls/dmscript/script.c,v
retrieving revision 1.19
diff -u -r1.19 script.c
--- dlls/dmscript/script.c 2 Feb 2005 09:31:28 -0000 1.19
+++ dlls/dmscript/script.c 26 Mar 2005 09:40:21 -0000
@@ -226,11 +226,11 @@
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: dlls/dmstyle/style.c
===================================================================
RCS file: /home/wine/wine/dlls/dmstyle/style.c,v
retrieving revision 1.14
diff -u -r1.14 style.c
--- dlls/dmstyle/style.c 24 Jan 2005 19:33:23 -0000 1.14
+++ dlls/dmstyle/style.c 26 Mar 2005 09:40:23 -0000
@@ -230,11 +230,11 @@
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)
More information about the wine-patches
mailing list