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/Ping/src/icmp.cpp | 2 +- plugins/Ping/src/options.cpp | 16 ++++++++-------- plugins/Ping/src/ping.cpp | 2 +- plugins/Ping/src/pinggraph.cpp | 6 +++--- plugins/Ping/src/pinglist.cpp | 10 +++++----- plugins/Ping/src/pingthread.cpp | 32 ++++++++++++++++---------------- plugins/Ping/src/utils.cpp | 14 +++++++------- 7 files changed, 41 insertions(+), 41 deletions(-) (limited to 'plugins/Ping') diff --git a/plugins/Ping/src/icmp.cpp b/plugins/Ping/src/icmp.cpp index 84dd47d272..88d7dfcf87 100644 --- a/plugins/Ping/src/icmp.cpp +++ b/plugins/Ping/src/icmp.cpp @@ -68,7 +68,7 @@ bool ICMP::ping(char *host, ICMP_ECHO_REPLY &reply) { char winmsg[512], msg[1024]; FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, code, 0, winmsg, 512, 0); - mir_snprintf(msg, SIZEOF(msg), "Ping error (%d): %s", code, winmsg); + mir_snprintf(msg, _countof(msg), "Ping error (%d): %s", code, winmsg); PUShowMessage(msg, SM_NOTIFY); return false; } diff --git a/plugins/Ping/src/options.cpp b/plugins/Ping/src/options.cpp index 0e99ed7778..7fd6912da9 100644 --- a/plugins/Ping/src/options.cpp +++ b/plugins/Ping/src/options.cpp @@ -82,12 +82,12 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA case IDC_BTN_LOGBROWSE: { TCHAR filter[MAX_PATH]; - mir_sntprintf(filter, SIZEOF(filter), _T("%s%c*.txt%c%s%c*.*%c"), TranslateT("Text Files (*.txt)"), 0, 0, TranslateT("All Files"), 0, 0); + mir_sntprintf(filter, _countof(filter), _T("%s%c*.txt%c%s%c*.*%c"), TranslateT("Text Files (*.txt)"), 0, 0, TranslateT("All Files"), 0, 0); OPENFILENAME ofn = { 0 }; ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = options.log_filename; ofn.hwndOwner = hwndDlg; - ofn.nMaxFile = SIZEOF(options.log_filename); + ofn.nMaxFile = _countof(options.log_filename); ofn.lpstrTitle = TranslateT("Open log file"); ofn.lpstrFilter = filter; ofn.nFilterIndex = 1; @@ -128,7 +128,7 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA options.block_reps = IsDlgButtonChecked(hwndDlg, IDC_CHK_BLOCK) == BST_CHECKED; options.logging = IsDlgButtonChecked(hwndDlg, IDC_CHK_LOG) == BST_CHECKED; options.log_csv = IsDlgButtonChecked(hwndDlg, IDC_CHK_LOGCSV) == BST_CHECKED; - GetDlgItemText(hwndDlg, IDC_ED_FILENAME, options.log_filename, SIZEOF(options.log_filename)); + GetDlgItemText(hwndDlg, IDC_ED_FILENAME, options.log_filename, _countof(options.log_filename)); options.no_test_icon = IsDlgButtonChecked(hwndDlg, IDC_CHK_NOTESTICON) == BST_CHECKED; @@ -233,14 +233,14 @@ INT_PTR CALLBACK DlgProcDestEdit(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l EnableWindow(GetDlgItem(hwndDlg, IDC_ED_DESTPORT), IsDlgButtonChecked(hwndDlg, IDC_CHK_DESTTCP)); break; case IDOK: - GetDlgItemText(hwndDlg, IDC_ED_DESTADDR, add_edit_addr.pszName, SIZEOF(add_edit_addr.pszName)); - GetDlgItemText(hwndDlg, IDC_ED_DESTLAB, add_edit_addr.pszLabel, SIZEOF(add_edit_addr.pszLabel)); - GetDlgItemText(hwndDlg, IDC_ED_COMMAND, add_edit_addr.pszCommand, SIZEOF(add_edit_addr.pszCommand)); - GetDlgItemText(hwndDlg, IDC_ED_PARAMS, add_edit_addr.pszParams, SIZEOF(add_edit_addr.pszParams)); + GetDlgItemText(hwndDlg, IDC_ED_DESTADDR, add_edit_addr.pszName, _countof(add_edit_addr.pszName)); + GetDlgItemText(hwndDlg, IDC_ED_DESTLAB, add_edit_addr.pszLabel, _countof(add_edit_addr.pszLabel)); + GetDlgItemText(hwndDlg, IDC_ED_COMMAND, add_edit_addr.pszCommand, _countof(add_edit_addr.pszCommand)); + GetDlgItemText(hwndDlg, IDC_ED_PARAMS, add_edit_addr.pszParams, _countof(add_edit_addr.pszParams)); if (SendDlgItemMessage(hwndDlg, IDC_COMBO_DESTPROTO, CB_GETCURSEL, 0, 0) != -1) { - GetDlgItemTextA(hwndDlg, IDC_COMBO_DESTPROTO, add_edit_addr.pszProto, SIZEOF(add_edit_addr.pszProto)); + GetDlgItemTextA(hwndDlg, IDC_COMBO_DESTPROTO, add_edit_addr.pszProto, _countof(add_edit_addr.pszProto)); if (!mir_strcmp(add_edit_addr.pszProto, Translate(""))) add_edit_addr.pszProto[0] = '\0'; else { diff --git a/plugins/Ping/src/ping.cpp b/plugins/Ping/src/ping.cpp index a1654e9f1d..3a4f5f26b6 100644 --- a/plugins/Ping/src/ping.cpp +++ b/plugins/Ping/src/ping.cpp @@ -151,7 +151,7 @@ extern "C" __declspec(dllexport) int Load(void) HookEvent(ME_SYSTEM_PRESHUTDOWN, OnShutdown); - Icon_Register(hInst, LPGEN("Ping"), iconList, SIZEOF(iconList)); + Icon_Register(hInst, LPGEN("Ping"), iconList, _countof(iconList)); HookEvent(ME_SKIN2_ICONSCHANGED, ReloadIcons); diff --git a/plugins/Ping/src/pinggraph.cpp b/plugins/Ping/src/pinggraph.cpp index 1947ada7bf..8e0b7d0846 100644 --- a/plugins/Ping/src/pinggraph.cpp +++ b/plugins/Ping/src/pinggraph.cpp @@ -276,10 +276,10 @@ INT_PTR ShowGraph(WPARAM wParam, LPARAM lParam) { RegisterClass(&wndclass); TCHAR title[256]; - mir_tstrncpy(title, TranslateT("Ping Graph"), SIZEOF(title)); + mir_tstrncpy(title, TranslateT("Ping Graph"), _countof(title)); if (lParam) { - mir_tstrncat(title, _T(" - "), SIZEOF(title) - mir_tstrlen(title)); - mir_tstrncat(title, (TCHAR *)lParam, SIZEOF(title) - mir_tstrlen(title)); + mir_tstrncat(title, _T(" - "), _countof(title) - mir_tstrlen(title)); + mir_tstrncat(title, (TCHAR *)lParam, _countof(title) - mir_tstrlen(title)); } HWND parent = 0; diff --git a/plugins/Ping/src/pinglist.cpp b/plugins/Ping/src/pinglist.cpp index cbd590c503..51aa6f73a3 100644 --- a/plugins/Ping/src/pinglist.cpp +++ b/plugins/Ping/src/pinglist.cpp @@ -116,13 +116,13 @@ bool read_ping_address(PINGADDRESS &pa) { DBVARIANT dbv; if (!db_get_ts(0, buff, "Address", &dbv)) { - mir_tstrncpy(pa.pszName, dbv.ptszVal, SIZEOF(pa.pszName)); + mir_tstrncpy(pa.pszName, dbv.ptszVal, _countof(pa.pszName)); db_free(&dbv); } else return false; if (!db_get_ts(0, buff, "Label", &dbv)) { - mir_tstrncpy(pa.pszLabel, dbv.ptszVal, SIZEOF(pa.pszLabel)); + mir_tstrncpy(pa.pszLabel, dbv.ptszVal, _countof(pa.pszLabel)); db_free(&dbv); } else return false; @@ -133,19 +133,19 @@ bool read_ping_address(PINGADDRESS &pa) { pa.port = (int)db_get_dw(0, buff, "Port", -1); if (!db_get_s(0, buff, "Proto", &dbv)) { - mir_strncpy(pa.pszProto, dbv.pszVal, SIZEOF(pa.pszProto)); + mir_strncpy(pa.pszProto, dbv.pszVal, _countof(pa.pszProto)); db_free(&dbv); } else pa.pszProto[0] = '\0'; if (!db_get_ts(0, buff, "Command", &dbv)) { - mir_tstrncpy(pa.pszCommand, dbv.ptszVal, SIZEOF(pa.pszCommand)); + mir_tstrncpy(pa.pszCommand, dbv.ptszVal, _countof(pa.pszCommand)); db_free(&dbv); } else pa.pszCommand[0] = '\0'; if (!db_get_ts(0, buff, "CommandParams", &dbv)) { - mir_tstrncpy(pa.pszParams, dbv.ptszVal, SIZEOF(pa.pszParams)); + mir_tstrncpy(pa.pszParams, dbv.ptszVal, _countof(pa.pszParams)); db_free(&dbv); } else diff --git a/plugins/Ping/src/pingthread.cpp b/plugins/Ping/src/pingthread.cpp index c0465a06a0..71e4f54b16 100644 --- a/plugins/Ping/src/pingthread.cpp +++ b/plugins/Ping/src/pingthread.cpp @@ -115,9 +115,9 @@ void __cdecl sttCheckStatusThreadProc(void *vp) pa.item_id = i->item_id; pa.miss_count = i->miss_count; pa.port = i->port; - mir_tstrncpy(pa.pszLabel, i->pszLabel, SIZEOF(pa.pszLabel)); - mir_tstrncpy(pa.pszName, i->pszName, SIZEOF(pa.pszName)); - mir_strncpy(pa.pszProto, i->pszProto, SIZEOF(pa.pszProto)); + mir_tstrncpy(pa.pszLabel, i->pszLabel, _countof(pa.pszLabel)); + mir_tstrncpy(pa.pszName, i->pszName, _countof(pa.pszName)); + mir_strncpy(pa.pszProto, i->pszProto, _countof(pa.pszProto)); pa.set_status = i->set_status; pa.status = i->status; break; @@ -317,9 +317,9 @@ void CALLBACK TimerProc( { TCHAR TBcapt[255]; if (total > 0) - mir_sntprintf(TBcapt, SIZEOF(TBcapt), _T("Ping (%d/%d)"), upCount, total); + mir_sntprintf(TBcapt, _countof(TBcapt), _T("Ping (%d/%d)"), upCount, total); else - mir_sntprintf(TBcapt, SIZEOF(TBcapt), _T("Ping")); + mir_sntprintf(TBcapt, _countof(TBcapt), _T("Ping")); CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_TBNAME | FO_TCHAR, frame_id), (LPARAM)TBcapt); CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_TBTIPNAME | FO_TCHAR, frame_id), (LPARAM)TBcapt); @@ -1007,27 +1007,27 @@ void InitList() { font_id.cbSize = sizeof(FontIDT); - mir_tstrncpy(font_id.group, LPGENT("Ping"), SIZEOF(font_id.group)); - mir_tstrncpy(font_id.name, LPGENT("List"), SIZEOF(font_id.name)); - mir_strncpy(font_id.dbSettingsGroup, "PING", SIZEOF(font_id.dbSettingsGroup)); - mir_strncpy(font_id.prefix, "Font", SIZEOF(font_id.prefix)); - mir_tstrncpy(font_id.backgroundGroup, _T("Ping"), SIZEOF(font_id.backgroundGroup)); - mir_tstrncpy(font_id.backgroundName, _T("Background"), SIZEOF(font_id.backgroundName)); + mir_tstrncpy(font_id.group, LPGENT("Ping"), _countof(font_id.group)); + mir_tstrncpy(font_id.name, LPGENT("List"), _countof(font_id.name)); + mir_strncpy(font_id.dbSettingsGroup, "PING", _countof(font_id.dbSettingsGroup)); + mir_strncpy(font_id.prefix, "Font", _countof(font_id.prefix)); + mir_tstrncpy(font_id.backgroundGroup, _T("Ping"), _countof(font_id.backgroundGroup)); + mir_tstrncpy(font_id.backgroundName, _T("Background"), _countof(font_id.backgroundName)); font_id.order = 0; font_id.flags = FIDF_DEFAULTVALID; font_id.deffontsettings.charset = DEFAULT_CHARSET; font_id.deffontsettings.size = -14; font_id.deffontsettings.style = 0; font_id.deffontsettings.colour = RGB(255, 255, 255); - mir_tstrncpy(font_id.deffontsettings.szFace, _T("Tahoma"), SIZEOF(font_id.deffontsettings.szFace)); + mir_tstrncpy(font_id.deffontsettings.szFace, _T("Tahoma"), _countof(font_id.deffontsettings.szFace)); FontRegisterT(&font_id); bk_col_id.cbSize = sizeof(ColourIDT); - mir_tstrncpy(bk_col_id.group, _T("Ping"), SIZEOF(bk_col_id.group)); - mir_tstrncpy(bk_col_id.name, _T("Background"), SIZEOF(bk_col_id.name)); - mir_strncpy(bk_col_id.dbSettingsGroup, "PING", SIZEOF(bk_col_id.dbSettingsGroup)); - mir_strncpy(bk_col_id.setting, "BgColor", SIZEOF(bk_col_id.setting)); + mir_tstrncpy(bk_col_id.group, _T("Ping"), _countof(bk_col_id.group)); + mir_tstrncpy(bk_col_id.name, _T("Background"), _countof(bk_col_id.name)); + mir_strncpy(bk_col_id.dbSettingsGroup, "PING", _countof(bk_col_id.dbSettingsGroup)); + mir_strncpy(bk_col_id.setting, "BgColor", _countof(bk_col_id.setting)); bk_col_id.defcolour = RGB(0, 0, 0); ColourRegisterT(&bk_col_id); diff --git a/plugins/Ping/src/utils.cpp b/plugins/Ping/src/utils.cpp index aca8eab105..16adad8964 100644 --- a/plugins/Ping/src/utils.cpp +++ b/plugins/Ping/src/utils.cpp @@ -38,8 +38,8 @@ void __stdcall ShowPopup(TCHAR *line1, TCHAR *line2, int flags) ppd->lchContact = NULL; ppd->lchIcon = (flags ? hIconResponding : hIconNotResponding); - mir_tstrncpy(ppd->lptzContactName, line1, SIZEOF(ppd->lptzContactName)); - mir_tstrncpy(ppd->lptzText, line2, SIZEOF(ppd->lptzText)); + mir_tstrncpy(ppd->lptzContactName, line1, _countof(ppd->lptzContactName)); + mir_tstrncpy(ppd->lptzText, line2, _countof(ppd->lptzText)); ppd->colorBack = GetSysColor(COLOR_BTNFACE); ppd->colorText = GetSysColor(COLOR_WINDOWTEXT); @@ -221,26 +221,26 @@ void import_ping_address(int index, PINGADDRESS &pa) { char buf[256]; mir_snprintf(buf, "Address%d", index); if (!db_get_ts(0, "PingPlug", buf, &dbv)) { - mir_tstrncpy(pa.pszName, dbv.ptszVal, SIZEOF(pa.pszName)); + mir_tstrncpy(pa.pszName, dbv.ptszVal, _countof(pa.pszName)); db_free(&dbv); } else - mir_tstrncpy(pa.pszName, TranslateT("Unknown Address"), SIZEOF(pa.pszName)); + mir_tstrncpy(pa.pszName, TranslateT("Unknown Address"), _countof(pa.pszName)); mir_snprintf(buf, "Label%d", index); if (!db_get_ts(0, "PingPlug", buf, &dbv)) { - mir_tstrncpy(pa.pszLabel, dbv.ptszVal, SIZEOF(pa.pszLabel)); + mir_tstrncpy(pa.pszLabel, dbv.ptszVal, _countof(pa.pszLabel)); db_free(&dbv); } else - mir_tstrncpy(pa.pszLabel, TranslateT("Unknown"), SIZEOF(pa.pszLabel)); + mir_tstrncpy(pa.pszLabel, TranslateT("Unknown"), _countof(pa.pszLabel)); mir_snprintf(buf, "Port%d", index); pa.port = (int)db_get_dw(0, "PingPlug", buf, -1); mir_snprintf(buf, "Proto%d", index); if (!db_get_s(0, "PingPlug", buf, &dbv)) { - mir_strncpy(pa.pszProto, dbv.pszVal, SIZEOF(pa.pszProto)); + mir_strncpy(pa.pszProto, dbv.pszVal, _countof(pa.pszProto)); db_free(&dbv); mir_snprintf(buf, "Status%d", index); pa.set_status = db_get_w(0, "PingPlug", buf, ID_STATUS_ONLINE); -- cgit v1.2.3