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/Weather/src/weather.cpp | 2 +- plugins/Weather/src/weather_addstn.cpp | 32 +++++------ plugins/Weather/src/weather_contacts.cpp | 66 +++++++++++----------- plugins/Weather/src/weather_conv.cpp | 22 ++++---- plugins/Weather/src/weather_data.cpp | 72 ++++++++++++------------ plugins/Weather/src/weather_http.cpp | 2 +- plugins/Weather/src/weather_icons.cpp | 6 +- plugins/Weather/src/weather_info.cpp | 94 ++++++++++++++++---------------- plugins/Weather/src/weather_ini.cpp | 16 +++--- plugins/Weather/src/weather_mwin.cpp | 2 +- plugins/Weather/src/weather_opt.cpp | 22 ++++---- plugins/Weather/src/weather_popup.cpp | 24 ++++---- plugins/Weather/src/weather_svcs.cpp | 6 +- plugins/Weather/src/weather_update.cpp | 34 ++++++------ plugins/Weather/src/weather_userinfo.cpp | 2 +- 15 files changed, 201 insertions(+), 201 deletions(-) (limited to 'plugins/Weather/src') diff --git a/plugins/Weather/src/weather.cpp b/plugins/Weather/src/weather.cpp index ed3196c1e5..1a4127fa05 100644 --- a/plugins/Weather/src/weather.cpp +++ b/plugins/Weather/src/weather.cpp @@ -229,7 +229,7 @@ extern "C" int __declspec(dllexport) Load(void) // window needed for popup commands TCHAR SvcFunc[100]; - mir_sntprintf(SvcFunc, SIZEOF(SvcFunc), _T("%s__PopupWindow"), _T(WEATHERPROTONAME)); + mir_sntprintf(SvcFunc, _countof(SvcFunc), _T("%s__PopupWindow"), _T(WEATHERPROTONAME)); hPopupWindow = CreateWindowEx(WS_EX_TOOLWINDOW, _T("static"), SvcFunc, 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, NULL, hInst, NULL); SetWindowLongPtr(hPopupWindow, GWLP_WNDPROC, (LONG_PTR)PopupWndProc); diff --git a/plugins/Weather/src/weather_addstn.cpp b/plugins/Weather/src/weather_addstn.cpp index 878b590c65..167675d2e5 100644 --- a/plugins/Weather/src/weather_addstn.cpp +++ b/plugins/Weather/src/weather_addstn.cpp @@ -70,7 +70,7 @@ INT_PTR WeatherAddToList(WPARAM wParam, LPARAM lParam) // set contact info and settings TCHAR svc[256]; - _tcsncpy(svc, psr->email.t, SIZEOF(svc)); svc[SIZEOF(svc)-1] = 0; + _tcsncpy(svc, psr->email.t, _countof(svc)); svc[_countof(svc)-1] = 0; GetSvc(svc); // set settings by obtaining the default for the service if (psr->lastName.t[0] != 0) { @@ -90,7 +90,7 @@ INT_PTR WeatherAddToList(WPARAM wParam, LPARAM lParam) AvatarDownloaded(hContact); TCHAR str[256]; - mir_sntprintf(str, SIZEOF(str), TranslateT("Current weather information for %s."), psr->nick.t); + mir_sntprintf(str, _countof(str), TranslateT("Current weather information for %s."), psr->nick.t); db_set_ts(hContact, WEATHERPROTONAME, "About", str); // make the last update tags to something invalid @@ -104,12 +104,12 @@ INT_PTR WeatherAddToList(WPARAM wParam, LPARAM lParam) // if no default station is found, set the new contact as default station if (opt.Default[0] == 0) { DBVARIANT dbv; - GetStationID(hContact, opt.Default, SIZEOF(opt.Default)); + GetStationID(hContact, opt.Default, _countof(opt.Default)); opt.DefStn = hContact; if ( !db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) { // notification message box - mir_sntprintf(str, SIZEOF(str), TranslateT("%s is now the default weather station"), dbv.ptszVal); + mir_sntprintf(str, _countof(str), TranslateT("%s is now the default weather station"), dbv.ptszVal); db_free(&dbv); MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK|MB_ICONINFORMATION); } @@ -155,8 +155,8 @@ static void __cdecl BasicSearchTimerProc(LPVOID hWnd) INT_PTR WeatherBasicSearch(WPARAM wParam, LPARAM lParam) { if (searchId != -1) return 0; //only one search at a time - _tcsncpy(sID, ( TCHAR* )lParam, SIZEOF(sID)); - sID[SIZEOF(sID)-1] = 0; + _tcsncpy(sID, ( TCHAR* )lParam, _countof(sID)); + sID[_countof(sID)-1] = 0; searchId = 1; // create a thread for the ID search mir_forkthread(BasicSearchTimerProc, NULL); @@ -210,7 +210,7 @@ INT_PTR WeatherAdvancedSearch(WPARAM, LPARAM lParam) if (searchId != -1) return 0; //only one search at a time searchId = 1; - GetDlgItemText((HWND)lParam, IDC_SEARCHCITY, name1, SIZEOF(name1)); + GetDlgItemText((HWND)lParam, IDC_SEARCHCITY, name1, _countof(name1)); // search for the weather station using a thread mir_forkthread(NameSearchTimerProc, NULL); @@ -233,7 +233,7 @@ int IDSearchProc(TCHAR *sID, const int searchId, WIIDSEARCH *sData, TCHAR *svc, TCHAR *szData = NULL; // load the page - mir_snprintf(loc, SIZEOF(loc), sData->SearchURL, sID); + mir_snprintf(loc, _countof(loc), sData->SearchURL, sID); BOOL bFound = (InternetDownloadFile(loc, NULL, NULL, &szData) == 0); if (bFound) { TCHAR* szInfo = szData; @@ -250,7 +250,7 @@ int IDSearchProc(TCHAR *sID, const int searchId, WIIDSEARCH *sData, TCHAR *svc, // give no station name but only ID if the search is unavailable else _tcsncpy(str, TranslateT(""), MAX_DATA_LEN - 1); - mir_sntprintf(newID, SIZEOF(newID), _T("%s/%s"), svc, sID); + mir_sntprintf(newID, _countof(newID), _T("%s/%s"), svc, sID); // set the search result and broadcast it PROTOSEARCHRESULT psr = { sizeof(psr) }; @@ -310,7 +310,7 @@ int NameSearchProc(TCHAR *name, const int searchId, WINAMESEARCH *sData, TCHAR * // replace spaces with %20 char loc[256]; T2Utf szSearchName(name); - mir_snprintf(loc, SIZEOF(loc), sData->SearchURL, ptrA( mir_urlEncode(szSearchName))); + mir_snprintf(loc, _countof(loc), sData->SearchURL, ptrA( mir_urlEncode(szSearchName))); if (InternetDownloadFile(loc, NULL, NULL, &szData) == 0) { TCHAR* szInfo = szData; search = _tcsstr(szInfo, sData->NotFoundStr); // determine if data is available @@ -323,14 +323,14 @@ int NameSearchProc(TCHAR *name, const int searchId, WINAMESEARCH *sData, TCHAR * // if station ID appears first in the downloaded data if ( !mir_tstrcmpi(sData->Single.First, _T("ID"))) { GetDataValue(&sData->Single.ID, str, &szInfo); - mir_sntprintf(sID, SIZEOF(sID), _T("%s/%s"), svc, str); + mir_sntprintf(sID, _countof(sID), _T("%s/%s"), svc, str); GetDataValue(&sData->Single.Name, Name, &szInfo); } // if station name appears first in the downloaded data else if ( !mir_tstrcmpi(sData->Single.First, _T("NAME"))) { GetDataValue(&sData->Single.Name, Name, &szInfo); GetDataValue(&sData->Single.ID, str, &szInfo); - mir_sntprintf(sID, SIZEOF(sID), _T("%s/%s"), svc, str); + mir_sntprintf(sID, _countof(sID), _T("%s/%s"), svc, str); } else str[0] = 0; @@ -343,7 +343,7 @@ int NameSearchProc(TCHAR *name, const int searchId, WINAMESEARCH *sData, TCHAR * // if can't get the name, use the search string as name if (Name[0] == 0) - _tcsncpy(Name, name, SIZEOF(Name)); + _tcsncpy(Name, name, _countof(Name)); // set the data and broadcast it PROTOSEARCHRESULT psr = { sizeof(psr) }; @@ -364,14 +364,14 @@ int NameSearchProc(TCHAR *name, const int searchId, WINAMESEARCH *sData, TCHAR * // if station ID appears first in the downloaded data if ( !mir_tstrcmpi(sData->Multiple.First, _T("ID"))) { GetDataValue(&sData->Multiple.ID, str, &szInfo); - mir_sntprintf(sID, SIZEOF(sID), _T("%s/%s"), svc, str); + mir_sntprintf(sID, _countof(sID), _T("%s/%s"), svc, str); GetDataValue(&sData->Multiple.Name, Name, &szInfo); } // if station name appears first in the downloaded data else if ( !mir_tstrcmpi(sData->Multiple.First, _T("NAME"))) { GetDataValue(&sData->Multiple.Name, Name, &szInfo); GetDataValue(&sData->Multiple.ID, str, &szInfo); - mir_sntprintf(sID, SIZEOF(sID), _T("%s/%s"), svc, str); + mir_sntprintf(sID, _countof(sID), _T("%s/%s"), svc, str); } else break; @@ -382,7 +382,7 @@ int NameSearchProc(TCHAR *name, const int searchId, WINAMESEARCH *sData, TCHAR * // if can't get the name, use the search string as name if (Name[0] == 0) - _tcsncpy(Name, name, SIZEOF(Name)); + _tcsncpy(Name, name, _countof(Name)); PROTOSEARCHRESULT psr = { sizeof(psr) }; psr.flags = PSR_TCHAR; diff --git a/plugins/Weather/src/weather_contacts.cpp b/plugins/Weather/src/weather_contacts.cpp index bd99e5df8b..4aed6418df 100644 --- a/plugins/Weather/src/weather_contacts.cpp +++ b/plugins/Weather/src/weather_contacts.cpp @@ -30,7 +30,7 @@ static void OpenUrl( TCHAR* format, TCHAR* id ) TCHAR loc[512]; GetID( id ); - mir_sntprintf(loc, SIZEOF(loc), format, id); + mir_sntprintf(loc, _countof(loc), format, id); CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, (LPARAM)loc ); } @@ -59,10 +59,10 @@ INT_PTR ViewLog(WPARAM wParam, LPARAM lParam) INT_PTR LoadForecast(WPARAM wParam, LPARAM lParam) { TCHAR id[256], loc2[256]; - GetStationID(wParam, id, SIZEOF(id)); + GetStationID(wParam, id, _countof(id)); if (id[0] != 0) { // check if the complte forecast URL is set. If it is not, display warning and quit - if (DBGetStaticString(wParam, WEATHERPROTONAME, "InfoURL", loc2, SIZEOF(loc2)) || loc2[0] == 0) { + if (DBGetStaticString(wParam, WEATHERPROTONAME, "InfoURL", loc2, _countof(loc2)) || loc2[0] == 0) { MessageBox(NULL, NO_FORECAST_URL, TranslateT("Weather Protocol"), MB_ICONINFORMATION); return 1; } @@ -77,10 +77,10 @@ INT_PTR LoadForecast(WPARAM wParam, LPARAM lParam) INT_PTR WeatherMap(WPARAM wParam, LPARAM lParam) { TCHAR id[256], loc2[256]; - GetStationID(wParam, id, SIZEOF(id)); + GetStationID(wParam, id, _countof(id)); if (id[0] != 0) { // check if the weather map URL is set. If it is not, display warning and quit - if (DBGetStaticString(wParam, WEATHERPROTONAME, "MapURL", loc2, SIZEOF(loc2)) || loc2[0] == 0) { + if (DBGetStaticString(wParam, WEATHERPROTONAME, "MapURL", loc2, _countof(loc2)) || loc2[0] == 0) { MessageBox(NULL, NO_MAP_URL, TranslateT("Weather Protocol"), MB_ICONINFORMATION); return 1; } @@ -227,7 +227,7 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa case IDC_ID: // check if there are 2 parts in the ID (svc/id) seperated by "/" // if not, don't let user change the setting - GetDlgItemText(hwndDlg, IDC_ID, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_ID, str, _countof(str)); chop = _tcsstr(str, _T("/")); if (chop == NULL) EnableWindow(GetDlgItem(hwndDlg, IDC_CHANGE), FALSE); @@ -238,7 +238,7 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa case IDC_NAME: // check if station name is entered // if not, don't let user change the setting - GetDlgItemText(hwndDlg, IDC_NAME, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_NAME, str, _countof(str)); EnableWindow(GetDlgItem(hwndDlg, IDC_CHANGE), str[0] != 0); break; @@ -249,17 +249,17 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa if ( !CheckSearch()) return TRUE; // don't download if update is in progress // get the weather update data using the string in the ID field - GetDlgItemText(hwndDlg, IDC_ID, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_ID, str, _countof(str)); GetSvc(str); WIDATA *sData = GetWIData(str); - GetDlgItemText(hwndDlg, IDC_ID, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_ID, str, _countof(str)); GetID(str); // if ID search is available, do it if (sData->IDSearch.Available) { TCHAR *szData = NULL; // load the page - mir_snprintf(loc, SIZEOF(loc), sData->IDSearch.SearchURL, str); + mir_snprintf(loc, _countof(loc), sData->IDSearch.SearchURL, str); str[0] = 0; if (InternetDownloadFile(loc, NULL, sData->UserAgent, &szData) == 0) { TCHAR *szInfo = szData; @@ -285,23 +285,23 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa case IDC_BROWSE: // fall through // browse for the external log file - GetDlgItemText(hwndDlg, IDC_LOG, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_LOG, str, _countof(str)); // Initialize OPENFILENAME memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwndDlg; ofn.lpstrFile = str; - ofn.nMaxFile = SIZEOF(str); + ofn.nMaxFile = _countof(str); // set filters - _tcsncpy(filter, TranslateT("Text Files"), SIZEOF(filter) - 1); - mir_tstrncat(filter, _T(" (*.txt)"), SIZEOF(filter) - mir_tstrlen(filter)); + _tcsncpy(filter, TranslateT("Text Files"), _countof(filter) - 1); + mir_tstrncat(filter, _T(" (*.txt)"), _countof(filter) - mir_tstrlen(filter)); pfilter = filter + mir_tstrlen(filter)+1; - _tcsncpy(pfilter, _T("*.txt"), SIZEOF(filter) - 1); + _tcsncpy(pfilter, _T("*.txt"), _countof(filter) - 1); pfilter = pfilter + mir_tstrlen(pfilter)+1; - _tcsncpy(pfilter, TranslateT("All Files"), SIZEOF(filter) - 1); - mir_tstrncat(pfilter, _T(" (*.*)"), SIZEOF(filter) - mir_tstrlen(filter)); + _tcsncpy(pfilter, TranslateT("All Files"), _countof(filter) - 1); + mir_tstrncat(pfilter, _T(" (*.*)"), _countof(filter) - mir_tstrlen(filter)); pfilter = pfilter + mir_tstrlen(pfilter)+1; - _tcsncpy(pfilter, _T("*.*"), SIZEOF(filter) - 1); + _tcsncpy(pfilter, _T("*.*"), _countof(filter) - 1); pfilter = pfilter + mir_tstrlen(pfilter)+1; *pfilter = '\0'; ofn.lpstrFilter = filter; @@ -320,23 +320,23 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa case IDC_VIEW1: // view the page for more info - GetDlgItemText(hwndDlg, IDC_IURL, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_IURL, str, _countof(str)); if (str[0] == 0) return TRUE; - GetDlgItemText(hwndDlg, IDC_ID, str2, SIZEOF(str2)); + GetDlgItemText(hwndDlg, IDC_ID, str2, _countof(str2)); OpenUrl(str, str2); break; case IDC_VIEW2: // view the page for weather map - GetDlgItemText(hwndDlg, IDC_MURL, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_MURL, str, _countof(str)); if (str[0] == 0) return TRUE; - GetDlgItemText(hwndDlg, IDC_ID, str2, SIZEOF(str2)); + GetDlgItemText(hwndDlg, IDC_ID, str2, _countof(str2)); OpenUrl(str, str2); break; case IDC_RESET1: // reset the more info url to service default - GetDlgItemText(hwndDlg, IDC_ID, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_ID, str, _countof(str)); GetSvc(str); sData = GetWIData(str); SetDlgItemTextA(hwndDlg, IDC_IURL, sData->DefaultURL); @@ -344,7 +344,7 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa case IDC_RESET2: // reset the weathe map url to service default - GetDlgItemText(hwndDlg, IDC_ID, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_ID, str, _countof(str)); GetSvc(str); sData = GetWIData(str); SetDlgItemText(hwndDlg, IDC_MURL, sData->DefaultMap); @@ -352,7 +352,7 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa case IDC_SVCINFO: // display the information of the ini file used by the weather station - GetDlgItemText(hwndDlg, IDC_ID, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_ID, str, _countof(str)); GetSvc(str); GetINIInfo(str); break; @@ -360,26 +360,26 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa case IDC_CHANGE: // temporary disable the protocol while applying the change // start writing the new settings to database - GetDlgItemText(hwndDlg, IDC_ID, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_ID, str, _countof(str)); db_set_ts(hContact, WEATHERPROTONAME, "ID", str); if ((BYTE)IsDlgButtonChecked(hwndDlg, IDC_DEFA)) { // if default station is set mir_tstrcpy(opt.Default, str); opt.DefStn = hContact; db_set_ts(NULL, WEATHERPROTONAME, "Default", opt.Default); } - GetDlgItemText(hwndDlg, IDC_NAME, city, SIZEOF(city)); + GetDlgItemText(hwndDlg, IDC_NAME, city, _countof(city)); db_set_ts(hContact, WEATHERPROTONAME, "Nick", city); - mir_sntprintf(str2, SIZEOF(str2), TranslateT("Current weather information for %s."), city); + mir_sntprintf(str2, _countof(str2), TranslateT("Current weather information for %s."), city); if ((BYTE)IsDlgButtonChecked(hwndDlg, IDC_External)) { - GetDlgItemText(hwndDlg, IDC_LOG, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_LOG, str, _countof(str)); db_set_ts(hContact, WEATHERPROTONAME, "Log", str); } else db_unset(hContact, WEATHERPROTONAME, "Log"); - GetDlgItemText(hwndDlg, IDC_IURL, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_IURL, str, _countof(str)); db_set_ts(hContact, WEATHERPROTONAME, "InfoURL", str); - GetDlgItemText(hwndDlg, IDC_MURL, str, SIZEOF(str)); + GetDlgItemText(hwndDlg, IDC_MURL, str, _countof(str)); db_set_ts(hContact, WEATHERPROTONAME, "MapURL", str); db_set_w(hContact, WEATHERPROTONAME, "Status", ID_STATUS_OFFLINE); db_set_w(hContact, WEATHERPROTONAME, "StatusIcon", ID_STATUS_OFFLINE); @@ -452,12 +452,12 @@ int ContactDeleted(WPARAM wParam, LPARAM lParam) // if the station is not a default station, set it as the new default station // this is the first weather station encountered from the search if ( mir_tstrcmp(opt.Default, dbv.ptszVal)) { - _tcsncpy(opt.Default, dbv.ptszVal, SIZEOF(opt.Default) - 1); + _tcsncpy(opt.Default, dbv.ptszVal, _countof(opt.Default) - 1); opt.DefStn = hContact; db_free(&dbv); if ( !db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) { TCHAR str[255]; - mir_sntprintf(str, SIZEOF(str), TranslateT("%s is now the default weather station"), dbv.ptszVal); + mir_sntprintf(str, _countof(str), TranslateT("%s is now the default weather station"), dbv.ptszVal); db_free(&dbv); MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK | MB_ICONINFORMATION); } diff --git a/plugins/Weather/src/weather_conv.cpp b/plugins/Weather/src/weather_conv.cpp index 64fa4fa6d6..22bd529140 100644 --- a/plugins/Weather/src/weather_conv.cpp +++ b/plugins/Weather/src/weather_conv.cpp @@ -107,7 +107,7 @@ void GetTemp(TCHAR *tempchar, TCHAR *unit, TCHAR* str) switch (opt.tUnit) { case 1: // rounding - numToStr((temp-32)/9*5, tstr, SIZEOF(tstr)); + numToStr((temp-32)/9*5, tstr, _countof(tstr)); if (opt.DoNotAppendUnit) _tcsncpy_s(str, MAX_DATA_LEN, tstr, _TRUNCATE); else @@ -115,7 +115,7 @@ void GetTemp(TCHAR *tempchar, TCHAR *unit, TCHAR* str) break; case 2: - numToStr(temp, tstr, SIZEOF(tstr)); + numToStr(temp, tstr, _countof(tstr)); if (opt.DoNotAppendUnit) _tcsncpy_s(str, MAX_DATA_LEN, tstr, _TRUNCATE); else @@ -212,19 +212,19 @@ void GetSpeed(TCHAR *tempchar, TCHAR *unit, TCHAR *str) // convert to apporiate unit switch (opt.wUnit) { case 1: - numToStr(tempunit * 3.6, tstr, SIZEOF(tstr)); + numToStr(tempunit * 3.6, tstr, _countof(tstr)); mir_sntprintf(str, MAX_DATA_LEN, _T("%s %s"), tstr, opt.DoNotAppendUnit ? _T("") : TranslateT("km/h")); break; case 2: - numToStr(tempunit, tstr, SIZEOF(tstr)); + numToStr(tempunit, tstr, _countof(tstr)); mir_sntprintf(str, MAX_DATA_LEN, _T("%s %s"), tstr, opt.DoNotAppendUnit ? _T("") : TranslateT("m/s")); break; case 3: - numToStr(tempunit / 0.44704, tstr, SIZEOF(tstr)); + numToStr(tempunit / 0.44704, tstr, _countof(tstr)); mir_sntprintf(str, MAX_DATA_LEN, _T("%s %s"), tstr, opt.DoNotAppendUnit ? _T("") : TranslateT("mph")); break; case 4: - numToStr(tempunit / 0.514444, tstr, SIZEOF(tstr)); + numToStr(tempunit / 0.514444, tstr, _countof(tstr)); mir_sntprintf(str, MAX_DATA_LEN, _T("%s %s"), tstr, opt.DoNotAppendUnit ? _T("") : TranslateT("knots")); break; } @@ -393,7 +393,7 @@ WORD GetIcon(const TCHAR* cond, WIDATA *Data) do { j++; // using the format _T("# Weather #" - mir_sntprintf(LangPackStr, SIZEOF(LangPackStr), _T("# Weather %s %i #"), statusStr[i], j); + mir_sntprintf(LangPackStr, _countof(LangPackStr), _T("# Weather %s %i #"), statusStr[i], j); _tcsncpy_s(LangPackStr1, TranslateTS(LangPackStr), _TRUNCATE); CharLowerBuff(LangPackStr1, (DWORD)mir_tstrlen(LangPackStr1)); if (_tcsstr(cond, LangPackStr1) != NULL) @@ -522,7 +522,7 @@ TCHAR* GetDisplay(WEATHERINFO *w, const TCHAR *dis, TCHAR* str) switch (chr) { case 'c': mir_tstrcat(str, w->cond); break; case 'd': // get the current date - GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, lpzDate, SIZEOF(lpzDate)); + GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, lpzDate, _countof(lpzDate)); mir_tstrcat(str, lpzDate); break; case 'e': mir_tstrcat(str, w->dewpoint); break; case 'f': mir_tstrcat(str, w->feel); break; @@ -548,7 +548,7 @@ TCHAR* GetDisplay(WEATHERINFO *w, const TCHAR *dis, TCHAR* str) name[0] = 0; // read the entire variable name while (dis[i] != ']' && i < mir_tstrlen(dis)) { - mir_snprintf(temp, SIZEOF(temp), "%c", dis[i++]); + mir_snprintf(temp, _countof(temp), "%c", dis[i++]); mir_strcat(name, temp); } // access the database to get its value @@ -562,7 +562,7 @@ TCHAR* GetDisplay(WEATHERINFO *w, const TCHAR *dis, TCHAR* str) } // if the character is not a variable, write the original character to the new string else { - mir_sntprintf(lpzDate, SIZEOF(lpzDate), _T("%c"), dis[i]); + mir_sntprintf(lpzDate, _countof(lpzDate), _T("%c"), dis[i]); mir_tstrcat(str, lpzDate); } } @@ -634,7 +634,7 @@ TCHAR *GetError(int code) case 503: str = E503; break; case 504: str = E504; break; default: - mir_sntprintf(str2, SIZEOF(str2), TranslateT("HTTP Error %i"), code); + mir_sntprintf(str2, _countof(str2), TranslateT("HTTP Error %i"), code); str = str2; break; } diff --git a/plugins/Weather/src/weather_data.cpp b/plugins/Weather/src/weather_data.cpp index a5e9c5737d..b800bd0f94 100644 --- a/plugins/Weather/src/weather_data.cpp +++ b/plugins/Weather/src/weather_data.cpp @@ -47,38 +47,38 @@ WEATHERINFO LoadWeatherInfo(MCONTACT hContact) // if the string is not found in database, a value of "N/A" is stored in the field WEATHERINFO winfo; winfo.hContact = hContact; - GetStationID(hContact, winfo.id, SIZEOF(winfo.id)); - - if (DBGetStaticString(hContact, WEATHERPROTONAME, "Nick", winfo.city, SIZEOF(winfo.city))) - _tcsncpy(winfo.city, NODATA, SIZEOF(winfo.city) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Update", winfo.update, SIZEOF(winfo.update))) - _tcsncpy(winfo.update, NODATA, SIZEOF(winfo.update) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Condition", winfo.cond, SIZEOF(winfo.cond))) - _tcsncpy(winfo.cond, NODATA, SIZEOF(winfo.cond) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Temperature", winfo.temp, SIZEOF(winfo.temp))) - _tcsncpy(winfo.temp, NODATA, SIZEOF(winfo.temp) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "High", winfo.high, SIZEOF(winfo.high))) - _tcsncpy(winfo.high, NODATA, SIZEOF(winfo.high) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Low", winfo.low, SIZEOF(winfo.low))) - _tcsncpy(winfo.low, NODATA, SIZEOF(winfo.low) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Sunset", winfo.sunset, SIZEOF(winfo.sunset))) - _tcsncpy(winfo.sunset, NODATA, SIZEOF(winfo.sunset) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Sunrise", winfo.sunrise, SIZEOF(winfo.sunrise))) - _tcsncpy(winfo.sunrise, NODATA, SIZEOF(winfo.sunrise) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Wind Speed", winfo.wind, SIZEOF(winfo.wind))) - _tcsncpy(winfo.wind, NODATA, SIZEOF(winfo.wind) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Wind Direction", winfo.winddir, SIZEOF(winfo.winddir))) - _tcsncpy(winfo.winddir, NODATA, SIZEOF(winfo.winddir) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Dewpoint", winfo.dewpoint, SIZEOF(winfo.dewpoint))) - _tcsncpy(winfo.dewpoint, NODATA, SIZEOF(winfo.dewpoint) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Pressure", winfo.pressure, SIZEOF(winfo.pressure))) - _tcsncpy(winfo.pressure, NODATA, SIZEOF(winfo.pressure) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Visibility", winfo.vis, SIZEOF(winfo.vis))) - _tcsncpy(winfo.vis, NODATA, SIZEOF(winfo.vis) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Humidity", winfo.humid, SIZEOF(winfo.humid))) - _tcsncpy(winfo.humid, NODATA, SIZEOF(winfo.humid) - 1); - if (DBGetStaticString(hContact, WEATHERCONDITION, "Feel", winfo.feel, SIZEOF(winfo.feel))) - _tcsncpy(winfo.feel, NODATA, SIZEOF(winfo.feel) - 1); + GetStationID(hContact, winfo.id, _countof(winfo.id)); + + if (DBGetStaticString(hContact, WEATHERPROTONAME, "Nick", winfo.city, _countof(winfo.city))) + _tcsncpy(winfo.city, NODATA, _countof(winfo.city) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Update", winfo.update, _countof(winfo.update))) + _tcsncpy(winfo.update, NODATA, _countof(winfo.update) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Condition", winfo.cond, _countof(winfo.cond))) + _tcsncpy(winfo.cond, NODATA, _countof(winfo.cond) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Temperature", winfo.temp, _countof(winfo.temp))) + _tcsncpy(winfo.temp, NODATA, _countof(winfo.temp) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "High", winfo.high, _countof(winfo.high))) + _tcsncpy(winfo.high, NODATA, _countof(winfo.high) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Low", winfo.low, _countof(winfo.low))) + _tcsncpy(winfo.low, NODATA, _countof(winfo.low) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Sunset", winfo.sunset, _countof(winfo.sunset))) + _tcsncpy(winfo.sunset, NODATA, _countof(winfo.sunset) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Sunrise", winfo.sunrise, _countof(winfo.sunrise))) + _tcsncpy(winfo.sunrise, NODATA, _countof(winfo.sunrise) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Wind Speed", winfo.wind, _countof(winfo.wind))) + _tcsncpy(winfo.wind, NODATA, _countof(winfo.wind) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Wind Direction", winfo.winddir, _countof(winfo.winddir))) + _tcsncpy(winfo.winddir, NODATA, _countof(winfo.winddir) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Dewpoint", winfo.dewpoint, _countof(winfo.dewpoint))) + _tcsncpy(winfo.dewpoint, NODATA, _countof(winfo.dewpoint) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Pressure", winfo.pressure, _countof(winfo.pressure))) + _tcsncpy(winfo.pressure, NODATA, _countof(winfo.pressure) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Visibility", winfo.vis, _countof(winfo.vis))) + _tcsncpy(winfo.vis, NODATA, _countof(winfo.vis) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Humidity", winfo.humid, _countof(winfo.humid))) + _tcsncpy(winfo.humid, NODATA, _countof(winfo.humid) - 1); + if (DBGetStaticString(hContact, WEATHERCONDITION, "Feel", winfo.feel, _countof(winfo.feel))) + _tcsncpy(winfo.feel, NODATA, _countof(winfo.feel) - 1); winfo.status = (WORD)db_get_w(hContact, WEATHERPROTONAME, "StatusIcon", ID_STATUS_OFFLINE); return winfo; @@ -150,11 +150,11 @@ void EraseAllInfo() // if no default station find, assign a new one if (opt.Default[0] == 0) { - GetStationID(hContact, opt.Default, SIZEOF(opt.Default)); + GetStationID(hContact, opt.Default, _countof(opt.Default)); opt.DefStn = hContact; if ( !db_get_ts(hContact,WEATHERPROTONAME, "Nick",&dbv)) { - mir_sntprintf(str, SIZEOF(str), TranslateT("%s is now the default weather station"), dbv.ptszVal); + mir_sntprintf(str, _countof(str), TranslateT("%s is now the default weather station"), dbv.ptszVal); db_free(&dbv); MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK|MB_ICONINFORMATION); } @@ -176,12 +176,12 @@ void EraseAllInfo() // in case where the default station is missing if (opt.DefStn == NULL && ContactCount != 0) { if ( !db_get_ts(LastContact, WEATHERPROTONAME, "ID", &dbv)) { - _tcsncpy(opt.Default, dbv.ptszVal, SIZEOF(opt.Default) - 1); + _tcsncpy(opt.Default, dbv.ptszVal, _countof(opt.Default) - 1); db_free(&dbv); } opt.DefStn = LastContact; if ( !db_get_ts(LastContact,WEATHERPROTONAME, "Nick",&dbv)) { - mir_sntprintf(str, SIZEOF(str), TranslateT("%s is now the default weather station"), dbv.ptszVal); + mir_sntprintf(str, _countof(str), TranslateT("%s is now the default weather station"), dbv.ptszVal); db_free(&dbv); MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK|MB_ICONINFORMATION); } diff --git a/plugins/Weather/src/weather_http.cpp b/plugins/Weather/src/weather_http.cpp index add11a1e1c..f6258efb74 100644 --- a/plugins/Weather/src/weather_http.cpp +++ b/plugins/Weather/src/weather_http.cpp @@ -72,7 +72,7 @@ int InternetDownloadFile (char *szUrl, char *cookie, char *userAgent, TCHAR **sz nlhr.szUrl = szUrl; nlhr.nlc = hNetlibHttp; nlhr.headers = headers; - nlhr.headersCount = SIZEOF(headers); + nlhr.headersCount = _countof(headers); if (cookie == NULL || cookie[0] == 0) --nlhr.headersCount; diff --git a/plugins/Weather/src/weather_icons.cpp b/plugins/Weather/src/weather_icons.cpp index e4b548b37c..207bc0d338 100644 --- a/plugins/Weather/src/weather_icons.cpp +++ b/plugins/Weather/src/weather_icons.cpp @@ -39,19 +39,19 @@ static IconItem iconList[] = void InitIcons(void) { - Icon_Register(hInst, WEATHERPROTONAME, iconList, SIZEOF(iconList), WEATHERPROTONAME); + Icon_Register(hInst, WEATHERPROTONAME, iconList, _countof(iconList), WEATHERPROTONAME); } HICON LoadIconEx(const char* name, bool big) { char szSettingName[100]; - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%s_%s", WEATHERPROTONAME, name); + mir_snprintf(szSettingName, _countof(szSettingName), "%s_%s", WEATHERPROTONAME, name); return IcoLib_GetIcon(szSettingName, big); } HANDLE GetIconHandle(const char* name) { - for (int i=0; i < SIZEOF(iconList); i++) + for (int i=0; i < _countof(iconList); i++) if (mir_strcmp(iconList[i].szName, name) == 0) return iconList[i].hIcolib; diff --git a/plugins/Weather/src/weather_info.cpp b/plugins/Weather/src/weather_info.cpp index 39e41637c7..8065433f35 100644 --- a/plugins/Weather/src/weather_info.cpp +++ b/plugins/Weather/src/weather_info.cpp @@ -152,55 +152,55 @@ void GetINIInfo(TCHAR *pszSvc) // if the service does not exist among the loaded INI's if (sData == NULL) { - mir_sntprintf(str2, SIZEOF(str2), TranslateT("The corresponding INI file for \"%s\" is not found."), pszSvc); + mir_sntprintf(str2, _countof(str2), TranslateT("The corresponding INI file for \"%s\" is not found."), pszSvc); MessageBox(NULL, str2, TranslateT("Weather INI information"), MB_OK|MB_ICONINFORMATION); } // if exist, get the information else { - mir_sntprintf(str2, SIZEOF(str2), TranslateT("Weather INI information for \"%s\":"), pszSvc); - mir_tstrncat(str2, _T("\n\n"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, TranslateT("Name:"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\t\t"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, sData->DisplayName, SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\n"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, TranslateT("Internal Name:"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\t"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, sData->InternalName, SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\n"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, TranslateT("Author:"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\t\t"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, sData->Author, SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\n"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, TranslateT("Version:"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\t\t"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, sData->Version, SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\n"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, TranslateT("INI Version:"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\t"), SIZEOF(str2) - mir_tstrlen(str2)); + mir_sntprintf(str2, _countof(str2), TranslateT("Weather INI information for \"%s\":"), pszSvc); + mir_tstrncat(str2, _T("\n\n"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, TranslateT("Name:"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\t\t"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, sData->DisplayName, _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\n"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, TranslateT("Internal Name:"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\t"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, sData->InternalName, _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\n"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, TranslateT("Author:"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\t\t"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, sData->Author, _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\n"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, TranslateT("Version:"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\t\t"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, sData->Version, _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\n"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, TranslateT("INI Version:"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\t"), _countof(str2) - mir_tstrlen(str2)); switch (sData->InternalVer) { - case 1: mir_tstrncat(str2, _T("1.0"), SIZEOF(str2) - mir_tstrlen(str2)); break; - case 2: mir_tstrncat(str2, _T("1.1"), SIZEOF(str2) - mir_tstrlen(str2)); break; - case 3: mir_tstrncat(str2, _T("1.1a"), SIZEOF(str2) - mir_tstrlen(str2)); break; - case 4: mir_tstrncat(str2, _T("1.2"), SIZEOF(str2) - mir_tstrlen(str2)); break; - case 5: mir_tstrncat(str2, _T("1.3"), SIZEOF(str2) - mir_tstrlen(str2)); break; - case 6: mir_tstrncat(str2, _T("1.4"), SIZEOF(str2) - mir_tstrlen(str2)); break; - case 7: mir_tstrncat(str2, _T("1.5"), SIZEOF(str2) - mir_tstrlen(str2)); break; + case 1: mir_tstrncat(str2, _T("1.0"), _countof(str2) - mir_tstrlen(str2)); break; + case 2: mir_tstrncat(str2, _T("1.1"), _countof(str2) - mir_tstrlen(str2)); break; + case 3: mir_tstrncat(str2, _T("1.1a"), _countof(str2) - mir_tstrlen(str2)); break; + case 4: mir_tstrncat(str2, _T("1.2"), _countof(str2) - mir_tstrlen(str2)); break; + case 5: mir_tstrncat(str2, _T("1.3"), _countof(str2) - mir_tstrlen(str2)); break; + case 6: mir_tstrncat(str2, _T("1.4"), _countof(str2) - mir_tstrlen(str2)); break; + case 7: mir_tstrncat(str2, _T("1.5"), _countof(str2) - mir_tstrlen(str2)); break; } - mir_tstrncat(str2, _T("\n"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, TranslateT("File Name:"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\t"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, sData->ShortFileName, SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\n"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, TranslateT("Item Count:"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_sntprintf(str2, SIZEOF(str2), _T("%s\t%i\n"), str2, sData->UpdateDataCount); - mir_tstrncat(str2, TranslateT("Memory Used:"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_sntprintf(str2, SIZEOF(str2), _T("%s\t%i "), str2, sData->MemUsed); - mir_tstrncat(str2, TranslateT("bytes"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\n\n"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, TranslateT("Description:"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, _T("\n"), SIZEOF(str2) - mir_tstrlen(str2)); - mir_tstrncat(str2, sData->Description, SIZEOF(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\n"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, TranslateT("File Name:"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\t"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, sData->ShortFileName, _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\n"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, TranslateT("Item Count:"), _countof(str2) - mir_tstrlen(str2)); + mir_sntprintf(str2, _countof(str2), _T("%s\t%i\n"), str2, sData->UpdateDataCount); + mir_tstrncat(str2, TranslateT("Memory Used:"), _countof(str2) - mir_tstrlen(str2)); + mir_sntprintf(str2, _countof(str2), _T("%s\t%i "), str2, sData->MemUsed); + mir_tstrncat(str2, TranslateT("bytes"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\n\n"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, TranslateT("Description:"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, _T("\n"), _countof(str2) - mir_tstrlen(str2)); + mir_tstrncat(str2, sData->Description, _countof(str2) - mir_tstrlen(str2)); // display the message box and quit MessageBox(NULL, str2, TranslateT("Weather INI information"), MB_OK|MB_ICONINFORMATION); @@ -216,8 +216,8 @@ void MoreVarList(void) TCHAR str[10240], tempstr[1024]; // heading - _tcsncpy(str, VARS_LIST, SIZEOF(str) - 1); - mir_tstrncat(str, _T("\n\n"), SIZEOF(str) - mir_tstrlen(str)); + _tcsncpy(str, VARS_LIST, _countof(str) - 1); + mir_tstrncat(str, _T("\n\n"), _countof(str) - mir_tstrlen(str)); // loop through all weather services to find custom variables for (WIDATALIST *Item = WIHead;Item != NULL;Item = Item->next) { @@ -227,12 +227,12 @@ void MoreVarList(void) // the custom variable is defined as "%[]" // ignore the "hi" item and hidden items if ( mir_tstrcmp(WItem->Item.Name, _T("Ignore")) && WItem->Item.Name[0] != '#') { - mir_sntprintf(tempstr, SIZEOF(tempstr), _T("%c[%s]"), '%', WItem->Item.Name); + mir_sntprintf(tempstr, _countof(tempstr), _T("%c[%s]"), '%', WItem->Item.Name); TCHAR* find = _tcsstr(str, tempstr); // if the custom variable does not exist in the list, add it to the list if (find == NULL) { - mir_tstrncat(str, tempstr, SIZEOF(str) - mir_tstrlen(str)); - mir_tstrncat(str, _T(", "), SIZEOF(str) - mir_tstrlen(str)); + mir_tstrncat(str, tempstr, _countof(str) - mir_tstrlen(str)); + mir_tstrncat(str, _T(", "), _countof(str) - mir_tstrlen(str)); } } } diff --git a/plugins/Weather/src/weather_ini.cpp b/plugins/Weather/src/weather_ini.cpp index 9e636102dd..c89472cb2c 100644 --- a/plugins/Weather/src/weather_ini.cpp +++ b/plugins/Weather/src/weather_ini.cpp @@ -178,12 +178,12 @@ bool LoadWIData(bool dial) // find all *.ini file in the plugin\weather directory TCHAR szSearchPath[MAX_PATH], FileName[MAX_PATH]; - GetModuleFileName(GetModuleHandle(NULL), szSearchPath, SIZEOF(szSearchPath)); + GetModuleFileName(GetModuleHandle(NULL), szSearchPath, _countof(szSearchPath)); TCHAR *chop = _tcsrchr(szSearchPath, '\\'); if (chop == NULL) return false; *chop = '\0'; - mir_tstrncat(szSearchPath, _T("\\Plugins\\Weather\\*.ini"), SIZEOF(szSearchPath) - mir_tstrlen(szSearchPath)); + mir_tstrncat(szSearchPath, _T("\\Plugins\\Weather\\*.ini"), _countof(szSearchPath) - mir_tstrlen(szSearchPath)); _tcsncpy(FileName, szSearchPath, MAX_PATH - 1); WIN32_FIND_DATA fd; @@ -195,7 +195,7 @@ bool LoadWIData(bool dial) do { chop = _tcsrchr(FileName, '\\'); chop[1] = '\0'; - mir_tstrncat(FileName, fd.cFileName, SIZEOF(FileName) - mir_tstrlen(FileName)); + mir_tstrncat(FileName, fd.cFileName, _countof(FileName) - mir_tstrlen(FileName)); if ( mir_tstrcmpi(fd.cFileName, _T("SAMPLE_INI.INI"))) { WIDATA Data; LoadStationData(FileName, fd.cFileName, &Data); @@ -253,7 +253,7 @@ void LoadStationData(TCHAR *pszFile, TCHAR *pszShortFile, WIDATA *Data) FILE *pfile = _tfsopen(pszFile, _T("rt"), _SH_DENYWR); if (pfile != NULL) { char Line[4096]; - fgets(Line, SIZEOF(Line), pfile); + fgets(Line, _countof(Line), pfile); TrimString(Line); // make sure it is a valid weather protocol ini file @@ -274,7 +274,7 @@ void LoadStationData(TCHAR *pszFile, TCHAR *pszShortFile, WIDATA *Data) else { TCHAR str[4096]; - mir_sntprintf(str, SIZEOF(str), TranslateT("Invalid ini format for: %s"), pszFile); + mir_sntprintf(str, _countof(str), TranslateT("Invalid ini format for: %s"), pszFile); MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK|MB_ICONERROR); fclose(pfile); return; @@ -338,7 +338,7 @@ void LoadStationData(TCHAR *pszFile, TCHAR *pszShortFile, WIDATA *Data) while (!feof(pfile)) { // determine current tag - if (fgets(Line, SIZEOF(Line), pfile) == NULL) + if (fgets(Line, _countof(Line), pfile) == NULL) break; TrimString(Line); @@ -563,11 +563,11 @@ INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar case IDC_STEP2: { TCHAR szPath[1024]; - GetModuleFileName(GetModuleHandle(NULL), szPath, SIZEOF(szPath)); + GetModuleFileName(GetModuleHandle(NULL), szPath, _countof(szPath)); TCHAR *chop = _tcsrchr(szPath, '\\'); if (chop) { *chop = '\0'; - mir_tstrncat(szPath, _T("\\Plugins\\weather\\"), SIZEOF(szPath) - mir_tstrlen(szPath)); + mir_tstrncat(szPath, _T("\\Plugins\\weather\\"), _countof(szPath) - mir_tstrlen(szPath)); _tmkdir(szPath); ShellExecute((HWND)lParam, _T("open"), szPath, _T(""), _T(""), SW_SHOW); } diff --git a/plugins/Weather/src/weather_mwin.cpp b/plugins/Weather/src/weather_mwin.cpp index 921e1b7275..f1cee4e98b 100644 --- a/plugins/Weather/src/weather_mwin.cpp +++ b/plugins/Weather/src/weather_mwin.cpp @@ -252,7 +252,7 @@ static void addWindow(MCONTACT hContact) db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv); TCHAR winname[512]; - mir_sntprintf(winname, SIZEOF(winname), _T("Weather: %s"), dbv.ptszVal); + mir_sntprintf(winname, _countof(winname), _T("Weather: %s"), dbv.ptszVal); db_free(&dbv); HWND hWnd = CreateWindow( _T("WeatherFrame"), _T(""), WS_CHILD | WS_VISIBLE, diff --git a/plugins/Weather/src/weather_opt.cpp b/plugins/Weather/src/weather_opt.cpp index 77cc37b97a..691defdd08 100644 --- a/plugins/Weather/src/weather_opt.cpp +++ b/plugins/Weather/src/weather_opt.cpp @@ -373,14 +373,14 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) } // get update time and remove the old timer - GetDlgItemText(hdlg, IDC_UPDATETIME, str, SIZEOF(str)); + GetDlgItemText(hdlg, IDC_UPDATETIME, str, _countof(str)); opt.UpdateTime = (WORD)_ttoi(str); if (opt.UpdateTime < 1) opt.UpdateTime = 1; KillTimer(NULL, timerId); timerId = SetTimer(NULL, 0, opt.UpdateTime * 60000, (TIMERPROC)timerProc); // other general options - GetDlgItemText(hdlg, IDC_DEGREE, opt.DegreeSign, SIZEOF(opt.DegreeSign)); + GetDlgItemText(hdlg, IDC_DEGREE, opt.DegreeSign, _countof(opt.DegreeSign)); opt.StartupUpdate = IsDlgButtonChecked(hdlg, IDC_STARTUPUPD); opt.AutoUpdate = IsDlgButtonChecked(hdlg, IDC_UPDATE); opt.NoProtoCondition = BST_UNCHECKED == IsDlgButtonChecked(hdlg, IDC_PROTOCOND); @@ -472,7 +472,7 @@ INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) SetWindowPos(hdlg, HWND_TOPMOST, rc.left, rc.top, 0, 0, SWP_NOSIZE); TranslateDialogDefault(hdlg); // generate the display text for variable list - _tcsncpy(str, VAR_LIST_OPT, SIZEOF(str) - 1); + _tcsncpy(str, VAR_LIST_OPT, _countof(str) - 1); SetDlgItemText(hdlg, IDC_VARLIST, str); // make the more variable and other buttons flat @@ -578,21 +578,21 @@ INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) // free memory for old settings FreeTextVar(); // save new settings to memory - GetDlgItemText(hdlg, IDC_CTEXT, textstr, SIZEOF(textstr)); + GetDlgItemText(hdlg, IDC_CTEXT, textstr, _countof(textstr)); wSetData(&opt.cText, textstr); - GetDlgItemText(hdlg, IDC_BTEXT, textstr, SIZEOF(textstr)); + GetDlgItemText(hdlg, IDC_BTEXT, textstr, _countof(textstr)); wSetData(&opt.bText, textstr); - GetDlgItemText(hdlg, IDC_BTITLE, textstr, SIZEOF(textstr)); + GetDlgItemText(hdlg, IDC_BTITLE, textstr, _countof(textstr)); wSetData(&opt.bTitle, textstr); - GetDlgItemText(hdlg, IDC_ETEXT, textstr, SIZEOF(textstr)); + GetDlgItemText(hdlg, IDC_ETEXT, textstr, _countof(textstr)); wSetData(&opt.eText, textstr); - GetDlgItemText(hdlg, IDC_NTEXT, textstr, SIZEOF(textstr)); + GetDlgItemText(hdlg, IDC_NTEXT, textstr, _countof(textstr)); wSetData(&opt.nText, textstr); - GetDlgItemText(hdlg, IDC_HTEXT, textstr, SIZEOF(textstr)); + GetDlgItemText(hdlg, IDC_HTEXT, textstr, _countof(textstr)); wSetData(&opt.hText, textstr); - GetDlgItemText(hdlg, IDC_XTEXT, textstr, SIZEOF(textstr)); + GetDlgItemText(hdlg, IDC_XTEXT, textstr, _countof(textstr)); wSetData(&opt.xText, textstr); - GetDlgItemText(hdlg, IDC_BTITLE2, textstr, SIZEOF(textstr)); + GetDlgItemText(hdlg, IDC_BTITLE2, textstr, _countof(textstr)); wSetData(&opt.sText, textstr); SaveOptions(); UpdateAllInfo(0, 0); diff --git a/plugins/Weather/src/weather_popup.cpp b/plugins/Weather/src/weather_popup.cpp index 3b08a3c1a5..8e5397ac0d 100644 --- a/plugins/Weather/src/weather_popup.cpp +++ b/plugins/Weather/src/weather_popup.cpp @@ -79,8 +79,8 @@ int WeatherError(WPARAM wParam, LPARAM lParam) TCHAR str1[512], str2[512]; // get the 2 strings - _tcsncpy(str1, tszMsg, SIZEOF(str1) - 1); - _tcsncpy(str2, tszMsg, SIZEOF(str2) - 1); + _tcsncpy(str1, tszMsg, _countof(str1) - 1); + _tcsncpy(str2, tszMsg, _countof(str2) - 1); TCHAR *chop = _tcschr(str1, 255); if (chop != NULL) *chop = '\0'; @@ -88,7 +88,7 @@ int WeatherError(WPARAM wParam, LPARAM lParam) str1[0] = 0; chop = _tcschr(str2, 255); if (chop != NULL) - _tcsncpy(str2, chop+1, SIZEOF(str2) - 1); + _tcsncpy(str2, chop+1, _countof(str2) - 1); else str2[0] = 0; @@ -222,7 +222,7 @@ void ReadPopupOpt(HWND hdlg) opt.BGColour = SendDlgItemMessage(hdlg,IDC_BGCOLOUR,CPM_GETCOLOUR,0,0); // get delay time - GetDlgItemText(hdlg, IDC_DELAY, str, SIZEOF(str)); + GetDlgItemText(hdlg, IDC_DELAY, str, _countof(str)); int num = _ttoi(str); opt.pDelay = num; @@ -237,9 +237,9 @@ void ReadPopupOpt(HWND hdlg) // popup texts wfree(&opt.pText); wfree(&opt.pTitle); - GetDlgItemText(hdlg, IDC_PText, text, SIZEOF(text)); + GetDlgItemText(hdlg, IDC_PText, text, _countof(text)); wSetData(&opt.pText, text); - GetDlgItemText(hdlg, IDC_PTitle, text, SIZEOF(text)); + GetDlgItemText(hdlg, IDC_PTitle, text, _countof(text)); wSetData(&opt.pTitle, text); } @@ -261,9 +261,9 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) // click actions hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_PMENU)); hMenu1 = GetSubMenu(hMenu, 0); - GetMenuString(hMenu1, opt.LeftClickAction, str, SIZEOF(str), MF_BYCOMMAND); + GetMenuString(hMenu1, opt.LeftClickAction, str, _countof(str), MF_BYCOMMAND); SetDlgItemText(hdlg, IDC_LeftClick, TranslateTS(str)); - GetMenuString(hMenu1, opt.RightClickAction, str, SIZEOF(str), MF_BYCOMMAND); + GetMenuString(hMenu1, opt.RightClickAction, str, _countof(str), MF_BYCOMMAND); SetDlgItemText(hdlg, IDC_RightClick, TranslateTS(str)); DestroyMenu(hMenu); @@ -396,10 +396,10 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) case IDC_VAR3: // display variable list - _tcsncpy(str, _T(" \n"),SIZEOF(str) - 1); // to make the message box wider - mir_tstrncat(str, VAR_LIST_POPUP, SIZEOF(str) - mir_tstrlen(str)); - mir_tstrncat(str, _T("\n"), SIZEOF(str) - mir_tstrlen(str)); - mir_tstrncat(str, CUSTOM_VARS, SIZEOF(str) - mir_tstrlen(str)); + _tcsncpy(str, _T(" \n"),_countof(str) - 1); // to make the message box wider + mir_tstrncat(str, VAR_LIST_POPUP, _countof(str) - mir_tstrlen(str)); + mir_tstrncat(str, _T("\n"), _countof(str) - mir_tstrlen(str)); + mir_tstrncat(str, CUSTOM_VARS, _countof(str) - mir_tstrlen(str)); MessageBox(NULL, str, TranslateT("Variable List"), MB_OK|MB_ICONASTERISK|MB_TOPMOST); break; diff --git a/plugins/Weather/src/weather_svcs.cpp b/plugins/Weather/src/weather_svcs.cpp index c5ce992c7e..93629e09cb 100644 --- a/plugins/Weather/src/weather_svcs.cpp +++ b/plugins/Weather/src/weather_svcs.cpp @@ -133,7 +133,7 @@ INT_PTR WeatherGetAvatarInfo(WPARAM wParam, LPARAM lParam) unsigned i; PROTO_AVATAR_INFORMATION *pai = (PROTO_AVATAR_INFORMATION*)lParam; - GetModuleFileName(GetModuleHandle(NULL), szSearchPath, SIZEOF(szSearchPath)); + GetModuleFileName(GetModuleHandle(NULL), szSearchPath, _countof(szSearchPath)); chop = _tcsrchr(szSearchPath, '\\'); if (chop) *chop = '\0'; @@ -148,12 +148,12 @@ INT_PTR WeatherGetAvatarInfo(WPARAM wParam, LPARAM lParam) return GAIR_NOAVATAR; pai->format = PA_FORMAT_PNG; - mir_sntprintf(pai->filename, SIZEOF(pai->filename), _T("%s\\Plugins\\Weather\\%s.png"), szSearchPath, statusStr[i]); + mir_sntprintf(pai->filename, _countof(pai->filename), _T("%s\\Plugins\\Weather\\%s.png"), szSearchPath, statusStr[i]); if ( _taccess(pai->filename, 4) == 0) return GAIR_SUCCESS; pai->format = PA_FORMAT_GIF; - mir_sntprintf(pai->filename, SIZEOF(pai->filename), _T("%s\\Plugins\\Weather\\%s.gif"), szSearchPath, statusStr[i]); + mir_sntprintf(pai->filename, _countof(pai->filename), _T("%s\\Plugins\\Weather\\%s.gif"), szSearchPath, statusStr[i]); if ( _taccess(pai->filename, 4) == 0) return GAIR_SUCCESS; diff --git a/plugins/Weather/src/weather_update.cpp b/plugins/Weather/src/weather_update.cpp index afa00c84a2..5e45b69732 100644 --- a/plugins/Weather/src/weather_update.cpp +++ b/plugins/Weather/src/weather_update.cpp @@ -58,11 +58,11 @@ int UpdateWeather(MCONTACT hContact) // error occurs if the return value is not equals to 0 if (opt.ShowWarnings) { // show warnings by popup - mir_sntprintf(str, SIZEOF(str) - 105, + mir_sntprintf(str, _countof(str) - 105, TranslateT("Unable to retrieve weather information for %s"), dbv.ptszVal); - mir_tstrncat(str, _T("\n"), SIZEOF(str) - mir_tstrlen(str)); + mir_tstrncat(str, _T("\n"), _countof(str) - mir_tstrlen(str)); TCHAR *tszError = GetError(code); - mir_tstrncat(str, tszError, SIZEOF(str) - mir_tstrlen(str)); + mir_tstrncat(str, tszError, _countof(str) - mir_tstrlen(str)); WPShowMessage(str, SM_WARNING); mir_free(tszError); } @@ -106,7 +106,7 @@ int UpdateWeather(MCONTACT hContact) if (!dbres && dbv.ptszVal[0] != 0) { if (opt.AlertPopup && !db_get_b(hContact, WEATHERPROTONAME, "DPopUp", 0) && Ch) { // display alert popup - mir_sntprintf(str, SIZEOF(str), _T("Alert for %s%c%s"), winfo.city, 255, dbv.ptszVal); + mir_sntprintf(str, _countof(str), _T("Alert for %s%c%s"), winfo.city, 255, dbv.ptszVal); WPShowMessage(str, SM_WEATHERALERT); } // alert issued, set display to italic @@ -381,7 +381,7 @@ int GetWeatherData(MCONTACT hContact) { // get eacnh part of the id's TCHAR id[256]; - GetStationID(hContact, id, SIZEOF(id)); + GetStationID(hContact, id, _countof(id)); // test ID format TCHAR* szInfo = _tcschr(id, '/'); @@ -391,7 +391,7 @@ int GetWeatherData(MCONTACT hContact) GetID(id); TCHAR Svc[256]; - GetStationID(hContact, Svc, SIZEOF(Svc)); + GetStationID(hContact, Svc, _countof(Svc)); GetSvc(Svc); // check for invalid station @@ -409,19 +409,19 @@ int GetWeatherData(MCONTACT hContact) // generate update URL switch(i) { case 0: - mir_snprintf(loc, SIZEOF(loc), Data->UpdateURL, _T2A(id)); + mir_snprintf(loc, _countof(loc), Data->UpdateURL, _T2A(id)); break; case 1: - mir_snprintf(loc, SIZEOF(loc), Data->UpdateURL2, _T2A(id)); + mir_snprintf(loc, _countof(loc), Data->UpdateURL2, _T2A(id)); break; case 2: - mir_snprintf(loc, SIZEOF(loc), Data->UpdateURL3, _T2A(id)); + mir_snprintf(loc, _countof(loc), Data->UpdateURL3, _T2A(id)); break; case 3: - mir_snprintf(loc, SIZEOF(loc), Data->UpdateURL4, _T2A(id)); + mir_snprintf(loc, _countof(loc), Data->UpdateURL4, _T2A(id)); break; default: @@ -489,15 +489,15 @@ int GetWeatherData(MCONTACT hContact) case '[': // variable, add the value to the result string hasvar = TRUE; if ( !DBGetData(hContact, _T2A(str2), &dbv)) { - mir_tstrncat(DataValue, dbv.ptszVal, SIZEOF(DataValue) - mir_tstrlen(DataValue)); - DataValue[SIZEOF(DataValue)-1] = 0; + mir_tstrncat(DataValue, dbv.ptszVal, _countof(DataValue) - mir_tstrlen(DataValue)); + DataValue[_countof(DataValue)-1] = 0; db_free(&dbv); } break; case'\"': // constant, add it to the result string - mir_tstrncat(DataValue, TranslateTS(str2), SIZEOF(DataValue) - mir_tstrlen(DataValue)); - DataValue[SIZEOF(DataValue)-1] = 0; + mir_tstrncat(DataValue, TranslateTS(str2), _countof(DataValue) - mir_tstrlen(DataValue)); + DataValue[_countof(DataValue)-1] = 0; break; } @@ -513,8 +513,8 @@ int GetWeatherData(MCONTACT hContact) // for the "Break Data=" operation DBVARIANT dbv; if ( !DBGetData(hContact, _T2A(Item->Item.Start), &dbv)) { - _tcsncpy(DataValue, dbv.ptszVal, SIZEOF(DataValue)); - DataValue[SIZEOF(DataValue)-1] = 0; + _tcsncpy(DataValue, dbv.ptszVal, _countof(DataValue)); + DataValue[_countof(DataValue)-1] = 0; db_free(&dbv); } else { @@ -549,7 +549,7 @@ int GetWeatherData(MCONTACT hContact) // temporary workaround for mToolTip to show feel-like temperature if ( !mir_tstrcmp(Item->Item.Name, _T("Feel"))) db_set_ts(hContact, WEATHERCONDITION, "Heat Index", DataValue); - GetStationID(hContact, Svc, SIZEOF(Svc)); + GetStationID(hContact, Svc, _countof(Svc)); if ( !mir_tstrcmp(Svc, opt.Default)) db_set_ts(NULL, DEFCURRENTWEATHER, _T2A(Item->Item.Name), DataValue); if ( !mir_tstrcmp(Item->Item.Name, _T("Condition"))) { diff --git a/plugins/Weather/src/weather_userinfo.cpp b/plugins/Weather/src/weather_userinfo.cpp index af318beeb2..d5e57c977f 100644 --- a/plugins/Weather/src/weather_userinfo.cpp +++ b/plugins/Weather/src/weather_userinfo.cpp @@ -336,7 +336,7 @@ void LoadBriefInfoText(HWND hwndDlg, MCONTACT hContact) winfo = LoadWeatherInfo(hContact); // check if data exist. If not, display error message box if ( !(BOOL)db_get_b(hContact, WEATHERPROTONAME, "IsUpdated", FALSE)) - _tcsncpy(str, WEATHER_NO_INFO, SIZEOF(str) - 1); + _tcsncpy(str, WEATHER_NO_INFO, _countof(str) - 1); else // set the display text and show the message box GetDisplay(&winfo, opt.bText, str); -- cgit v1.2.3