simplify secure function usage using template overloads
Modified: trunk/reactos/subsys/system/explorer/explorer.vcproj
Modified: trunk/reactos/subsys/system/explorer/precomp.h
Modified: trunk/reactos/subsys/system/explorer/shell/fatfs.cpp
Modified: trunk/reactos/subsys/system/explorer/shell/mainframe.cpp
Modified: trunk/reactos/subsys/system/explorer/shell/pane.cpp
Modified: trunk/reactos/subsys/system/explorer/shell/regfs.cpp
Modified: trunk/reactos/subsys/system/explorer/shell/shellfs.cpp
Modified: trunk/reactos/subsys/system/explorer/taskbar/quicklaunch.cpp
Modified: trunk/reactos/subsys/system/explorer/taskbar/startmenu.cpp
Modified: trunk/reactos/subsys/system/explorer/taskbar/traynotify.cpp
Modified: trunk/reactos/subsys/system/explorer/utility/utility.cpp
Modified: trunk/reactos/subsys/system/explorer/utility/utility.h
Modified: trunk/reactos/subsys/system/explorer/utility/xmlstorage.cpp
Modified: trunk/reactos/subsys/system/explorer/utility/xmlstorage.h
_____
Modified: trunk/reactos/subsys/system/explorer/explorer.vcproj
--- trunk/reactos/subsys/system/explorer/explorer.vcproj
2005-12-01 22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/explorer.vcproj
2005-12-01 22:24:00 UTC (rev 19814)
@@ -43,7 +43,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
-
PreprocessorDefinitions="_DEBUG;UNICODE;WIN32;_WIN32_IE=0x0600;_WIN32_WI
NNT=0x0501"
+
PreprocessorDefinitions="_DEBUG;UNICODE;WIN32;_WIN32_IE=0x0600;_WIN32_WI
NNT=0x0501,_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES,_CRT_SECURE_CPP_OVERL
OAD_STANDARD_NAMES_COUNT"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
@@ -141,7 +141,7 @@
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
-
PreprocessorDefinitions="NDEBUG;UNICODE;WIN32;_WIN32_IE=0x0600;_WIN32_WI
NNT=0x0501"
+
PreprocessorDefinitions="NDEBUG;UNICODE;WIN32;_WIN32_IE=0x0600;_WIN32_WI
NNT=0x0501,_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES,_CRT_SECURE_CPP_OVERL
OAD_STANDARD_NAMES_COUNT"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
@@ -426,7 +426,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
-
PreprocessorDefinitions="_DEBUG;WIN32;_WIN32_IE=0x0600;_WIN32_WINNT=0x05
01"
+
PreprocessorDefinitions="_DEBUG;WIN32;_WIN32_IE=0x0600;_WIN32_WINNT=0x05
01,_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES,_CRT_SECURE_CPP_OVERLOAD_STAN
DARD_NAMES_COUNT"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
@@ -524,7 +524,7 @@
Name="VCCLCompilerTool"
Optimization="1"
InlineFunctionExpansion="1"
-
PreprocessorDefinitions="NDEBUG;WIN32;_WIN32_IE=0x0600;_WIN32_WINNT=0x05
01;_CRT_SECURE_NO_DEPRECATE_xx"
+
PreprocessorDefinitions="NDEBUG;WIN32;_WIN32_IE=0x0600;_WIN32_WINNT=0x05
01;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES,_CRT_SECURE_CPP_OVERLOAD_STAN
DARD_NAMES_COUNT"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
_____
Modified: trunk/reactos/subsys/system/explorer/precomp.h
--- trunk/reactos/subsys/system/explorer/precomp.h 2005-12-01
22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/precomp.h 2005-12-01
22:24:00 UTC (rev 19814)
@@ -25,6 +25,9 @@
// Martin Fuchs, 17.05.2004
//
+#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
1
+#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT 1
+
#include "utility/utility.h"
#include "explorer.h"
_____
Modified: trunk/reactos/subsys/system/explorer/shell/fatfs.cpp
--- trunk/reactos/subsys/system/explorer/shell/fatfs.cpp
2005-12-01 22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/shell/fatfs.cpp
2005-12-01 22:24:00 UTC (rev 19814)
@@ -83,7 +83,7 @@
TCHAR buffer[MAX_PATH];
- _tcscpy_s(buffer, COUNTOF(buffer), (LPCTSTR)_path);
+ _tcscpy(buffer, (LPCTSTR)_path);
LPTSTR pname = buffer + _tcslen(buffer);
int plen = COUNTOF(buffer) - _tcslen(buffer);
_____
Modified: trunk/reactos/subsys/system/explorer/shell/mainframe.cpp
--- trunk/reactos/subsys/system/explorer/shell/mainframe.cpp
2005-12-01 22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/shell/mainframe.cpp
2005-12-01 22:24:00 UTC (rev 19814)
@@ -1021,7 +1021,7 @@
if (activate_drive_window(root))
return 0;
- _tsplitpath_s(root, drv, COUNTOF(drv), 0, 0, 0, 0, 0,
0);
+ _tsplitpath_s(root, drv, COUNTOF(drv), NULL, 0, NULL, 0,
NULL, 0);
if (!SetCurrentDirectory(drv)) {
display_error(_hwnd, GetLastError());
@@ -1251,14 +1251,14 @@
TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
HWND child_wnd;
- _tsplitpath_s(path, drv1, COUNTOF(drv1), 0, 0, 0, 0, 0, 0);
+ _tsplitpath_s(path, drv1, COUNTOF(drv1), NULL, 0, NULL, 0, NULL,
0);
// search for a already open window for the same drive
for(child_wnd=::GetNextWindow(_hmdiclient,GW_CHILD); child_wnd;
child_wnd=::GetNextWindow(child_wnd, GW_HWNDNEXT)) {
FileChildWindow* child = (FileChildWindow*)
SendMessage(child_wnd, PM_GET_FILEWND_PTR, 0, 0);
if (child) {
- _tsplitpath_s(child->get_root()._path, drv2,
COUNTOF(drv2), 0, 0, 0, 0, 0, 0);
+ _tsplitpath_s(child->get_root()._path, drv2,
COUNTOF(drv2), NULL, 0, NULL, 0, NULL, 0);
if (!lstrcmpi(drv2, drv1)) {
SendMessage(_hmdiclient, WM_MDIACTIVATE,
(WPARAM)child_wnd, 0);
_____
Modified: trunk/reactos/subsys/system/explorer/shell/pane.cpp
--- trunk/reactos/subsys/system/explorer/shell/pane.cpp 2005-12-01
22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/shell/pane.cpp 2005-12-01
22:24:00 UTC (rev 19814)
@@ -501,7 +501,7 @@
if (visible_cols & COL_SIZE) {
ULONGLONG size = ((ULONGLONG)entry->_data.nFileSizeHigh
<< 32) | entry->_data.nFileSizeLow;
- _stprintf_s1(buffer, BUFFER_LEN, TEXT("%") LONGLONGARG
TEXT("d"), size);
+ _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("d"),
size);
if (calcWidthCol == -1)
_out_wrkr.output_number(dis, _positions, col,
buffer);
@@ -539,7 +539,7 @@
ULONGLONG index =
((ULONGLONG)entry->_bhfi.nFileIndexHigh << 32) |
entry->_bhfi.nFileIndexLow;
if (visible_cols & COL_INDEX) {
- _stprintf_s1(buffer, BUFFER_LEN, TEXT("%")
LONGLONGARG TEXT("X"), index);
+ _stprintf(buffer, TEXT("%") LONGLONGARG
TEXT("X"), index);
if (calcWidthCol == -1)
_out_wrkr.output_text(dis, _positions,
col, buffer, DT_RIGHT);
_____
Modified: trunk/reactos/subsys/system/explorer/shell/regfs.cpp
--- trunk/reactos/subsys/system/explorer/shell/regfs.cpp
2005-12-01 22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/shell/regfs.cpp
2005-12-01 22:24:00 UTC (rev 19814)
@@ -40,7 +40,7 @@
TCHAR buffer[MAX_PATH];
- _tcscpy_s(buffer, COUNTOF(buffer), (LPCTSTR)_path);
+ _tcscpy(buffer, (LPCTSTR)_path);
LPTSTR pname = buffer + _tcslen(buffer);
int plen = MAX_PATH - _tcslen(buffer);
@@ -65,7 +65,7 @@
break;
w32fd.dwFileAttributes |=
FILE_ATTRIBUTE_DIRECTORY;
- _tcsncpy_s(w32fd.cFileName,
COUNTOF(w32fd.cFileName), name, name_len);
+ _tcsncpy(w32fd.cFileName, name, name_len);
_tcscpy_s(pname, plen, name);
entry = new RegDirectory(this, buffer,
_hKeyRoot);
@@ -153,7 +153,7 @@
entry->_content =
_tcsdup(value);
else if (type == REG_DWORD) {
TCHAR b[32];
- _stprintf_s1(b, COUNTOF(b),
TEXT("%ld"), *(DWORD*)&value);
+ _stprintf(b, TEXT("%ld"),
*(DWORD*)&value);
entry->_content = _tcsdup(b);
}
}
@@ -254,49 +254,49 @@
_data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
entry = new RegDirectory(this, TEXT("\\"), HKEY_CURRENT_USER);
- _tcscpy_s(entry->_data.cFileName,
COUNTOF(entry->_data.cFileName), TEXT("HKEY_CURRENT_USER"));
+ _tcscpy(entry->_data.cFileName, TEXT("HKEY_CURRENT_USER"));
entry->_level = level;
first_entry = entry;
last = entry;
entry = new RegDirectory(this, TEXT("\\"), HKEY_LOCAL_MACHINE);
- _tcscpy_s(entry->_data.cFileName,
COUNTOF(entry->_data.cFileName), TEXT("HKEY_LOCAL_MACHINE"));
+ _tcscpy(entry->_data.cFileName, TEXT("HKEY_LOCAL_MACHINE"));
entry->_level = level;
last->_next = entry;
last = entry;
entry = new RegDirectory(this, TEXT("\\"), HKEY_CLASSES_ROOT);
- _tcscpy_s(entry->_data.cFileName,
COUNTOF(entry->_data.cFileName), TEXT("HKEY_CLASSES_ROOT"));
+ _tcscpy(entry->_data.cFileName, TEXT("HKEY_CLASSES_ROOT"));
entry->_level = level;
last->_next = entry;
last = entry;
entry = new RegDirectory(this, TEXT("\\"), HKEY_USERS);
- _tcscpy_s(entry->_data.cFileName,
COUNTOF(entry->_data.cFileName), TEXT("HKEY_USERS"));
+ _tcscpy(entry->_data.cFileName, TEXT("HKEY_USERS"));
entry->_level = level;
last->_next = entry;
last = entry;
/*
entry = new RegDirectory(this, TEXT("\\"),
HKEY_PERFORMANCE_DATA);
- _tcscpy_s(entry->_data.cFileName,
COUNTOF(entry->_data.cFileName), TEXT("HKEY_PERFORMANCE_DATA"));
+ _tcscpy(entry->_data.cFileName, TEXT("HKEY_PERFORMANCE_DATA"));
entry->_level = level;
last->_next = entry;
last = entry;
*/
entry = new RegDirectory(this, TEXT("\\"), HKEY_CURRENT_CONFIG);
- _tcscpy_s(entry->_data.cFileName,
COUNTOF(entry->_data.cFileName), TEXT("HKEY_CURRENT_CONFIG"));
+ _tcscpy(entry->_data.cFileName, TEXT("HKEY_CURRENT_CONFIG"));
entry->_level = level;
last->_next = entry;
last = entry;
/*
entry = new RegDirectory(this, TEXT("\\"), HKEY_DYN_DATA);
- _tcscpy_s(entry->_data.cFileName,
COUNTOF(entry->_data.cFileName), TEXT("HKEY_DYN_DATA"));
+ _tcscpy(entry->_data.cFileName, TEXT("HKEY_DYN_DATA"));
entry->_level = level;
last->_next = entry;
_____
Modified: trunk/reactos/subsys/system/explorer/shell/shellfs.cpp
--- trunk/reactos/subsys/system/explorer/shell/shellfs.cpp
2005-12-01 22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/shell/shellfs.cpp
2005-12-01 22:24:00 UTC (rev 19814)
@@ -61,7 +61,7 @@
if (path) {
// fill with drive names "C:",
...
assert(_tcslen(path) <
GlobalSize(medium.UNION_MEMBER(hGlobal)));
- _tcscpy_s(pw32fdata->cFileName,
COUNTOF(pw32fdata->cFileName), path);
+ _tcscpy(pw32fdata->cFileName,
path);
UINT sem_org =
SetErrorMode(SEM_FAILCRITICALERRORS);
@@ -412,7 +412,7 @@
if
(SUCCEEDED(name_from_pidl(_folder, pidls[n], name, COUNTOF(name),
SHGDN_INFOLDER|0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/))) {
if
(!entry->_data.cFileName[0])
-
_tcscpy_s(entry->_data.cFileName, COUNTOF(entry->_data.cFileName),
name);
+
_tcscpy(entry->_data.cFileName, name);
else if
(_tcscmp(entry->_display_name, name))
entry->_display_name = _tcsdup(name); // store display name separate
from file name; sort display by file name
}
_____
Modified: trunk/reactos/subsys/system/explorer/taskbar/quicklaunch.cpp
--- trunk/reactos/subsys/system/explorer/taskbar/quicklaunch.cpp
2005-12-01 22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/taskbar/quicklaunch.cpp
2005-12-01 22:24:00 UTC (rev 19814)
@@ -100,7 +100,7 @@
SpecialFolderFSPath app_data(CSIDL_APPDATA, _hwnd);
///@todo perhaps also look into CSIDL_COMMON_APPDATA ?
- _stprintf_s1(path, COUNTOF(path),
TEXT("%s\\")QUICKLAUNCH_FOLDER, (LPCTSTR)app_data);
+ _stprintf(path, TEXT("%s\\")QUICKLAUNCH_FOLDER,
(LPCTSTR)app_data);
RecursiveCreateDirectory(path);
_dir = new ShellDirectory(GetDesktopFolder(), path,
_hwnd);
_____
Modified: trunk/reactos/subsys/system/explorer/taskbar/startmenu.cpp
--- trunk/reactos/subsys/system/explorer/taskbar/startmenu.cpp
2005-12-01 22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/taskbar/startmenu.cpp
2005-12-01 22:24:00 UTC (rev 19814)
@@ -250,8 +250,8 @@
if (!ignore.empty()) {
_tsplitpath_s(ignore, ignore_path, COUNTOF(ignore_path),
ignore_dir, COUNTOF(ignore_dir), ignore_name, COUNTOF(ignore_name),
ignore_ext, COUNTOF(ignore_ext));
- _tcscat_s(ignore_path, COUNTOF(ignore_path),
ignore_dir);
- _tcscat_s(ignore_name, COUNTOF(ignore_path),
ignore_ext);
+ _tcscat(ignore_path, ignore_dir);
+ _tcscat(ignore_name, ignore_ext);
dir.get_path(dir_path, COUNTOF(dir_path));
_____
Modified: trunk/reactos/subsys/system/explorer/taskbar/traynotify.cpp
--- trunk/reactos/subsys/system/explorer/taskbar/traynotify.cpp
2005-12-01 22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/taskbar/traynotify.cpp
2005-12-01 22:24:00 UTC (rev 19814)
@@ -1285,7 +1285,7 @@
TCHAR buffer[8];
if (!GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, NULL,
NULL, buffer, sizeof(buffer)/sizeof(TCHAR)))
- _tcscpy_s(buffer, COUNTOF(buffer), TEXT("00:00"));
+ _tcscpy(buffer, TEXT("00:00"));
DrawText(canvas, buffer, -1, &rect,
DT_SINGLELINE|DT_NOPREFIX|DT_CALCRECT);
int clockwindowWidth = rect.right-rect.left + 4;
@@ -1324,7 +1324,7 @@
GetLocalTime(&systime);
if (GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE,
&systime, NULL, buffer, 64))
- _tcscpy_s(pdi->szText, COUNTOF(pdi->szText),
buffer);
+ _tcscpy(pdi->szText, buffer);
else
pdi->szText[0] = '\0';
}
@@ -1344,7 +1344,7 @@
if (GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, NULL,
NULL, buffer, sizeof(buffer)/sizeof(TCHAR)))
if (_tcscmp(buffer, _time)) {
- _tcscpy_s(_time, COUNTOF(_time), buffer);
+ _tcscpy(_time, buffer);
return true; // The text to display has
changed.
}
_____
Modified: trunk/reactos/subsys/system/explorer/utility/utility.cpp
--- trunk/reactos/subsys/system/explorer/utility/utility.cpp
2005-12-01 22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/utility/utility.cpp
2005-12-01 22:24:00 UTC (rev 19814)
@@ -393,7 +393,7 @@
{
TCHAR path[MAX_PATH], hole_path[MAX_PATH];
- _tcscpy_s(hole_path, COUNTOF(hole_path), path_in);
+ _tcscpy(hole_path, path_in);
int drv_len = 0;
LPCTSTR d;
@@ -418,7 +418,7 @@
HANDLE hFind = FindFirstFile(hole_path, &w32fd);
if (hFind == INVALID_HANDLE_VALUE) {
- _tcsncpy_s(path, COUNTOF(path), hole_path, drv_len);
+ _tcsncpy(path, hole_path, drv_len);
int i = drv_len;
for(p=dir; *p=='/'||*p=='\\'; p++)
@@ -521,7 +521,7 @@
TCHAR drv[_MAX_DRIVE], dir[_MAX_DIR],
fname[_MAX_FNAME], ext[_MAX_EXT];
_tsplitpath_s(path, drv, COUNTOF(drv), dir,
COUNTOF(dir), fname, COUNTOF(fname), ext, COUNTOF(ext));
- _stprintf_s2(path, COUNTOF(path), TEXT("%s%s"),
drv, dir);
+ _stprintf(path, TEXT("%s%s"), drv, dir);
fname_out.printf(TEXT("%s%s"), fname, ext);
}
_____
Modified: trunk/reactos/subsys/system/explorer/utility/utility.h
--- trunk/reactos/subsys/system/explorer/utility/utility.h
2005-12-01 22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/utility/utility.h
2005-12-01 22:24:00 UTC (rev 19814)
@@ -69,7 +69,11 @@
#define for if (0) {} else for
+#ifdef _countof
+#define COUNTOF _countof
+#else
#define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
+#endif
#define BUFFER_LEN 2048
@@ -169,12 +173,6 @@
// secure CRT functions
#ifdef __STDC_WANT_SECURE_LIB__ // for VS 2005: _MSC_VER>=1400
-#undef _vsntprintf
-#define _vsntprintf(b, s, f, l) _vsntprintf_s(b, s, s, f, l)
-
-#undef _sntprintf
-#define _sntprintf(b, s, f, l) _sntprintf_s(b, s, s, f, l)
-
#define _stprintf_s1 _stprintf_s
#define _stprintf_s2 _stprintf_s
@@ -182,9 +180,7 @@
#define strcpy_s(d, l, s) strcpy(d, s)
#define _tcscpy_s(d, l, s) _tcscpy(d, s)
-#define _tcscat_s(d, l, s) _tcscat(d, s)
#define wcsncpy_s(d, l, s, n) wcsncpy(d, s, n)
-#define _tcsncpy_s(d, l, s, n) _tcsncpy(d, s, n)
#define _stprintf_s1(b, l, f, p1) _stprintf(b, f, p1)
#define _stprintf_s2(b, l, f, p1,p2) _stprintf(b, f, p1,p2)
#define _tsplitpath_s(f, d,dl, p,pl, n,nl, e,el) _tsplitpath(f, d, p,
n, e)
_____
Modified: trunk/reactos/subsys/system/explorer/utility/xmlstorage.cpp
--- trunk/reactos/subsys/system/explorer/utility/xmlstorage.cpp
2005-12-01 22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/utility/xmlstorage.cpp
2005-12-01 22:24:00 UTC (rev 19814)
@@ -492,7 +492,7 @@
default:
if ((unsigned)*p<20 && *p!='\t' && *p!='\r'
&&
*p!='\n') {
char b[16];
- sprintf_s1(b, COUNTOF(b), "&%d;",
(unsigned)*p);
+ sprintf(b, "&%d;", (unsigned)*p);
for(const char*q=b; *q; )
*o++ = *q++;
} else
_____
Modified: trunk/reactos/subsys/system/explorer/utility/xmlstorage.h
--- trunk/reactos/subsys/system/explorer/utility/xmlstorage.h
2005-12-01 22:15:57 UTC (rev 19813)
+++ trunk/reactos/subsys/system/explorer/utility/xmlstorage.h
2005-12-01 22:24:00 UTC (rev 19814)
@@ -71,14 +71,6 @@
namespace XMLStorage {
- // secure CRT functions
-#ifdef __STDC_WANT_SECURE_LIB__ // VS 2005
-#define sprintf_s1 sprintf_s
-#else
-#define sprintf_s1(b, l, f, p1) sprintf(b, f, p1)
-#endif
-
-
#ifndef XS_String
#ifdef XS_STRING_UTF8
@@ -282,7 +274,7 @@
{
FileHolder(LPCTSTR path, LPCTSTR mode)
{
-#ifdef __STDC_WANT_SECURE_LIB__ // VS2005
+#ifdef __STDC_WANT_SECURE_LIB__ // secure CRT functions using VS
2005
if (_tfopen_s(&_pfile, path, mode) != 0)
_pfile = NULL;
#else