From 02ac3e7c9a90243ab30c7ea0f780e498262123e1 Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Mon, 30 Mar 2015 19:21:44 +0000 Subject: Weather: - Minor fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@12555 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Weather/src/weather.h | 8 ++- plugins/Weather/src/weather_addstn.cpp | 2 +- plugins/Weather/src/weather_contacts.cpp | 19 +++---- plugins/Weather/src/weather_data.cpp | 32 +++++------ plugins/Weather/src/weather_info.cpp | 97 +++++++++++++++----------------- plugins/Weather/src/weather_ini.cpp | 15 ++--- plugins/Weather/src/weather_opt.cpp | 22 ++++---- plugins/Weather/src/weather_popup.cpp | 31 +++++----- plugins/Weather/src/weather_update.cpp | 6 +- plugins/Weather/src/weather_userinfo.cpp | 4 +- 10 files changed, 118 insertions(+), 118 deletions(-) (limited to 'plugins/Weather') diff --git a/plugins/Weather/src/weather.h b/plugins/Weather/src/weather.h index ab64d6237c..77550391bc 100644 --- a/plugins/Weather/src/weather.h +++ b/plugins/Weather/src/weather.h @@ -158,7 +158,13 @@ along with this program. If not, see . #define P_DEFAULT TranslateT("%n (%u)") #define p_DEFAULT TranslateT("%c, %t\\nToday: High %h, Low %l") #define s_DEFAULT TranslateT("Temperature: %[Temperature]") - +#define VAR_LIST_POPUP TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temperature\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set") +#define VAR_LIST_OPT TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temp\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set\n----------\n\\n\tnew line") +#define WEATHER_NO_INFO TranslateT("No information available.\r\nPlease update weather condition first.") +#define CUSTOM_VARS TranslateT("%[..]\tcustom variables") +#define VARS_LIST TranslateT("Here is a list of custom variables that are currently available") +#define NO_FORECAST_URL TranslateT("The URL for complete forecast has not been set. You can set it from the Edit Settings dialog.") +#define NO_MAP_URL TranslateT("The URL for weather map has not been set. You can set it from the Edit Settings dialog.") //============ OPTION STRUCT ============ diff --git a/plugins/Weather/src/weather_addstn.cpp b/plugins/Weather/src/weather_addstn.cpp index 0a1a49a3ab..b864ff840c 100644 --- a/plugins/Weather/src/weather_addstn.cpp +++ b/plugins/Weather/src/weather_addstn.cpp @@ -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 _tcscpy(str, TranslateT("")); + else _tcsncpy(str, TranslateT(""), MAX_DATA_LEN - 1); mir_sntprintf(newID, SIZEOF(newID), _T("%s/%s"), svc, sID); // set the search result and broadcast it diff --git a/plugins/Weather/src/weather_contacts.cpp b/plugins/Weather/src/weather_contacts.cpp index 31ed3ef939..58fb62a540 100644 --- a/plugins/Weather/src/weather_contacts.cpp +++ b/plugins/Weather/src/weather_contacts.cpp @@ -63,8 +63,7 @@ INT_PTR LoadForecast(WPARAM wParam, LPARAM lParam) 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) { - MessageBox(NULL, TranslateT("The URL for complete forecast have not been set. You can set it from the Edit Settings dialog."), - TranslateT("Weather Protocol"), MB_ICONINFORMATION); + MessageBox(NULL, NO_FORECAST_URL, TranslateT("Weather Protocol"), MB_ICONINFORMATION); return 1; } // set the url and open the webpage @@ -82,7 +81,7 @@ INT_PTR WeatherMap(WPARAM wParam, LPARAM lParam) 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) { - MessageBox(NULL, TranslateT("The URL for weather map have not been set. You can set it from the Edit Settings dialog."), TranslateT("Weather Protocol"), MB_ICONINFORMATION); + MessageBox(NULL, NO_MAP_URL, TranslateT("Weather Protocol"), MB_ICONINFORMATION); return 1; } @@ -294,15 +293,15 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa ofn.lpstrFile = str; ofn.nMaxFile = SIZEOF(str); // set filters - _tcsncpy(filter, TranslateT("Text Files"), SIZEOF(filter)); - _tcsncat(filter, _T(" (*.txt)"), SIZEOF(filter)); + _tcsncpy(filter, TranslateT("Text Files"), SIZEOF(filter) - 1); + _tcsncat(filter, _T(" (*.txt)"), SIZEOF(filter) - 1); pfilter = filter + _tcslen(filter)+1; - _tcsncpy(pfilter, _T("*.txt"), SIZEOF(filter)); + _tcsncpy(pfilter, _T("*.txt"), SIZEOF(filter) - 1); pfilter = pfilter + _tcslen(pfilter)+1; - _tcsncpy(pfilter, TranslateT("All Files"), SIZEOF(filter)); - _tcsncat(pfilter, _T(" (*.*)"), SIZEOF(filter)); + _tcsncpy(pfilter, TranslateT("All Files"), SIZEOF(filter) - 1); + _tcsncat(pfilter, _T(" (*.*)"), SIZEOF(filter) - 1); pfilter = pfilter + _tcslen(pfilter)+1; - _tcsncpy(pfilter, _T("*.*"), SIZEOF(filter)); + _tcsncpy(pfilter, _T("*.*"), SIZEOF(filter) - 1); pfilter = pfilter + _tcslen(pfilter)+1; *pfilter = '\0'; ofn.lpstrFilter = filter; @@ -453,7 +452,7 @@ 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 ( _tcscmp(opt.Default, dbv.ptszVal)) { - _tcscpy(opt.Default, dbv.ptszVal); + _tcsncpy(opt.Default, dbv.ptszVal, SIZEOF(opt.Default) - 1); opt.DefStn = hContact; db_free(&dbv); if ( !db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) { diff --git a/plugins/Weather/src/weather_data.cpp b/plugins/Weather/src/weather_data.cpp index 5141f24ef3..fd33528024 100644 --- a/plugins/Weather/src/weather_data.cpp +++ b/plugins/Weather/src/weather_data.cpp @@ -50,35 +50,35 @@ WEATHERINFO LoadWeatherInfo(MCONTACT hContact) GetStationID(hContact, winfo.id, SIZEOF(winfo.id)); if (DBGetStaticString(hContact, WEATHERPROTONAME, "Nick", winfo.city, SIZEOF(winfo.city))) - _tcscpy(winfo.city, NODATA); + _tcsncpy(winfo.city, NODATA, SIZEOF(winfo.city) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Update", winfo.update, SIZEOF(winfo.update))) - _tcscpy(winfo.update, NODATA); + _tcsncpy(winfo.update, NODATA, SIZEOF(winfo.update) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Condition", winfo.cond, SIZEOF(winfo.cond))) - _tcscpy(winfo.cond, NODATA); + _tcsncpy(winfo.cond, NODATA, SIZEOF(winfo.cond) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Temperature", winfo.temp, SIZEOF(winfo.temp))) - _tcscpy(winfo.temp, NODATA); + _tcsncpy(winfo.temp, NODATA, SIZEOF(winfo.temp) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "High", winfo.high, SIZEOF(winfo.high))) - _tcscpy(winfo.high, NODATA); + _tcsncpy(winfo.high, NODATA, SIZEOF(winfo.high) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Low", winfo.low, SIZEOF(winfo.low))) - _tcscpy(winfo.low, NODATA); + _tcsncpy(winfo.low, NODATA, SIZEOF(winfo.low) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Sunset", winfo.sunset, SIZEOF(winfo.sunset))) - _tcscpy(winfo.sunset, NODATA); + _tcsncpy(winfo.sunset, NODATA, SIZEOF(winfo.sunset) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Sunrise", winfo.sunrise, SIZEOF(winfo.sunrise))) - _tcscpy(winfo.sunrise, NODATA); + _tcsncpy(winfo.sunrise, NODATA, SIZEOF(winfo.sunrise) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Wind Speed", winfo.wind, SIZEOF(winfo.wind))) - _tcscpy(winfo.wind, NODATA); + _tcsncpy(winfo.wind, NODATA, SIZEOF(winfo.wind) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Wind Direction", winfo.winddir, SIZEOF(winfo.winddir))) - _tcscpy(winfo.winddir, NODATA); + _tcsncpy(winfo.winddir, NODATA, SIZEOF(winfo.winddir) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Dewpoint", winfo.dewpoint, SIZEOF(winfo.dewpoint))) - _tcscpy(winfo.dewpoint, NODATA); + _tcsncpy(winfo.dewpoint, NODATA, SIZEOF(winfo.dewpoint) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Pressure", winfo.pressure, SIZEOF(winfo.pressure))) - _tcscpy(winfo.pressure, NODATA); + _tcsncpy(winfo.pressure, NODATA, SIZEOF(winfo.pressure) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Visibility", winfo.vis, SIZEOF(winfo.vis))) - _tcscpy(winfo.vis, NODATA); + _tcsncpy(winfo.vis, NODATA, SIZEOF(winfo.vis) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Humidity", winfo.humid, SIZEOF(winfo.humid))) - _tcscpy(winfo.humid, NODATA); + _tcsncpy(winfo.humid, NODATA, SIZEOF(winfo.humid) - 1); if (DBGetStaticString(hContact, WEATHERCONDITION, "Feel", winfo.feel, SIZEOF(winfo.feel))) - _tcscpy(winfo.feel, NODATA); + _tcsncpy(winfo.feel, NODATA, SIZEOF(winfo.feel) - 1); winfo.status = (WORD)db_get_w(hContact, WEATHERPROTONAME, "StatusIcon", ID_STATUS_OFFLINE); return winfo; @@ -176,7 +176,7 @@ void EraseAllInfo() // in case where the default station is missing if (opt.DefStn == NULL && ContactCount != 0) { if ( !db_get_ts(LastContact, WEATHERPROTONAME, "ID", &dbv)) { - _tcscpy(opt.Default, dbv.ptszVal); + _tcsncpy(opt.Default, dbv.ptszVal, SIZEOF(opt.Default) - 1); db_free(&dbv); } opt.DefStn = LastContact; diff --git a/plugins/Weather/src/weather_info.cpp b/plugins/Weather/src/weather_info.cpp index 62859b800f..7eb6e420d5 100644 --- a/plugins/Weather/src/weather_info.cpp +++ b/plugins/Weather/src/weather_info.cpp @@ -34,7 +34,7 @@ void INIInfo(HWND hwndDlg) { TCHAR str[16]; size_t memused = 0; - WIDATALIST *Item = WIHead; + HWND hIniList = GetDlgItem(hwndDlg, IDC_INFOLIST); @@ -43,7 +43,7 @@ void INIInfo(HWND hwndDlg) LVITEM lvi = {0}; lvi.mask = LVIF_TEXT; lvi.iItem = 0; - while (Item != NULL) + for (WIDATALIST *Item = WIHead;Item != NULL;Item = Item->next) { // get the data for the ini file lvi.iSubItem = 0; @@ -80,7 +80,6 @@ void INIInfo(HWND hwndDlg) memused += Item->Data.MemUsed; - Item = Item->next; ++lvi.iItem; } SetDlgItemText(hwndDlg, IDC_INICOUNT, _itot(lvi.iItem, str, 10)); @@ -160,48 +159,48 @@ void GetINIInfo(TCHAR *pszSvc) else { mir_sntprintf(str2, SIZEOF(str2), TranslateT("Weather INI information for \"%s\":"), pszSvc); - _tcscat(str2,_T("\n\n")); - _tcscat(str2, TranslateT("Name:")); - _tcscat(str2,_T("\t\t")); - _tcscat(str2, sData->DisplayName); - _tcscat(str2,_T("\n")); - _tcscat(str2, TranslateT("Internal Name:")); - _tcscat(str2,_T("\t")); - _tcscat(str2, sData->InternalName); - _tcscat(str2,_T("\n")); - _tcscat(str2, TranslateT("Author:")); - _tcscat(str2,_T("\t\t")); - _tcscat(str2, sData->Author); - _tcscat(str2,_T("\n")); - _tcscat(str2, TranslateT("Version:")); - _tcscat(str2,_T("\t\t")); - _tcscat(str2, sData->Version); - _tcscat(str2,_T("\n")); - _tcscat(str2, TranslateT("INI Version:")); - _tcscat(str2,_T("\t")); + _tcsncat(str2,_T("\n\n"), SIZEOF(str2) - 1); + _tcsncat(str2, TranslateT("Name:"), SIZEOF(str2) - 1); + _tcsncat(str2,_T("\t\t"), SIZEOF(str2) - 1); + _tcsncat(str2, sData->DisplayName, SIZEOF(str2) - 1); + _tcsncat(str2,_T("\n"), SIZEOF(str2) - 1); + _tcsncat(str2, TranslateT("Internal Name:"), SIZEOF(str2) - 1); + _tcsncat(str2,_T("\t"), SIZEOF(str2) - 1); + _tcsncat(str2, sData->InternalName, SIZEOF(str2) - 1); + _tcsncat(str2,_T("\n"), SIZEOF(str2) - 1); + _tcsncat(str2, TranslateT("Author:"), SIZEOF(str2) - 1); + _tcsncat(str2,_T("\t\t"), SIZEOF(str2) - 1); + _tcsncat(str2, sData->Author, SIZEOF(str2) - 1); + _tcsncat(str2,_T("\n"), SIZEOF(str2) - 1); + _tcsncat(str2, TranslateT("Version:"), SIZEOF(str2) - 1); + _tcsncat(str2,_T("\t\t"), SIZEOF(str2) - 1); + _tcsncat(str2, sData->Version, SIZEOF(str2) - 1); + _tcsncat(str2,_T("\n"), SIZEOF(str2) - 1); + _tcsncat(str2, TranslateT("INI Version:"), SIZEOF(str2) - 1); + _tcsncat(str2,_T("\t"), SIZEOF(str2) - 1); switch (sData->InternalVer) { - case 1: _tcscat(str2,_T("1.0")); break; - case 2: _tcscat(str2,_T("1.1")); break; - case 3: _tcscat(str2,_T("1.1a")); break; - case 4: _tcscat(str2,_T("1.2")); break; - case 5: _tcscat(str2,_T("1.3")); break; - case 6: _tcscat(str2,_T("1.4")); break; - case 7: _tcscat(str2,_T("1.5")); break; + case 1: _tcsncat(str2,_T("1.0"), SIZEOF(str2) - 1); break; + case 2: _tcsncat(str2,_T("1.1"), SIZEOF(str2) - 1); break; + case 3: _tcsncat(str2,_T("1.1a"), SIZEOF(str2) - 1); break; + case 4: _tcsncat(str2,_T("1.2"), SIZEOF(str2) - 1); break; + case 5: _tcsncat(str2,_T("1.3"), SIZEOF(str2) - 1); break; + case 6: _tcsncat(str2,_T("1.4"), SIZEOF(str2) - 1); break; + case 7: _tcsncat(str2,_T("1.5"), SIZEOF(str2) - 1); break; } - _tcscat(str2,_T("\n")); - _tcscat(str2, TranslateT("File Name:")); - _tcscat(str2,_T("\t")); - _tcscat(str2, sData->ShortFileName); - _tcscat(str2, _T("\n")); - _tcscat(str2, TranslateT("Item Count:")); + _tcsncat(str2,_T("\n"), SIZEOF(str2) - 1); + _tcsncat(str2, TranslateT("File Name:"), SIZEOF(str2) - 1); + _tcsncat(str2,_T("\t"), SIZEOF(str2) - 1); + _tcsncat(str2, sData->ShortFileName, SIZEOF(str2) - 1); + _tcsncat(str2, _T("\n"), SIZEOF(str2) - 1); + _tcsncat(str2, TranslateT("Item Count:"), SIZEOF(str2) - 1); mir_sntprintf(str2, SIZEOF(str2), _T("%s\t%i\n"), str2, sData->UpdateDataCount); - _tcscat(str2, TranslateT("Memory Used:")); + _tcsncat(str2, TranslateT("Memory Used:"), SIZEOF(str2) - 1); mir_sntprintf(str2, SIZEOF(str2), _T("%s\t%i "), str2, sData->MemUsed); - _tcscat(str2, TranslateT("bytes")); - _tcscat(str2,_T("\n\n")); - _tcscat(str2, TranslateT("Description:")); - _tcscat(str2,_T("\n")); - _tcscat(str2, sData->Description); + _tcsncat(str2, TranslateT("bytes"), SIZEOF(str2) - 1); + _tcsncat(str2,_T("\n\n"), SIZEOF(str2) - 1); + _tcsncat(str2, TranslateT("Description:"), SIZEOF(str2) - 1); + _tcsncat(str2,_T("\n"), SIZEOF(str2) - 1); + _tcsncat(str2, sData->Description, SIZEOF(str2) - 1); // display the message box and quit MessageBox(NULL, str2, TranslateT("Weather INI information"), MB_OK|MB_ICONINFORMATION); @@ -216,16 +215,14 @@ void MoreVarList(void) { TCHAR str[10240], tempstr[1024]; - WIDATALIST *Item = WIHead; // heading - _tcscpy(str, TranslateT("Here is a list of custom variables that are currently available")); - _tcscat(str, _T("\n\n")); + _tcsncpy(str, VARS_LIST, SIZEOF(str) - 1); + _tcsncat(str, _T("\n\n"), SIZEOF(str) - 1); // loop through all weather services to find custom variables - while (Item != NULL) + for (WIDATALIST *Item = WIHead;Item != NULL;Item = Item->next) { - WIDATAITEMLIST *WItem = Item->Data.UpdateData; // loop through all update items in a service - while (WItem != NULL) + for (WIDATAITEMLIST *WItem = Item->Data.UpdateData;WItem != NULL;WItem = WItem->Next) { // the custom variable is defined as "%[]" // ignore the "hi" item and hidden items @@ -234,13 +231,11 @@ void MoreVarList(void) TCHAR* find = _tcsstr(str, tempstr); // if the custom variable does not exist in the list, add it to the list if (find == NULL) { - _tcscat(str, tempstr); - _tcscat(str, _T(", ")); + _tcsncat(str, tempstr, SIZEOF(str) - 1); + _tcsncat(str, _T(", "), SIZEOF(str) - 1); } } - WItem = WItem->Next; } - Item = Item->next; } // remove the last comma in the list TCHAR* find = _tcsrchr(str, ','); diff --git a/plugins/Weather/src/weather_ini.cpp b/plugins/Weather/src/weather_ini.cpp index 67c5740000..0f81268766 100644 --- a/plugins/Weather/src/weather_ini.cpp +++ b/plugins/Weather/src/weather_ini.cpp @@ -50,15 +50,12 @@ void WIListAdd(WIDATA Data) // return value = the matching WIDATA struct for pszServ, NULL if no match found WIDATA* GetWIData(TCHAR *pszServ) { - WIDATALIST *Item = WIHead; - // loop through the list to find matching internal name - while (Item != NULL) { + for (WIDATALIST *Item = WIHead;Item != NULL;Item = Item->next) // if internal name found, return the data if ( _tcscmp(Item->Data.InternalName, pszServ) == 0) return &Item->Data; - Item = Item->next; - } + // return NULL when no match found return NULL; } @@ -186,8 +183,8 @@ bool LoadWIData(bool dial) if (chop == NULL) return false; *chop = '\0'; - _tcsncat(szSearchPath, _T("\\Plugins\\Weather\\*.ini"),SIZEOF(szSearchPath)); - _tcsncpy(FileName, szSearchPath, SIZEOF(FileName)); + _tcsncat(szSearchPath, _T("\\Plugins\\Weather\\*.ini"),MAX_PATH - 1); + _tcsncpy(FileName, szSearchPath, MAX_PATH - 1); WIN32_FIND_DATA fd; HANDLE hFind = FindFirstFile(szSearchPath, &fd); @@ -198,7 +195,7 @@ bool LoadWIData(bool dial) do { chop = _tcsrchr(FileName, '\\'); chop[1] = '\0'; - _tcscat(FileName, fd.cFileName); + _tcsncat(FileName, fd.cFileName, SIZEOF(FileName) - 1); if ( _tcsicmp(fd.cFileName, _T("SAMPLE_INI.INI"))) { WIDATA Data; LoadStationData(FileName, fd.cFileName, &Data); @@ -570,7 +567,7 @@ INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar TCHAR *chop = _tcsrchr(szPath, '\\'); if (chop) { *chop = '\0'; - _tcsncat(szPath, _T("\\Plugins\\weather\\"),SIZEOF(szPath)); + _tcsncat(szPath, _T("\\Plugins\\weather\\"),SIZEOF(szPath) - 1); _tmkdir(szPath); ShellExecute((HWND)lParam, _T("open"), szPath, _T(""), _T(""), SW_SHOW); } diff --git a/plugins/Weather/src/weather_opt.cpp b/plugins/Weather/src/weather_opt.cpp index 012b123166..3e4c31725e 100644 --- a/plugins/Weather/src/weather_opt.cpp +++ b/plugins/Weather/src/weather_opt.cpp @@ -36,43 +36,43 @@ void SetTextDefault(const char* in) TCHAR str[MAX_TEXT_SIZE]; if (strchr(in, 'C') != NULL) { - _tcscpy(str, C_DEFAULT); + _tcsncpy(str, C_DEFAULT, MAX_TEXT_SIZE - 1); wSetData(&opt.cText, str); } if (strchr(in, 'b') != NULL) { - _tcscpy(str, b_DEFAULT); + _tcsncpy(str, b_DEFAULT, MAX_TEXT_SIZE - 1); wSetData(&opt.bTitle, str); } if (strchr(in, 'B') != NULL) { - _tcscpy(str, B_DEFAULT); + _tcsncpy(str, B_DEFAULT, MAX_TEXT_SIZE - 1); wSetData(&opt.bText, str); } if (strchr(in, 'N') != NULL) { - _tcscpy(str, N_DEFAULT); + _tcsncpy(str, N_DEFAULT, MAX_TEXT_SIZE - 1); wSetData(&opt.nText, str); } if (strchr(in, 'E') != NULL) { - _tcscpy(str, E_DEFAULT); + _tcsncpy(str, E_DEFAULT, MAX_TEXT_SIZE - 1); wSetData(&opt.eText, str); } if (strchr(in, 'H') != NULL) { - _tcscpy(str, H_DEFAULT); + _tcsncpy(str, H_DEFAULT, MAX_TEXT_SIZE - 1); wSetData(&opt.hText, str); } if (strchr(in, 'X') != NULL) { - _tcscpy(str, X_DEFAULT); + _tcsncpy(str, X_DEFAULT, MAX_TEXT_SIZE - 1); wSetData(&opt.xText, str); } if (strchr(in, 'P') != NULL) { - _tcscpy(str, P_DEFAULT); + _tcsncpy(str, P_DEFAULT, MAX_TEXT_SIZE - 1); wSetData(&opt.pTitle, str); } if (strchr(in, 'p') != NULL) { - _tcscpy(str, p_DEFAULT); + _tcsncpy(str, p_DEFAULT, MAX_TEXT_SIZE - 1); wSetData(&opt.pText, str); } if (strchr(in, 'S') != NULL) { - _tcscpy(str, s_DEFAULT); + _tcsncpy(str, s_DEFAULT, MAX_TEXT_SIZE - 1); wSetData(&opt.sText, str); } } @@ -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 - _tcscpy(str, TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temp\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set\n----------\n\\n\tnew line")); + _tcsncpy(str, VAR_LIST_OPT, SIZEOF(str) - 1); SetDlgItemText(hdlg, IDC_VARLIST, str); // make the more variable and other buttons flat diff --git a/plugins/Weather/src/weather_popup.cpp b/plugins/Weather/src/weather_popup.cpp index aff1b8738d..b8b6a326f8 100644 --- a/plugins/Weather/src/weather_popup.cpp +++ b/plugins/Weather/src/weather_popup.cpp @@ -76,17 +76,21 @@ int WeatherError(WPARAM wParam, LPARAM lParam) else if ((DWORD)lParam == SM_WEATHERALERT) { POPUPDATAT ppd = {0}; - TCHAR *chop, str1[512], str2[512]; + TCHAR str1[512], str2[512]; // get the 2 strings - _tcscpy(str1, tszMsg); - _tcscpy(str2, tszMsg); - chop = _tcschr(str1, 255); - if (chop != NULL) *chop = '\0'; - else str1[0] = 0; + _tcsncpy(str1, tszMsg, SIZEOF(str1) - 1); + _tcsncpy(str2, tszMsg, SIZEOF(str2) - 1); + TCHAR *chop = _tcschr(str1, 255); + if (chop != NULL) + *chop = '\0'; + else + str1[0] = 0; chop = _tcschr(str2, 255); - if (chop != NULL) _tcscpy(str2, chop+1); - else str2[0] = 0; + if (chop != NULL) + _tcsncpy(str2, chop+1, SIZEOF(str2) - 1); + else + str2[0] = 0; // setup the popup ppd.lchIcon = (HICON)LoadImage(NULL, MAKEINTRESOURCE(OIC_BANG), IMAGE_ICON, @@ -211,7 +215,6 @@ static void SelectMenuItem(HMENU hMenu, int Check) void ReadPopupOpt(HWND hdlg) { TCHAR text[MAX_TEXT_SIZE]; - int num; TCHAR str[512]; // popup colour @@ -220,7 +223,7 @@ void ReadPopupOpt(HWND hdlg) // get delay time GetDlgItemText(hdlg, IDC_DELAY, str, SIZEOF(str)); - num = _ttoi(str); + int num = _ttoi(str); opt.pDelay = num; // other options @@ -393,10 +396,10 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) case IDC_VAR3: // display variable list - _tcscpy(str, _T(" \n")); // to make the message box wider - _tcscat(str, TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temperature\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set")); - _tcscat(str, _T("\n")); - _tcscat(str, TranslateT("%[..]\tcustom variables")); + _tcsncpy(str, _T(" \n"),SIZEOF(str) - 1); // to make the message box wider + _tcsncat(str, VAR_LIST_POPUP, SIZEOF(str) - 1); + _tcsncat(str, _T("\n"),SIZEOF(str) - 1); + _tcsncat(str, CUSTOM_VARS,SIZEOF(str) - 1); MessageBox(NULL, str, TranslateT("Variable List"), MB_OK|MB_ICONASTERISK|MB_TOPMOST); break; diff --git a/plugins/Weather/src/weather_update.cpp b/plugins/Weather/src/weather_update.cpp index 612f536b5c..290303d372 100644 --- a/plugins/Weather/src/weather_update.cpp +++ b/plugins/Weather/src/weather_update.cpp @@ -60,9 +60,9 @@ int UpdateWeather(MCONTACT hContact) // show warnings by popup mir_sntprintf(str, SIZEOF(str) - 105, TranslateT("Unable to retrieve weather information for %s"), dbv.ptszVal); - _tcscat(str, _T("\n")); + _tcsncat(str, _T("\n"), SIZEOF(str) - 1); TCHAR *tszError = GetError(code); - _tcscat(str, tszError); + _tcsncat(str, tszError, SIZEOF(str) - 1); WPShowMessage(str, SM_WARNING); mir_free(tszError); } @@ -458,7 +458,7 @@ int GetWeatherData(MCONTACT hContact) // to get a data value. GetDataValue(&Item->Item, DataValue, &szInfo); if ( _tcscmp(Item->Item.Name, _T("Condition")) && _tcsicmp(Item->Item.Unit, _T("Cond"))) - _tcscpy(DataValue, TranslateTS(DataValue)); + _tcsncpy(DataValue, TranslateTS(DataValue), MAX_DATA_LEN - 1); break; case WID_SET: diff --git a/plugins/Weather/src/weather_userinfo.cpp b/plugins/Weather/src/weather_userinfo.cpp index 10479f95e5..22c76a6169 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)) - _tcscpy(str, TranslateT("No information available.\r\nPlease update weather condition first.")); + _tcsncpy(str, WEATHER_NO_INFO, SIZEOF(str) - 1); else // set the display text and show the message box GetDisplay(&winfo, opt.bText, str); @@ -351,7 +351,7 @@ void LoadBriefInfoText(HWND hwndDlg, MCONTACT hContact) // show brief information dialog // wParam = current contact -int BriefInfo(WPARAM wParam, LPARAM lParam) +int BriefInfo(WPARAM wParam, LPARAM) { // make sure that the contact is actually a weather one if (IsMyContact(wParam)) { -- cgit v1.2.3