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 --- src/core/stdchat/src/main.cpp | 26 ++++++++++++------------- src/core/stdchat/src/options.cpp | 42 ++++++++++++++++++++-------------------- src/core/stdchat/src/tools.cpp | 6 +++--- src/core/stdchat/src/window.cpp | 18 ++++++++--------- 4 files changed, 46 insertions(+), 46 deletions(-) (limited to 'src/core/stdchat') diff --git a/src/core/stdchat/src/main.cpp b/src/core/stdchat/src/main.cpp index 0528908ae0..f849446347 100644 --- a/src/core/stdchat/src/main.cpp +++ b/src/core/stdchat/src/main.cpp @@ -287,30 +287,30 @@ static void RegisterFonts() { ColourIDT colourid = { sizeof(colourid) }; strncpy(colourid.dbSettingsGroup, CHAT_MODULE, sizeof(colourid.dbSettingsGroup)); - _tcsncpy(colourid.group, LPGENT("Chat module"), SIZEOF(colourid.group)); + _tcsncpy(colourid.group, LPGENT("Chat module"), _countof(colourid.group)); - strncpy(colourid.setting, "ColorLogBG", SIZEOF(colourid.setting)); - _tcsncpy(colourid.name, LPGENT("Group chat log background"), SIZEOF(colourid.name)); + strncpy(colourid.setting, "ColorLogBG", _countof(colourid.setting)); + _tcsncpy(colourid.name, LPGENT("Group chat log background"), _countof(colourid.name)); colourid.defcolour = GetSysColor(COLOR_WINDOW); ColourRegisterT(&colourid); - strncpy(colourid.setting, "ColorMessageBG", SIZEOF(colourid.setting)); - _tcsncpy(colourid.name, LPGENT("Message background"), SIZEOF(colourid.name)); + strncpy(colourid.setting, "ColorMessageBG", _countof(colourid.setting)); + _tcsncpy(colourid.name, LPGENT("Message background"), _countof(colourid.name)); colourid.defcolour = GetSysColor(COLOR_WINDOW); ColourRegisterT(&colourid); - strncpy(colourid.setting, "ColorNicklistBG", SIZEOF(colourid.setting)); - _tcsncpy(colourid.name, LPGENT("Nick list background"), SIZEOF(colourid.name)); + strncpy(colourid.setting, "ColorNicklistBG", _countof(colourid.setting)); + _tcsncpy(colourid.name, LPGENT("Nick list background"), _countof(colourid.name)); colourid.defcolour = GetSysColor(COLOR_WINDOW); ColourRegisterT(&colourid); - strncpy(colourid.setting, "ColorNicklistLines", SIZEOF(colourid.setting)); - _tcsncpy(colourid.name, LPGENT("Nick list lines"), SIZEOF(colourid.name)); + strncpy(colourid.setting, "ColorNicklistLines", _countof(colourid.setting)); + _tcsncpy(colourid.name, LPGENT("Nick list lines"), _countof(colourid.name)); colourid.defcolour = GetSysColor(COLOR_INACTIVEBORDER); ColourRegisterT(&colourid); - strncpy(colourid.setting, "ColorNicklistSelectedBG", SIZEOF(colourid.setting)); - _tcsncpy(colourid.name, LPGENT("Nick list background (selected)"), SIZEOF(colourid.name)); + strncpy(colourid.setting, "ColorNicklistSelectedBG", _countof(colourid.setting)); + _tcsncpy(colourid.name, LPGENT("Nick list background (selected)"), _countof(colourid.name)); colourid.defcolour = GetSysColor(COLOR_HIGHLIGHT); ColourRegisterT(&colourid); } @@ -471,8 +471,8 @@ STDMETHODIMP CREOleCallback::GetNewStorage(LPSTORAGE * lplpstg) { WCHAR szwName[64]; char szName[64]; - mir_snprintf(szName, SIZEOF(szName), "s%u", nextStgId++); - MultiByteToWideChar(CP_ACP, 0, szName, -1, szwName, SIZEOF(szwName)); + mir_snprintf(szName, _countof(szName), "s%u", nextStgId++); + MultiByteToWideChar(CP_ACP, 0, szName, -1, szwName, _countof(szwName)); if (pictStg == NULL) return STG_E_MEDIUMFULL; return pictStg->CreateStorage(szwName, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, 0, lplpstg); diff --git a/src/core/stdchat/src/options.cpp b/src/core/stdchat/src/options.cpp index eccfa9ac3f..e75482a151 100644 --- a/src/core/stdchat/src/options.cpp +++ b/src/core/stdchat/src/options.cpp @@ -128,13 +128,13 @@ static const struct branch_t branch6[] = { { LPGENT("Show popup for status changes"), "PopupFlags", GC_EVENT_ADDSTATUS, 0 }, }; -HTREEITEM hItemB0[SIZEOF(branch0)]; -HTREEITEM hItemB1[SIZEOF(branch1)]; -HTREEITEM hItemB2[SIZEOF(branch2)]; -HTREEITEM hItemB3[SIZEOF(branch3)]; -HTREEITEM hItemB4[SIZEOF(branch4)]; -HTREEITEM hItemB5[SIZEOF(branch5)]; -HTREEITEM hItemB6[SIZEOF(branch6)]; +HTREEITEM hItemB0[_countof(branch0)]; +HTREEITEM hItemB1[_countof(branch1)]; +HTREEITEM hItemB2[_countof(branch2)]; +HTREEITEM hItemB3[_countof(branch3)]; +HTREEITEM hItemB4[_countof(branch4)]; +HTREEITEM hItemB5[_countof(branch5)]; +HTREEITEM hItemB6[_countof(branch6)]; static HTREEITEM InsertBranch(HWND hwndTree, char* pszDescr, BOOL bExpanded) { @@ -344,13 +344,13 @@ static INT_PTR CALLBACK DlgProcOptions1(HWND hwndDlg, UINT uMsg, WPARAM wParam, hListHeading5 = InsertBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), LPGEN("Icons to display in the tray"), db_get_b(NULL, CHAT_MODULE, "Branch5Exp", 0) ? TRUE : FALSE); if (PopupInstalled) hListHeading6 = InsertBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), LPGEN("Popups to display"), db_get_b(NULL, CHAT_MODULE, "Branch6Exp", 0) ? TRUE : FALSE); - FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading0, branch0, hItemB0, SIZEOF(branch0), 0); - FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading1, branch1, hItemB1, SIZEOF(branch1), 0); - FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading2, branch2, hItemB2, SIZEOF(branch2), 0); - FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading3, branch3, hItemB3, SIZEOF(branch3), 0x03E0); - FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading4, branch4, hItemB4, SIZEOF(branch4), 0x0000); - FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading5, branch5, hItemB5, SIZEOF(branch5), 0x1000); - FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading6, branch6, hItemB6, SIZEOF(branch6), 0x0000); + FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading0, branch0, hItemB0, _countof(branch0), 0); + FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading1, branch1, hItemB1, _countof(branch1), 0); + FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading2, branch2, hItemB2, _countof(branch2), 0); + FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading3, branch3, hItemB3, _countof(branch3), 0x03E0); + FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading4, branch4, hItemB4, _countof(branch4), 0x0000); + FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading5, branch5, hItemB5, _countof(branch5), 0x1000); + FillBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), hListHeading6, branch6, hItemB6, _countof(branch6), 0x0000); SendMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); break; @@ -413,14 +413,14 @@ static INT_PTR CALLBACK DlgProcOptions1(HWND hwndDlg, UINT uMsg, WPARAM wParam, switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: BYTE b = db_get_b(NULL, CHAT_MODULE, "Tabs", 1); - SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch0, hItemB0, SIZEOF(branch0)); - SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch1, hItemB1, SIZEOF(branch1)); - SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch2, hItemB2, SIZEOF(branch2)); - SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch3, hItemB3, SIZEOF(branch3)); - SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch4, hItemB4, SIZEOF(branch4)); - SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch5, hItemB5, SIZEOF(branch5)); + SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch0, hItemB0, _countof(branch0)); + SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch1, hItemB1, _countof(branch1)); + SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch2, hItemB2, _countof(branch2)); + SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch3, hItemB3, _countof(branch3)); + SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch4, hItemB4, _countof(branch4)); + SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch5, hItemB5, _countof(branch5)); if (PopupInstalled) - SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch6, hItemB6, SIZEOF(branch6)); + SaveBranch(GetDlgItem(hwndDlg, IDC_CHECKBOXES), branch6, hItemB6, _countof(branch6)); g_Settings.dwIconFlags = db_get_dw(NULL, CHAT_MODULE, "IconFlags", 0x0000); g_Settings.dwTrayIconFlags = db_get_dw(NULL, CHAT_MODULE, "TrayIconFlags", 0x1000); g_Settings.dwPopupFlags = db_get_dw(NULL, CHAT_MODULE, "PopupFlags", 0x0000); diff --git a/src/core/stdchat/src/tools.cpp b/src/core/stdchat/src/tools.cpp index 3537b61689..33f2988432 100644 --- a/src/core/stdchat/src/tools.cpp +++ b/src/core/stdchat/src/tools.cpp @@ -53,7 +53,7 @@ bool LoadMessageFont(LOGFONT *lf, COLORREF *colour) if (db_get_ts(NULL, "SRMM", str, &dbv)) mir_tstrcpy(lf->lfFaceName, _T("Arial")); else { - mir_tstrncpy(lf->lfFaceName, dbv.ptszVal, SIZEOF(lf->lfFaceName)); + mir_tstrncpy(lf->lfFaceName, dbv.ptszVal, _countof(lf->lfFaceName)); db_free(&dbv); } mir_snprintf(str, "SRMFont%dSet", i); @@ -135,7 +135,7 @@ UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO if (pszWordText && pszWordText[0]) { TCHAR szMenuText[4096]; - mir_sntprintf(szMenuText, SIZEOF(szMenuText), TranslateT("Look up '%s':"), pszWordText); + mir_sntprintf(szMenuText, _countof(szMenuText), TranslateT("Look up '%s':"), pszWordText); ModifyMenu(*hMenu, 4, MF_STRING | MF_BYPOSITION, 4, szMenuText); } else ModifyMenu(*hMenu, 4, MF_STRING | MF_GRAYED | MF_BYPOSITION, 4, TranslateT("No word to look up")); @@ -146,7 +146,7 @@ UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO if (pszWordText) mir_sntprintf(szTemp, TranslateT("&Message %s"), pszWordText); else - mir_tstrncpy(szTemp, TranslateT("&Message"), SIZEOF(szTemp) - 1); + mir_tstrncpy(szTemp, TranslateT("&Message"), _countof(szTemp) - 1); if (mir_tstrlen(szTemp) > 40) mir_tstrcpy(szTemp + 40, _T("...")); diff --git a/src/core/stdchat/src/window.cpp b/src/core/stdchat/src/window.cpp index 3e8edd8030..8bc99cbc52 100644 --- a/src/core/stdchat/src/window.cpp +++ b/src/core/stdchat/src/window.cpp @@ -997,7 +997,7 @@ static void ProcessNickListHovering(HWND hwnd, int hoveredItem, SESSION_INFO *si } if (tszBuf[0] == 0) - mir_sntprintf(tszBuf, SIZEOF(tszBuf), _T("%s: %s\r\n%s: %s\r\n%s: %s"), + mir_sntprintf(tszBuf, _countof(tszBuf), _T("%s: %s\r\n%s: %s\r\n%s: %s"), TranslateT("Nickname"), ui->pszNick, TranslateT("Unique ID"), ui->pszUID, TranslateT("Status"), pci->TM_WordToString(si->pStatuses, ui->Status)); @@ -1149,13 +1149,13 @@ static int RestoreWindowPosition(HWND hwnd, MCONTACT hContact, char * szModule, GetWindowPlacement(hwnd, &wp); char szSettingName[64]; - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sx", szNamePrefix); + mir_snprintf(szSettingName, _countof(szSettingName), "%sx", szNamePrefix); int x = db_get_dw(hContact, szModule, szSettingName, -1); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sy", szNamePrefix); + mir_snprintf(szSettingName, _countof(szSettingName), "%sy", szNamePrefix); int y = (int)db_get_dw(hContact, szModule, szSettingName, -1); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%swidth", szNamePrefix); + mir_snprintf(szSettingName, _countof(szSettingName), "%swidth", szNamePrefix); int width = db_get_dw(hContact, szModule, szSettingName, -1); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sheight", szNamePrefix); + mir_snprintf(szSettingName, _countof(szSettingName), "%sheight", szNamePrefix); int height = db_get_dw(hContact, szModule, szSettingName, -1); if (x == -1) @@ -2230,7 +2230,7 @@ LABEL_SHOWWINDOW: case ID_SEARCH_WIKIPEDIA: if (pszWord[0]) { TCHAR szURL[1024]; - mir_sntprintf(szURL, SIZEOF(szURL), _T("http://en.wikipedia.org/wiki/%s"), pszWord); + mir_sntprintf(szURL, _countof(szURL), _T("http://en.wikipedia.org/wiki/%s"), pszWord); CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, (LPARAM)szURL); } PostMessage(hwndDlg, WM_MOUSEACTIVATE, 0, 0); @@ -2316,7 +2316,7 @@ LABEL_SHOWWINDOW: USERINFO *ui = pci->SM_GetUserFromIndex(parentdat->ptszID, parentdat->pszModule, item); if (ui != NULL) { static TCHAR ptszBuf[1024]; - mir_sntprintf(ptszBuf, SIZEOF(ptszBuf), _T("%s: %s\r\n%s: %s\r\n%s: %s"), + mir_sntprintf(ptszBuf, _countof(ptszBuf), _T("%s: %s\r\n%s: %s\r\n%s: %s"), TranslateT("Nickname"), ui->pszNick, TranslateT("Unique ID"), ui->pszUID, TranslateT("Status"), pci->TM_WordToString(parentdat->pStatuses, ui->Status)); @@ -2435,11 +2435,11 @@ LABEL_SHOWWINDOW: _tcsncpy_s(szName, (pInfo->ptszModDispName ? pInfo->ptszModDispName : _A2T(si->pszModule)), _TRUNCATE); ValidateFilename(szName); - mir_sntprintf(szFolder, SIZEOF(szFolder), _T("%s\\%s"), g_Settings.pszLogDir, szName); + mir_sntprintf(szFolder, _countof(szFolder), _T("%s\\%s"), g_Settings.pszLogDir, szName); mir_sntprintf(szName, _T("%s.log"), si->ptszID); ValidateFilename(szName); - mir_sntprintf(szFile, SIZEOF(szFile), _T("%s\\%s"), szFolder, szName); + mir_sntprintf(szFile, _countof(szFile), _T("%s\\%s"), szFolder, szName); ShellExecute(hwndDlg, _T("open"), szFile, NULL, NULL, SW_SHOW); } } -- cgit v1.2.3