[dlls/shell32/*] Strncpy elimination.
Peter Berg Larsen
pebl at math.ku.dk
Sun Mar 27 12:13:06 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/shell32/shelllink.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shelllink.c,v
retrieving revision 1.87
diff -u -r1.87 shelllink.c
--- dlls/shell32/shelllink.c 24 Mar 2005 21:01:37 -0000 1.87
+++ dlls/shell32/shelllink.c 26 Mar 2005 09:41:13 -0000
@@ -929,7 +929,7 @@
memset( &buffer, 0, sizeof buffer );
buffer.size = sizeof buffer;
buffer.magic = magic;
- strncpyW( buffer.bufW, string, MAX_PATH );
+ lstrcpynW( buffer.bufW, string, MAX_PATH );
WideCharToMultiByte(CP_ACP, 0, string, -1, buffer.bufA, MAX_PATH, NULL, NULL );
return IStream_Write( stm, &buffer, buffer.size, &count );
Index: dlls/shell32/shellpath.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shellpath.c,v
retrieving revision 1.100
diff -u -r1.100 shellpath.c
--- dlls/shell32/shellpath.c 16 Mar 2005 11:37:46 -0000 1.100
+++ dlls/shell32/shellpath.c 26 Mar 2005 09:41:15 -0000
@@ -1210,7 +1210,7 @@
WCHAR szTemp[MAX_PATH];
_SHExpandEnvironmentStrings(path, szTemp);
- strncpyW(path, szTemp, MAX_PATH);
+ lstrcpynW(path, szTemp, MAX_PATH);
}
ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ,
(LPBYTE)path,
(strlenW(path) + 1) * sizeof(WCHAR));
@@ -1493,12 +1493,12 @@
else
{
/* Missing or invalid value, set a default */
- strncpyW(szValue, szDefault, MAX_PATH);
- szValue[MAX_PATH - 1] = '\0';
+ lstrcpynW(szValue, szDefault, MAX_PATH);
TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName),
- debugstr_w(szValue));
+ debugstr_w(szValue));
lRet = RegSetValueExW(profilesKey, szValueName, 0, REG_EXPAND_SZ,
- (LPBYTE)szValue, (strlenW(szValue) + 1) * sizeof(WCHAR));
+ (LPBYTE)szValue,
+ (strlenW(szValue) + 1) * sizeof(WCHAR));
if (lRet)
hr = HRESULT_FROM_WIN32(lRet);
else
Index: dlls/shell32/shlexec.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shlexec.c,v
retrieving revision 1.62
diff -u -r1.62 shlexec.c
--- dlls/shell32/shlexec.c 23 Mar 2005 13:15:19 -0000 1.62
+++ dlls/shell32/shlexec.c 26 Mar 2005 09:41:17 -0000
@@ -1218,8 +1218,7 @@
LPWSTR beg = wszApplicationName/*sei_tmp.lpFile*/;
for(s=beg; (space=strchrW(s, ' ')); s=space+1) {
int idx = space-sei_tmp.lpFile;
- strncpyW(buffer, sei_tmp.lpFile, idx);
- buffer[idx] = '\0';
+ lstrcpynW(buffer, sei_tmp.lpFile, idx+1);
/*FIXME This finds directory paths if the targeted file name contains spaces. */
if (SearchPathW(*sei_tmp.lpDirectory? sei_tmp.lpDirectory: NULL, buffer, wszExe, sizeof(xlpFile), xlpFile, NULL))
@@ -1296,7 +1295,7 @@
TRACE("Got URL: %s\n", debugstr_w(lpFile));
/* Looking for ...protocol\shell\lpOperation\command */
- strncpyW(lpstrProtocol, lpFile, iSize);
+ memcpy(lpstrProtocol, lpFile, iSize*sizeof(WCHAR));
lpstrProtocol[iSize] = '\0';
strcatW(lpstrProtocol, wShell);
strcatW(lpstrProtocol, sei_tmp.lpVerb? sei_tmp.lpVerb: wszOpen);
Index: dlls/shell32/systray.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/systray.c,v
retrieving revision 1.28
diff -u -r1.28 systray.c
--- dlls/shell32/systray.c 6 Dec 2004 11:51:29 -0000 1.28
+++ dlls/shell32/systray.c 26 Mar 2005 09:41:18 -0000
@@ -256,8 +256,7 @@
{
TTTOOLINFOA ti;
- strncpy(ptrayItem->notifyIcon.szTip, szTip, sizeof(ptrayItem->notifyIcon.szTip));
- ptrayItem->notifyIcon.szTip[sizeof(ptrayItem->notifyIcon.szTip)-1]=0;
+ lstrcpynA(ptrayItem->notifyIcon.szTip, szTip, sizeof(ptrayItem->notifyIcon.szTip));
ti.cbSize = sizeof(TTTOOLINFOA);
ti.uFlags = 0;
More information about the wine-patches
mailing list