From 4c814798c7bc7f6a0f92c21b027b26290622aa2f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 19 Jun 2015 19:35:42 +0000 Subject: SIZEOF replaced with more secure analog - _countof git-svn-id: http://svn.miranda-ng.org/main/trunk@14270 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/BasicHistory/src/BasicHistory.cpp | 4 ++-- plugins/BasicHistory/src/EventList.cpp | 4 ++-- plugins/BasicHistory/src/ExportManager.cpp | 6 ++--- plugins/BasicHistory/src/HistoryWindow.cpp | 4 ++-- plugins/BasicHistory/src/Options.cpp | 36 +++++++++++++++--------------- plugins/BasicHistory/src/Scheduler.cpp | 22 +++++++++--------- plugins/BasicHistory/src/Searcher.cpp | 4 ++-- 7 files changed, 40 insertions(+), 40 deletions(-) (limited to 'plugins/BasicHistory/src') diff --git a/plugins/BasicHistory/src/BasicHistory.cpp b/plugins/BasicHistory/src/BasicHistory.cpp index c3cd59d45b..1f103b66d0 100644 --- a/plugins/BasicHistory/src/BasicHistory.cpp +++ b/plugins/BasicHistory/src/BasicHistory.cpp @@ -186,7 +186,7 @@ void InitIcolib() HICON LoadIconEx(int iconId, bool big) { - for (int i=0; i < SIZEOF(iconList); i++) + for (int i=0; i < _countof(iconList); i++) if ( iconList[i].defIconID == iconId) return IcoLib_GetIconByHandle(iconList[i].hIcolib, big); @@ -274,7 +274,7 @@ extern "C" int __declspec(dllexport) Load(void) EventList::Init(); - Icon_Register(hInst, LPGEN("History"), iconList, SIZEOF(iconList)); + Icon_Register(hInst, LPGEN("History"), iconList, _countof(iconList)); return 0; } diff --git a/plugins/BasicHistory/src/EventList.cpp b/plugins/BasicHistory/src/EventList.cpp index 9bbd8ab243..947c2139d8 100644 --- a/plugins/BasicHistory/src/EventList.cpp +++ b/plugins/BasicHistory/src/EventList.cpp @@ -346,11 +346,11 @@ void EventList::InitNames() TCHAR str[200]; if (hContact) { _tcscpy_s(contactName, 256, (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR )); - mir_sntprintf(str, SIZEOF(str), TranslateT("History for %s"),contactName); + mir_sntprintf(str, _countof(str), TranslateT("History for %s"),contactName); } else { _tcscpy_s(contactName, 256, TranslateT("System")); - mir_sntprintf(str, SIZEOF(str), TranslateT("History")); + mir_sntprintf(str, _countof(str), TranslateT("History")); } if (isWnd) diff --git a/plugins/BasicHistory/src/ExportManager.cpp b/plugins/BasicHistory/src/ExportManager.cpp index a1049d87d7..e6fef029e1 100644 --- a/plugins/BasicHistory/src/ExportManager.cpp +++ b/plugins/BasicHistory/src/ExportManager.cpp @@ -41,9 +41,9 @@ std::wstring GetFile(const TCHAR* ext, HWND hwnd, bool open) _tcscpy_s(extUpper, ext); extUpper[0] = std::toupper(ext[0], loc); - mir_sntprintf(filter, SIZEOF(filter), TranslateT("%s Files (*.%s)"), extUpper, ext); + mir_sntprintf(filter, _countof(filter), TranslateT("%s Files (*.%s)"), extUpper, ext); size_t len = mir_tstrlen(filter) + 1; - mir_sntprintf(filter + len, SIZEOF(filter) - len, _T("*.%s"), ext); + mir_sntprintf(filter + len, _countof(filter) - len, _T("*.%s"), ext); len += mir_tstrlen(filter + len); filter[++len] = 0; TCHAR stzFilePath[1024]; @@ -59,7 +59,7 @@ std::wstring GetFile(const TCHAR* ext, HWND hwnd, bool open) ofn.nFilterIndex = 1; ofn.lpstrFile = stzFilePath; ofn.lpstrTitle = open ? TranslateT("Import") : TranslateT("Export"); - ofn.nMaxFile = SIZEOF(stzFilePath); + ofn.nMaxFile = _countof(stzFilePath); ofn.lpstrDefExt = ext; if (open) { ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; diff --git a/plugins/BasicHistory/src/HistoryWindow.cpp b/plugins/BasicHistory/src/HistoryWindow.cpp index 5fe89953f7..215aedd623 100644 --- a/plugins/BasicHistory/src/HistoryWindow.cpp +++ b/plugins/BasicHistory/src/HistoryWindow.cpp @@ -1180,7 +1180,7 @@ void HistoryWindow::Initialise() { 2, IDM_CONFIG, TBSTATE_ENABLED, BTNS_DROPDOWN, {0}, 0, (INT_PTR)TranslateT("Options")}, }; SendMessage(toolbarWindow, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); - SendMessage(toolbarWindow, TB_ADDBUTTONS, (WPARAM)SIZEOF(tbButtons), (LPARAM)&tbButtons); + SendMessage(toolbarWindow, TB_ADDBUTTONS, (WPARAM)_countof(tbButtons), (LPARAM)&tbButtons); SendMessage(toolbarWindow, TB_SETBUTTONSIZE, 0, MAKELPARAM(16, 16)); SendMessage(toolbarWindow, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS); SendMessage(toolbarWindow, TB_SETMAXTEXTROWS, 0, 0); @@ -2061,7 +2061,7 @@ void HistoryWindow::Delete(int what) return; TCHAR message[256]; - mir_sntprintf(message, SIZEOF(message), TranslateT("Number of history items to delete: %d.\nAre you sure you want to do this?"), toDelete); + mir_sntprintf(message, _countof(message), TranslateT("Number of history items to delete: %d.\nAre you sure you want to do this?"), toDelete); if (MessageBox(hWnd, message, TranslateT("Are You sure?"), MB_OKCANCEL | MB_ICONERROR) != IDOK) return; diff --git a/plugins/BasicHistory/src/Options.cpp b/plugins/BasicHistory/src/Options.cpp index 15656791ae..0e472145b7 100644 --- a/plugins/BasicHistory/src/Options.cpp +++ b/plugins/BasicHistory/src/Options.cpp @@ -223,11 +223,11 @@ static HotkeyOptionsList g_HotkeyOptionsList[] = { { "basichistory_hot_impdat", LPGENT("Import From Dat (mContacts)"), LPGENT("History"), 0, 0, HISTORY_HK_IMPDAT }, }; -const int g_fontsSize = SIZEOF(g_FontOptionsList); +const int g_fontsSize = _countof(g_FontOptionsList); -const int g_colorsSize = SIZEOF(g_ColorOptionsList); +const int g_colorsSize = _countof(g_ColorOptionsList); -const int g_hotkeysSize = SIZEOF(g_HotkeyOptionsList); +const int g_hotkeysSize = _countof(g_HotkeyOptionsList); void Options::Load(void) { @@ -247,7 +247,7 @@ void Options::Load(void) fid.deffontsettings.colour = g_FontOptionsList[i].defColour; fid.deffontsettings.style = g_FontOptionsList[i].defStyle; fid.deffontsettings.charset = DEFAULT_CHARSET; - mir_snprintf(fid.prefix, SIZEOF(fid.prefix), "Font%d", i); + mir_snprintf(fid.prefix, _countof(fid.prefix), "Font%d", i); _tcsncpy_s(fid.name, g_FontOptionsList[i].szDescr, _TRUNCATE); _tcsncpy_s(fid.backgroundName, g_FontOptionsList[i].szBackgroundName, _TRUNCATE); fid.flags = FIDF_DEFAULTVALID | FIDF_CLASSGENERAL | g_FontOptionsList[i].flags; @@ -258,7 +258,7 @@ void Options::Load(void) _tcsncpy_s(cid.group, LPGENT("History"), _TRUNCATE); for (int i = 0; i < g_colorsSize; ++i) { _tcsncpy_s(cid.name, g_ColorOptionsList[i].tszName, _TRUNCATE); - mir_snprintf(cid.setting, SIZEOF(cid.setting), "Color%d", i); + mir_snprintf(cid.setting, _countof(cid.setting), "Color%d", i); cid.order = i; cid.defcolour = g_ColorOptionsList[i].def; ColourRegisterT(&cid); @@ -714,7 +714,7 @@ void InitTaskMenuItems(); void SetEventCB(HWND hwndCB, int eventId) { - int cpCount = SIZEOF(EventNames); + int cpCount = _countof(EventNames); int selCpIdx = -1; for (int i = 0; i < cpCount; ++i) if (EventNames[i].id == eventId) @@ -769,7 +769,7 @@ void ReloadEventLB(HWND hwndLB, const FilterOptions &sel) ListBox_AddString(hwndLB, TranslateT("Outgoing events")); for (std::vector::const_iterator it = sel.events.begin(); it != sel.events.end(); ++it) { - int cpCount = SIZEOF(EventNames); + int cpCount = _countof(EventNames); int selCpIdx = -1; for (int i = 0; i < cpCount; ++i) if (EventNames[i].id == *it) @@ -805,9 +805,9 @@ bool OpenFileDlg(HWND hwndDlg, HWND hwndEdit, const TCHAR* defName, const TCHAR* TCHAR extUpper[32]; _tcscpy_s(extUpper, ext); extUpper[0] = std::toupper(ext[0], loc); - mir_sntprintf(filter, SIZEOF(filter), TranslateT("%s Files (*.%s)"), extUpper, ext); + mir_sntprintf(filter, _countof(filter), TranslateT("%s Files (*.%s)"), extUpper, ext); size_t len = mir_tstrlen(filter) + 1; - mir_sntprintf(filter + len, SIZEOF(filter) - len, _T("*.%s"), ext); + mir_sntprintf(filter + len, _countof(filter) - len, _T("*.%s"), ext); len += mir_tstrlen(filter + len) + 1; _tcscpy_s(filter + len, 1024 - len, TranslateT("All Files (*.*)")); len += mir_tstrlen(filter + len) + 1; @@ -834,7 +834,7 @@ bool OpenFileDlg(HWND hwndDlg, HWND hwndEdit, const TCHAR* defName, const TCHAR* ofn.nFilterIndex = 1; ofn.lpstrFile = stzFilePath; ofn.lpstrTitle = title; - ofn.nMaxFile = SIZEOF(stzFilePath); + ofn.nMaxFile = _countof(stzFilePath); ofn.lpstrDefExt = ext; if (open) { ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; @@ -871,7 +871,7 @@ INT_PTR CALLBACK Options::DlgProcOptsMain(HWND hwndDlg, UINT msg, WPARAM wParam, HWND ftpLog = GetDlgItem(hwndDlg, IDC_WINSCPLOG); ComboBox_AddString(events, TranslateT("Incoming events")); ComboBox_AddString(events, TranslateT("Outgoing events")); - for (int i = 0 ; i < SIZEOF(EventNames); ++i) + for (int i = 0 ; i < _countof(EventNames); ++i) ComboBox_AddString(events, TranslateTS(EventNames[i].name)); ComboBox_AddString(defFilter, TranslateT("Default history events")); @@ -1702,7 +1702,7 @@ INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, TCHAR sep = _T(':'); if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIME, timeFormat, 10) > 0) sep = timeFormat[0]; - mir_sntprintf(timeFormat, SIZEOF(timeFormat), _T("HH%cmm"), sep); + mir_sntprintf(timeFormat, _countof(timeFormat), _T("HH%cmm"), sep); } SYSTEMTIME st; @@ -1749,7 +1749,7 @@ INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, toCp.eventDeltaTime = GetDlgItemInt(hwndDlg, IDC_EVENT_TIME, &isOK, TRUE); if (!isOK) { TCHAR msg[256]; - mir_sntprintf(msg, SIZEOF(msg), TranslateT("Invalid '%s' value."), TranslateT("Events older than")); + mir_sntprintf(msg, _countof(msg), TranslateT("Invalid '%s' value."), TranslateT("Events older than")); MessageBox(hwndDlg, msg, TranslateT("Error"), MB_ICONERROR); break; } @@ -1759,7 +1759,7 @@ INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, toCp.importType = (enum IImport::ImportType)ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_IMPORT_TYPE)); toCp.compress = Button_GetCheck(GetDlgItem(hwndDlg, IDC_COMPRESS)) != 0; char bufC[100]; - GetDlgItemTextA(hwndDlg, IDC_PASSWORD, bufC, SIZEOF(bufC)); + GetDlgItemTextA(hwndDlg, IDC_PASSWORD, bufC, _countof(bufC)); toCp.zipPassword = bufC; HWND exportPath = GetDlgItem(hwndDlg, IDC_EXPORT_PATH); int exLen = Edit_GetTextLength(exportPath); @@ -1780,7 +1780,7 @@ INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, if (!isOK) { if (toCp.trigerType == TaskOptions::Monthly) { TCHAR msg[256]; - mir_sntprintf(msg, SIZEOF(msg), TranslateT("Invalid '%s' value."), TranslateT("Day")); + mir_sntprintf(msg, _countof(msg), TranslateT("Invalid '%s' value."), TranslateT("Day")); MessageBox(hwndDlg, msg, TranslateT("Error"), MB_ICONERROR); break; } @@ -1790,7 +1790,7 @@ INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, if (!isOK) { if (toCp.trigerType == TaskOptions::DeltaMin || toCp.trigerType == TaskOptions::DeltaHour) { TCHAR msg[256]; - mir_sntprintf(msg, SIZEOF(msg), TranslateT("Invalid '%s' value."), TranslateT("Delta time")); + mir_sntprintf(msg, _countof(msg), TranslateT("Invalid '%s' value."), TranslateT("Delta time")); MessageBox(hwndDlg, msg, TranslateT("Error"), MB_ICONERROR); break; } @@ -1807,9 +1807,9 @@ INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, if (err.empty()) _tcscpy_s(msg, TranslateT("Some value is invalid")); else if (errDescr.empty()) - mir_sntprintf(msg, SIZEOF(msg), TranslateT("Invalid '%s' value."), err.c_str()); + mir_sntprintf(msg, _countof(msg), TranslateT("Invalid '%s' value."), err.c_str()); else - mir_sntprintf(msg, SIZEOF(msg), TranslateT("Invalid '%s' value.\n%s"), err.c_str(), errDescr.c_str()); + mir_sntprintf(msg, _countof(msg), TranslateT("Invalid '%s' value.\n%s"), err.c_str(), errDescr.c_str()); MessageBox(hwndDlg, msg, TranslateT("Error"), MB_ICONERROR); break; } diff --git a/plugins/BasicHistory/src/Scheduler.cpp b/plugins/BasicHistory/src/Scheduler.cpp index fa833a46c5..0875b05596 100644 --- a/plugins/BasicHistory/src/Scheduler.cpp +++ b/plugins/BasicHistory/src/Scheduler.cpp @@ -236,9 +236,9 @@ bool DoTask(TaskOptions& to) if (err.empty()) _tcscpy_s(msg, TranslateT("Some value is invalid")); else if (errDescr.empty()) - mir_sntprintf(msg, SIZEOF(msg), TranslateT("Invalid '%s' value."), err.c_str()); + mir_sntprintf(msg, _countof(msg), TranslateT("Invalid '%s' value."), err.c_str()); else - mir_sntprintf(msg, SIZEOF(msg), TranslateT("Invalid '%s' value.\n%s"), err.c_str(), errDescr.c_str()); + mir_sntprintf(msg, _countof(msg), TranslateT("Invalid '%s' value.\n%s"), err.c_str(), errDescr.c_str()); DoError(to, msg); return true; @@ -395,7 +395,7 @@ bool DoTask(TaskOptions& to) errorStr += L"\n"; TCHAR msg[1024]; - mir_sntprintf(msg, SIZEOF(msg), TranslateT("Incorrect file format: %s."), GetName(*it).c_str()); + mir_sntprintf(msg, _countof(msg), TranslateT("Incorrect file format: %s."), GetName(*it).c_str()); errorStr += msg; } else { @@ -404,7 +404,7 @@ bool DoTask(TaskOptions& to) TCHAR msg[1024]; - mir_sntprintf(msg, SIZEOF(msg), TranslateT("Unknown contact in file: %s."), GetName(*it).c_str()); + mir_sntprintf(msg, _countof(msg), TranslateT("Unknown contact in file: %s."), GetName(*it).c_str()); errorStr += msg; } } @@ -460,7 +460,7 @@ bool DoTask(TaskOptions& to) TCHAR msg[1024]; - mir_sntprintf(msg, SIZEOF(msg), TranslateT("Cannot export history for contact: %s."), exp->GetContactName().c_str()); + mir_sntprintf(msg, _countof(msg), TranslateT("Cannot export history for contact: %s."), exp->GetContactName().c_str()); errorStr += msg; } @@ -481,7 +481,7 @@ bool DoTask(TaskOptions& to) errorStr += L"\n"; TCHAR msg[1024]; - mir_sntprintf(msg, SIZEOF(msg), TranslateT("Cannot export history for contact: %s."), exp->GetContactName().c_str()); + mir_sntprintf(msg, _countof(msg), TranslateT("Cannot export history for contact: %s."), exp->GetContactName().c_str()); errorStr += msg; break; } @@ -586,7 +586,7 @@ std::wstring GetFileName(const std::wstring &baseName, std::wstring contactName, TCHAR time[256]; SYSTEMTIME st; GetLocalTime(&st); - mir_sntprintf(time, SIZEOF(time), _T("%d-%02d-%02d %02d%02d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute); + mir_sntprintf(time, _countof(time), _T("%d-%02d-%02d %02d%02d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute); std::wstring str1 = str.substr(0, pos); str1 += time; str1 += str.substr(pos + 6); @@ -1124,7 +1124,7 @@ bool FtpFiles(const std::wstring& dir, const std::wstring& filePath, const std:: CreateDirectory(GetDirectoryName(log).c_str(), NULL); DeleteFile(log.c_str()); TCHAR cmdLine[MAX_PATH]; - mir_sntprintf(cmdLine, SIZEOF(cmdLine), _T("\"%s\" /nointeractiveinput /log=\"%s\" /script=script.sc"), Options::instance->ftpExePath.c_str(), log.c_str()); + mir_sntprintf(cmdLine, _countof(cmdLine), _T("\"%s\" /nointeractiveinput /log=\"%s\" /script=script.sc"), Options::instance->ftpExePath.c_str(), log.c_str()); STARTUPINFO startupInfo = {0}; PROCESS_INFORMATION processInfo; startupInfo.cb = sizeof(STARTUPINFO); @@ -1213,7 +1213,7 @@ bool FtpGetFiles(const std::wstring& dir, const std::list& files, CreateDirectory(GetDirectoryName(log).c_str(), NULL); DeleteFile(log.c_str()); TCHAR cmdLine[MAX_PATH]; - mir_sntprintf(cmdLine, SIZEOF(cmdLine), _T("\"%s\" /nointeractiveinput /log=\"%s\" /script=script.sc"), Options::instance->ftpExePath.c_str(), log.c_str()); + mir_sntprintf(cmdLine, _countof(cmdLine), _T("\"%s\" /nointeractiveinput /log=\"%s\" /script=script.sc"), Options::instance->ftpExePath.c_str(), log.c_str()); STARTUPINFO startupInfo = {0}; PROCESS_INFORMATION processInfo; startupInfo.cb = sizeof(STARTUPINFO); @@ -1243,7 +1243,7 @@ void CreatePath(const TCHAR *szDir) DWORD dwAttributes; TCHAR *pszLastBackslash, szTestDir[ MAX_PATH ]; - mir_tstrncpy( szTestDir, szDir, SIZEOF( szTestDir )); + mir_tstrncpy( szTestDir, szDir, _countof( szTestDir )); if (( dwAttributes = GetFileAttributes( szTestDir )) != INVALID_FILE_ATTRIBUTES && ( dwAttributes & FILE_ATTRIBUTE_DIRECTORY )) return; @@ -1274,7 +1274,7 @@ INT_PTR ExecuteTaskService(WPARAM wParam, LPARAM lParam) void DoError(const TaskOptions& to, const std::wstring _error) { TCHAR msg[256]; - mir_sntprintf(msg, SIZEOF(msg), TranslateT("Task '%s' execution failed:"), to.taskName.c_str()); + mir_sntprintf(msg, _countof(msg), TranslateT("Task '%s' execution failed:"), to.taskName.c_str()); if (Options::instance->schedulerHistoryAlerts) { std::wstring error = msg; error += L"\n"; diff --git a/plugins/BasicHistory/src/Searcher.cpp b/plugins/BasicHistory/src/Searcher.cpp index f8f46cdc39..13d7cfb645 100644 --- a/plugins/BasicHistory/src/Searcher.cpp +++ b/plugins/BasicHistory/src/Searcher.cpp @@ -102,7 +102,7 @@ void Searcher::Find() return; } - GetWindowText(context->findWindow, str, SIZEOF(str)); + GetWindowText(context->findWindow, str, _countof(str)); if (!str[0]) { TCHAR buf[256]; mir_sntprintf(buf, TranslateT("\"%s\" not found"), str); @@ -298,7 +298,7 @@ void Searcher::Find() lastFindSelection = -1; if (isStart) { TCHAR buf[256]; - GetWindowText(context->findWindow, str, SIZEOF(str)); + GetWindowText(context->findWindow, str, _countof(str)); mir_sntprintf(buf, TranslateT("\"%s\" not found"), str); MessageBox(context->hWnd, buf, TranslateT("Search"), MB_OK | MB_ICONINFORMATION); } -- cgit v1.2.3