simplify secure function usage using template overloads
authorMartin Fuchs <fuchs.martin@gmail.com>
Thu, 1 Dec 2005 22:24:00 +0000 (22:24 +0000)
committerMartin Fuchs <fuchs.martin@gmail.com>
Thu, 1 Dec 2005 22:24:00 +0000 (22:24 +0000)
svn path=/trunk/; revision=19814

14 files changed:
reactos/subsys/system/explorer/explorer.vcproj
reactos/subsys/system/explorer/precomp.h
reactos/subsys/system/explorer/shell/fatfs.cpp
reactos/subsys/system/explorer/shell/mainframe.cpp
reactos/subsys/system/explorer/shell/pane.cpp
reactos/subsys/system/explorer/shell/regfs.cpp
reactos/subsys/system/explorer/shell/shellfs.cpp
reactos/subsys/system/explorer/taskbar/quicklaunch.cpp
reactos/subsys/system/explorer/taskbar/startmenu.cpp
reactos/subsys/system/explorer/taskbar/traynotify.cpp
reactos/subsys/system/explorer/utility/utility.cpp
reactos/subsys/system/explorer/utility/utility.h
reactos/subsys/system/explorer/utility/xmlstorage.cpp
reactos/subsys/system/explorer/utility/xmlstorage.h

index e9b2b4b..277c497 100644 (file)
@@ -43,7 +43,7 @@
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               PreprocessorDefinitions="_DEBUG;UNICODE;WIN32;_WIN32_IE=0x0600;_WIN32_WINNT=0x0501"\r
+                               PreprocessorDefinitions="_DEBUG;UNICODE;WIN32;_WIN32_IE=0x0600;_WIN32_WINNT=0x0501,_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES,_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT"\r
                                MinimalRebuild="true"\r
                                BasicRuntimeChecks="3"\r
                                RuntimeLibrary="3"\r
                                Name="VCCLCompilerTool"\r
                                Optimization="2"\r
                                InlineFunctionExpansion="1"\r
-                               PreprocessorDefinitions="NDEBUG;UNICODE;WIN32;_WIN32_IE=0x0600;_WIN32_WINNT=0x0501"\r
+                               PreprocessorDefinitions="NDEBUG;UNICODE;WIN32;_WIN32_IE=0x0600;_WIN32_WINNT=0x0501,_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES,_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT"\r
                                StringPooling="true"\r
                                RuntimeLibrary="2"\r
                                EnableFunctionLevelLinking="true"\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               PreprocessorDefinitions="_DEBUG;WIN32;_WIN32_IE=0x0600;_WIN32_WINNT=0x0501"\r
+                               PreprocessorDefinitions="_DEBUG;WIN32;_WIN32_IE=0x0600;_WIN32_WINNT=0x0501,_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES,_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT"\r
                                MinimalRebuild="true"\r
                                BasicRuntimeChecks="3"\r
                                RuntimeLibrary="3"\r
                                Name="VCCLCompilerTool"\r
                                Optimization="1"\r
                                InlineFunctionExpansion="1"\r
-                               PreprocessorDefinitions="NDEBUG;WIN32;_WIN32_IE=0x0600;_WIN32_WINNT=0x0501;_CRT_SECURE_NO_DEPRECATE_xx"\r
+                               PreprocessorDefinitions="NDEBUG;WIN32;_WIN32_IE=0x0600;_WIN32_WINNT=0x0501;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES,_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT"\r
                                StringPooling="true"\r
                                RuntimeLibrary="2"\r
                                EnableFunctionLevelLinking="true"\r
index fae6bd3..8c68b84 100644 (file)
@@ -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"
index 110550d..8750637 100644 (file)
@@ -83,7 +83,7 @@ void FATDirectory::read_directory(int scan_flags)
 
        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);
 
index e2388ab..ed7612c 100644 (file)
@@ -1021,7 +1021,7 @@ int MDIMainFrame::Command(int id, int code)
                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 @@ bool MDIMainFrame::activate_drive_window(LPCTSTR path)
        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);
index 7deeae8..d8e4630 100644 (file)
@@ -501,7 +501,7 @@ void Pane::draw_item(LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
        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 @@ void Pane::draw_item(LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
                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);
index b4d7372..32567b6 100644 (file)
@@ -40,7 +40,7 @@ void RegDirectory::read_directory(int scan_flags)
 
        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 @@ void RegDirectory::read_directory(int scan_flags)
                                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 @@ void RegDirectory::read_directory(int scan_flags)
                                        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 @@ void RegistryRoot::read_directory(int scan_flags)
        _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;
index 72b018a..04936d0 100644 (file)
@@ -61,7 +61,7 @@ bool ShellDirectory::fill_w32fdata_shell(LPCITEMIDLIST pidl, SFGAOF attribs, WIN
                                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 @@ void ShellDirectory::read_directory(int scan_flags)
 
                                        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
                                        }
index f511339..9de2bf9 100644 (file)
@@ -100,7 +100,7 @@ void QuickLaunchBar::AddShortcuts()
 
                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);
index 026aa89..d125902 100644 (file)
@@ -250,8 +250,8 @@ void StartMenu::AddShellEntries(const ShellDirectory& dir, int max, const String
        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));
 
index 86dd419..d8878cf 100644 (file)
@@ -1285,7 +1285,7 @@ HWND ClockWindow::Create(HWND hwndParent)
        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 @@ int ClockWindow::Notify(int id, NMHDR* pnmh)
                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 @@ bool ClockWindow::FormatTime()
 
        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.
                }
 
index 49f2899..825e537 100644 (file)
@@ -393,7 +393,7 @@ BOOL RecursiveCreateDirectory(LPCTSTR path_in)
 {
        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 @@ BOOL RecursiveCreateDirectory(LPCTSTR path_in)
        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 @@ bool SplitFileSysURL(LPCTSTR url, String& dir_out, String& fname_out)
                        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);
                }
index 9ef4ef7..363fe48 100644 (file)
@@ -69,7 +69,11 @@ extern "C" {
 
 #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 @@ BOOL exists_path(LPCTSTR path);
  // 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 @@ BOOL exists_path(LPCTSTR path);
 
 #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)
index 540bf01..089e87a 100644 (file)
@@ -492,7 +492,7 @@ std::string EncodeXMLString(const XS_String& str)
                  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
index 067e523..125a693 100644 (file)
 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 @@ struct FileHolder
 {
        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