[dlls/shlwapi/*] Strncpy elimination.
Peter Berg Larsen
pebl at math.ku.dk
Sun Mar 27 12:14:20 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/shlwapi/path.c
===================================================================
RCS file: /home/wine/wine/dlls/shlwapi/path.c,v
retrieving revision 1.51
diff -u -r1.51 path.c
--- dlls/shlwapi/path.c 14 Mar 2005 10:09:53 -0000 1.51
+++ dlls/shlwapi/path.c 26 Mar 2005 09:41:21 -0000
@@ -168,14 +168,14 @@
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 @@
if (bUseBoth)
{
- strncpyW(szTemp, lpszDir, MAX_PATH);
+ lstrcpynW(szTemp, lpszDir, MAX_PATH);
if (bStrip)
{
PathStripToRootW(szTemp);
@@ -2845,7 +2845,7 @@
* 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 @@
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 @@
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: dlls/shlwapi/url.c
===================================================================
RCS file: /home/wine/wine/dlls/shlwapi/url.c,v
retrieving revision 1.49
diff -u -r1.49 url.c
--- dlls/shlwapi/url.c 24 Mar 2005 21:01:37 -0000 1.49
+++ dlls/shlwapi/url.c 26 Mar 2005 09:41:24 -0000
@@ -329,7 +329,7 @@
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 @@
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 @@
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'.') {
More information about the wine-patches
mailing list