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 --- protocols/Twitter/src/connection.cpp | 2 +- protocols/Twitter/src/main.cpp | 2 +- protocols/Twitter/src/oauth.cpp | 8 ++++---- protocols/Twitter/src/proto.cpp | 14 +++++++------- protocols/Twitter/src/theme.cpp | 14 +++++++------- protocols/Twitter/src/ui.cpp | 32 ++++++++++++++++---------------- 6 files changed, 36 insertions(+), 36 deletions(-) (limited to 'protocols/Twitter') diff --git a/protocols/Twitter/src/connection.cpp b/protocols/Twitter/src/connection.cpp index 5bb7e52b51..23d6e15e33 100644 --- a/protocols/Twitter/src/connection.cpp +++ b/protocols/Twitter/src/connection.cpp @@ -167,7 +167,7 @@ bool TwitterProto::NegotiateConnection() // this looks like bad code.. can someone clean this up please? or confirm that it's ok wchar_t buf[1024] = {}; - mir_snwprintf(buf, SIZEOF(buf), AuthorizeUrl.c_str(), oauthToken.c_str()); + mir_snwprintf(buf, _countof(buf), AuthorizeUrl.c_str(), oauthToken.c_str()); debugLogW(_T("**NegotiateConnection - Launching %s"), buf); ShellExecute(NULL, L"open", buf, NULL, NULL, SW_SHOWNORMAL); diff --git a/protocols/Twitter/src/main.cpp b/protocols/Twitter/src/main.cpp index 58bc371096..4a36d4412b 100644 --- a/protocols/Twitter/src/main.cpp +++ b/protocols/Twitter/src/main.cpp @@ -110,7 +110,7 @@ extern "C" int __declspec(dllexport) Load(void) extern "C" int __declspec(dllexport) Unload(void) { UninitContactMenus(); - for (size_t i = 1; i < SIZEOF(g_hEvents); i++) + for (size_t i = 1; i < _countof(g_hEvents); i++) UnhookEvent(g_hEvents[i]); return 0; diff --git a/protocols/Twitter/src/oauth.cpp b/protocols/Twitter/src/oauth.cpp index b2d8aa4795..563e5fcbc5 100644 --- a/protocols/Twitter/src/oauth.cpp +++ b/protocols/Twitter/src/oauth.cpp @@ -90,7 +90,7 @@ wstring mir_twitter::UrlGetQuery(const wstring& url) wchar_t buf[1024*4] = {}; components.lpszExtraInfo = buf; - components.dwExtraInfoLength = SIZEOF(buf); + components.dwExtraInfoLength = _countof(buf); BOOL crackUrlOk = InternetCrackUrl(url.c_str(), url.size(), 0, &components); _ASSERTE(crackUrlOk); @@ -308,7 +308,7 @@ wstring mir_twitter::OAuthNormalizeUrl(const wstring& url) if (Compare(brokenURL[L"scheme"], L"http", false) && !(Compare(brokenURL[L"port"], L"80", false)) || (Compare(brokenURL[L"scheme"], L"https", false) && !(Compare(brokenURL[L"port"], L"443", false)))) { - mir_snwprintf(port, SIZEOF(port), L":%s", brokenURL[L"port"]); + mir_snwprintf(port, _countof(port), L":%s", brokenURL[L"port"]); } // InternetCrackUrl includes ? and # elements in the path, @@ -366,7 +366,7 @@ wstring mir_twitter::OAuthCreateNonce() wstring nonce; for (int i = 0; i <= 16; ++i) - nonce += ALPHANUMERIC[rand() % (SIZEOF(ALPHANUMERIC) - 1)]; // don't count null terminator in array + nonce += ALPHANUMERIC[rand() % (_countof(ALPHANUMERIC) - 1)]; // don't count null terminator in array return nonce; } @@ -378,7 +378,7 @@ wstring mir_twitter::OAuthCreateTimestamp() _ASSERTE(utcNow != -1); wchar_t buf[100] = {}; - mir_snwprintf(buf, SIZEOF(buf), L"%I64u", utcNow); + mir_snwprintf(buf, _countof(buf), L"%I64u", utcNow); return buf; } diff --git a/protocols/Twitter/src/proto.cpp b/protocols/Twitter/src/proto.cpp index 752a3f78a2..c9bd871c80 100644 --- a/protocols/Twitter/src/proto.cpp +++ b/protocols/Twitter/src/proto.cpp @@ -45,7 +45,7 @@ TwitterProto::TwitterProto(const char *proto_name, const TCHAR *username) : // Initialize hotkeys char text[512]; - mir_snprintf(text, SIZEOF(text), "%s/Tweet", m_szModuleName); + mir_snprintf(text, _countof(text), "%s/Tweet", m_szModuleName); HOTKEYDESC hkd = { sizeof(hkd) }; hkd.pszName = text; @@ -332,7 +332,7 @@ int TwitterProto::OnModulesLoaded(WPARAM, LPARAM) // Create avatar network connection (TODO: probably remove this) char module[512]; - mir_snprintf(module, SIZEOF(module), "%sAv", m_szModuleName); + mir_snprintf(module, _countof(module), "%sAv", m_szModuleName); nlu.szSettingsModule = module; mir_sntprintf(descr, TranslateT("%s avatar connection"), m_tszUserName); nlu.ptszDescriptiveName = descr; @@ -387,7 +387,7 @@ int TwitterProto::ShowPinDialog() void TwitterProto::ShowPopup(const wchar_t *text, int Error) { POPUPDATAT popup = {}; - mir_sntprintf(popup.lptzContactName, SIZEOF(popup.lptzContactName), TranslateT("%s Protocol"), m_tszUserName); + mir_sntprintf(popup.lptzContactName, _countof(popup.lptzContactName), TranslateT("%s Protocol"), m_tszUserName); wcsncpy_s(popup.lptzText, text, _TRUNCATE); if (Error) { @@ -405,8 +405,8 @@ void TwitterProto::ShowPopup(const wchar_t *text, int Error) void TwitterProto::ShowPopup(const char *text, int Error) { POPUPDATAT popup = {}; - mir_sntprintf(popup.lptzContactName, SIZEOF(popup.lptzContactName), TranslateT("%s Protocol"), m_tszUserName); - mbcs_to_tcs(CP_UTF8, text, popup.lptzText, SIZEOF(popup.lptzText)); + mir_sntprintf(popup.lptzContactName, _countof(popup.lptzContactName), TranslateT("%s Protocol"), m_tszUserName); + mbcs_to_tcs(CP_UTF8, text, popup.lptzText, _countof(popup.lptzText)); if (Error) { popup.iSeconds = -1; popup.colorBack = 0x000000FF; @@ -429,7 +429,7 @@ void TwitterProto::SendTweetWorker(void *p) char *text = static_cast(p); if (mir_strlen(text) > 140) { // looks like the chat max outgoing msg thing doesn't work, so i'll do it here. TCHAR errorPopup[280]; - mir_sntprintf(errorPopup, SIZEOF(errorPopup), _T("Don't be crazy! Everyone knows the max tweet size is 140, and you're trying to fit %d chars in there?"), mir_strlen(text)); + mir_sntprintf(errorPopup, _countof(errorPopup), _T("Don't be crazy! Everyone knows the max tweet size is 140, and you're trying to fit %d chars in there?"), mir_strlen(text)); ShowPopup(errorPopup, 1); return; } @@ -462,7 +462,7 @@ void TwitterProto::UpdateSettings() std::tstring TwitterProto::GetAvatarFolder() { TCHAR path[MAX_PATH]; - mir_sntprintf(path, SIZEOF(path), _T("%s\\%s"), VARST(_T("%miranda_avatarcache%")), m_tszUserName); + mir_sntprintf(path, _countof(path), _T("%s\\%s"), VARST(_T("%miranda_avatarcache%")), m_tszUserName); return path; } diff --git a/protocols/Twitter/src/theme.cpp b/protocols/Twitter/src/theme.cpp index 8dcf0c2069..71e6d0316b 100644 --- a/protocols/Twitter/src/theme.cpp +++ b/protocols/Twitter/src/theme.cpp @@ -31,18 +31,18 @@ static IconItem icons[] = { LPGEN("Visit Homepage"), "homepage", 0 }, }; -static HANDLE hIconLibItem[SIZEOF(icons)]; +static HANDLE hIconLibItem[_countof(icons)]; // TODO: uninit void InitIcons(void) { - Icon_Register(g_hInstance, "Protocols/Twitter", icons, SIZEOF(icons), "Twitter"); - icons[SIZEOF(icons) - 1].hIcolib = Skin_GetIconHandle(SKINICON_EVENT_URL); + Icon_Register(g_hInstance, "Protocols/Twitter", icons, _countof(icons), "Twitter"); + icons[_countof(icons) - 1].hIcolib = Skin_GetIconHandle(SKINICON_EVENT_URL); } HANDLE GetIconHandle(const char* name) { - for (size_t i = 0; i < SIZEOF(icons); i++) + for (size_t i = 0; i < _countof(icons); i++) if (mir_strcmp(icons[i].szName, name) == 0) return hIconLibItem[i]; @@ -106,16 +106,16 @@ void InitContactMenus() void UninitContactMenus() { - for (size_t i = 0; i < SIZEOF(g_hMenuItems); i++) + for (size_t i = 0; i < _countof(g_hMenuItems); i++) CallService(MO_REMOVEMENUITEM, (WPARAM)g_hMenuItems[i], 0); UnhookEvent(g_hMenuEvts[0]); - for (size_t i = 1; i < SIZEOF(g_hMenuEvts); i++) + for (size_t i = 1; i < _countof(g_hMenuEvts); i++) DestroyServiceFunction(g_hMenuEvts[i]); } void ShowContactMenus(bool show) { - for (size_t i = 0; i < SIZEOF(g_hMenuItems); i++) + for (size_t i = 0; i < _countof(g_hMenuItems); i++) Menu_ShowItem(g_hMenuItems[i], show); } diff --git a/protocols/Twitter/src/ui.cpp b/protocols/Twitter/src/ui.cpp index c1575bd090..71dbb239c9 100644 --- a/protocols/Twitter/src/ui.cpp +++ b/protocols/Twitter/src/ui.cpp @@ -50,7 +50,7 @@ INT_PTR CALLBACK first_run_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM db_free(&dbv); } - for (size_t i = 0; i < SIZEOF(sites); i++) + for (size_t i = 0; i < _countof(sites); i++) SendDlgItemMessage(hwndDlg, IDC_SERVER, CB_ADDSTRING, 0, reinterpret_cast(sites[i])); if (!db_get_s(0, proto->ModuleName(), TWITTER_KEY_BASEURL, &dbv)) { @@ -82,12 +82,12 @@ INT_PTR CALLBACK first_run_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM char str[128]; TCHAR tstr[128]; - GetDlgItemTextA(hwndDlg, IDC_SERVER, str, SIZEOF(str) - 1); + GetDlgItemTextA(hwndDlg, IDC_SERVER, str, _countof(str) - 1); if (str[mir_strlen(str) - 1] != '/') - mir_strncat(str, "/", SIZEOF(str) - mir_strlen(str)); + mir_strncat(str, "/", _countof(str) - mir_strlen(str)); db_set_s(0, proto->ModuleName(), TWITTER_KEY_BASEURL, str); - GetDlgItemText(hwndDlg, IDC_GROUP, tstr, SIZEOF(tstr)); + GetDlgItemText(hwndDlg, IDC_GROUP, tstr, _countof(tstr)); db_set_ts(0, proto->ModuleName(), TWITTER_KEY_GROUP, tstr); return true; @@ -113,7 +113,7 @@ INT_PTR CALLBACK tweet_proc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam // Set window title TCHAR title[512]; - mir_sntprintf(title, SIZEOF(title), _T("Send Tweet for %s"), proto->m_tszUserName); + mir_sntprintf(title, _countof(title), _T("Send Tweet for %s"), proto->m_tszUserName); SetWindowText(hwndDlg, title); return true; @@ -122,7 +122,7 @@ INT_PTR CALLBACK tweet_proc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam TCHAR msg[141]; proto = reinterpret_cast(GetWindowLongPtr(hwndDlg, GWLP_USERDATA)); - GetDlgItemText(hwndDlg, IDC_TWEETMSG, msg, SIZEOF(msg)); + GetDlgItemText(hwndDlg, IDC_TWEETMSG, msg, _countof(msg)); ShowWindow(hwndDlg, SW_HIDE); char *narrow = mir_t2a_cp(msg, CP_UTF8); @@ -147,7 +147,7 @@ INT_PTR CALLBACK tweet_proc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam break; case WM_SETREPLY: char foo[512]; - mir_snprintf(foo, SIZEOF(foo), "@%s ", (char*)wParam); + mir_snprintf(foo, _countof(foo), "@%s ", (char*)wParam); size_t len = mir_strlen(foo); SetDlgItemTextA(hwndDlg, IDC_TWEETMSG, foo); @@ -181,7 +181,7 @@ INT_PTR CALLBACK options_proc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar CheckDlgButton(hwndDlg, IDC_CHATFEED, db_get_b(0, proto->ModuleName(), TWITTER_KEY_CHATFEED, 0) ? BST_CHECKED : BST_UNCHECKED); - for (size_t i = 0; i < SIZEOF(sites); i++) + for (size_t i = 0; i < _countof(sites); i++) SendDlgItemMessage(hwndDlg, IDC_BASEURL, CB_ADDSTRING, 0, reinterpret_cast(sites[i])); if (!db_get_s(0, proto->ModuleName(), TWITTER_KEY_BASEURL, &dbv)) { @@ -191,7 +191,7 @@ INT_PTR CALLBACK options_proc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar else SendDlgItemMessage(hwndDlg, IDC_BASEURL, CB_SETCURSEL, 0, 0); char pollrate_str[32]; - mir_snprintf(pollrate_str, SIZEOF(pollrate_str), "%d", db_get_dw(0, proto->ModuleName(), TWITTER_KEY_POLLRATE, 80)); + mir_snprintf(pollrate_str, _countof(pollrate_str), "%d", db_get_dw(0, proto->ModuleName(), TWITTER_KEY_POLLRATE, 80)); SetDlgItemTextA(hwndDlg, IDC_POLLRATE, pollrate_str); CheckDlgButton(hwndDlg, IDC_TWEET_MSG, db_get_b(0, proto->ModuleName(), TWITTER_KEY_TWEET_TO_MSG, 0) ? BST_CHECKED : BST_UNCHECKED); @@ -226,17 +226,17 @@ INT_PTR CALLBACK options_proc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar proto = reinterpret_cast(GetWindowLongPtr(hwndDlg, GWLP_USERDATA)); char str[128]; - GetDlgItemTextA(hwndDlg, IDC_UN, str, SIZEOF(str)); + GetDlgItemTextA(hwndDlg, IDC_UN, str, _countof(str)); db_set_s(0, proto->ModuleName(), TWITTER_KEY_UN, str); - GetDlgItemTextA(hwndDlg, IDC_BASEURL, str, SIZEOF(str) - 1); + GetDlgItemTextA(hwndDlg, IDC_BASEURL, str, _countof(str) - 1); if (str[mir_strlen(str) - 1] != '/') - mir_strncat(str, "/", SIZEOF(str) - mir_strlen(str)); + mir_strncat(str, "/", _countof(str) - mir_strlen(str)); db_set_s(0, proto->ModuleName(), TWITTER_KEY_BASEURL, str); db_set_b(0, proto->ModuleName(), TWITTER_KEY_CHATFEED, IsDlgButtonChecked(hwndDlg, IDC_CHATFEED) != 0); - GetDlgItemTextA(hwndDlg, IDC_POLLRATE, str, SIZEOF(str)); + GetDlgItemTextA(hwndDlg, IDC_POLLRATE, str, _countof(str)); int rate = atoi(str); if (rate == 0) rate = 80; @@ -260,7 +260,7 @@ namespace popup_options return -1; else if (IsDlgButtonChecked(hwndDlg, IDC_TIMEOUT_CUSTOM)) { char str[32]; - GetDlgItemTextA(hwndDlg, IDC_TIMEOUT, str, SIZEOF(str)); + GetDlgItemTextA(hwndDlg, IDC_TIMEOUT, str, _countof(str)); return atoi(str); } else // Default checked (probably) @@ -330,7 +330,7 @@ namespace popup_options } // Pick a random quote - int q = rand() % SIZEOF(quotes); + int q = rand() % _countof(quotes); _tcsncpy(popup.lptzContactName, quotes[q].name, MAX_CONTACTNAME); _tcsncpy(popup.lptzText, quotes[q].text, MAX_SECONDLINE); @@ -478,7 +478,7 @@ INT_PTR CALLBACK pin_proc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) proto = reinterpret_cast(GetWindowLongPtr(hwndDlg, GWLP_USERDATA)); char str[128]; - GetDlgItemTextA(hwndDlg, IDC_PIN, str, SIZEOF(str)); + GetDlgItemTextA(hwndDlg, IDC_PIN, str, _countof(str)); db_set_s(0, proto->ModuleName(), TWITTER_KEY_OAUTH_PIN, str); EndDialog(hwndDlg, wParam); -- cgit v1.2.3