From eefe0f0d556fbf3d77602d0a99b9134505050756 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 16 Jul 2014 13:43:06 +0000 Subject: in _tcsncpy_s / _tcsncat_s / strncpy_s / strncat_s the second parameter to be omitted if the size of first one is fixed (not to contaminate sources with the excessive code) git-svn-id: http://svn.miranda-ng.org/main/trunk@9829 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/LotusNotify/src/LotusNotify.cpp | 69 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 36 deletions(-) (limited to 'plugins/LotusNotify') diff --git a/plugins/LotusNotify/src/LotusNotify.cpp b/plugins/LotusNotify/src/LotusNotify.cpp index 7b7dbd1e23..fd18559cf1 100644 --- a/plugins/LotusNotify/src/LotusNotify.cpp +++ b/plugins/LotusNotify/src/LotusNotify.cpp @@ -286,16 +286,15 @@ BOOL checkFilters(TCHAR* str, int field) { TCHAR buff[512] = _T(""); TCHAR *strptr = NULL; - switch(field) - { + switch(field) { case 0: - _tcsncpy_s(buff, SIZEOF(buff), settingFilterSender, SIZEOF(buff)); + _tcsncpy_s(buff, settingFilterSender, _TRUNCATE); break; case 1: - _tcsncpy_s(buff, SIZEOF(buff), settingFilterSubject, SIZEOF(buff)); + _tcsncpy_s(buff, settingFilterSubject, _TRUNCATE); break; case 2: - _tcsncpy_s(buff, SIZEOF(buff), settingFilterTo, SIZEOF(buff)); + _tcsncpy_s(buff, settingFilterTo, _TRUNCATE); break; } @@ -303,8 +302,8 @@ BOOL checkFilters(TCHAR* str, int field) while(strptr = _tcschr(buff, ';')) { TCHAR tmp[512] = TEXT(""), *ptr; - _tcsncpy_s(tmp, SIZEOF(tmp), buff, (strptr-buff)); - _tcsncpy_s(buff, SIZEOF(buff), strptr + 1, SIZEOF(buff)); + _tcsncpy_s(tmp, buff, (strptr-buff)); + _tcsncpy_s(buff, strptr + 1, _TRUNCATE); if(_tcsstr(_tcslwr(ptr=_tcsdup(str)),_tcslwr(tmp))) { @@ -512,8 +511,8 @@ void ErMsgT(TCHAR* msg) log_p(L"Error: %S", msg); if(settingShowError && !isPopupWaiting) { TCHAR buffer[256+14]; - _tcsncpy_s(buffer, _countof(buffer), _T("LotusNotify: "), SIZEOF(buffer)); - _tcscat_s(buffer, _countof(buffer), msg); + _tcsncpy_s(buffer, _T("LotusNotify: "), _TRUNCATE); + _tcscat_s(buffer, msg); isPopupWaiting = TRUE; PUShowMessageT(buffer, SM_WARNING); isPopupWaiting = FALSE; @@ -761,15 +760,13 @@ void checkthread(void*) ZeroMemory(msgFrom,512); ZeroMemory(msgSubject,512); - if(wcslen(field_from_UNICODE) < 512 && wcslen(field_from_UNICODE) > 3 && wcsstr(field_from_UNICODE, L"CN=") == field_from_UNICODE){ - _tcsncpy_s(msgFrom, SIZEOF(msgFrom), &(field_from_UNICODE[3]), wcscspn(field_from_UNICODE, L"/")-3 ); - } else { - _tcsncpy_s(msgFrom, SIZEOF(msgFrom), field_from_UNICODE, _TRUNCATE); - } + if(wcslen(field_from_UNICODE) < 512 && wcslen(field_from_UNICODE) > 3 && wcsstr(field_from_UNICODE, L"CN=") == field_from_UNICODE) + _tcsncpy_s(msgFrom, &(field_from_UNICODE[3]), wcscspn(field_from_UNICODE, L"/")-3 ); + else + _tcsncpy_s(msgFrom, field_from_UNICODE, _TRUNCATE); - for (Att = 0; (MailGetMessageAttachmentInfo1)(note_handle, Att,&bhAttachment, NULL, &cSize, NULL, NULL, NULL, NULL); Att++) { + for (Att = 0; (MailGetMessageAttachmentInfo1)(note_handle, Att,&bhAttachment, NULL, &cSize, NULL, NULL, NULL, NULL); Att++) attSize += cSize; - } #ifdef _DEBUG log_p(L"checkthread: MAIL INFO: date=[%S], from=[%s], to=[%s], cc=[%s], sub=[%s], attSize=[%d]" @@ -998,13 +995,13 @@ void LoadSettings() db_free(&dbv); if(!db_get_ts(NULL, PLUGINNAME, "LNFilterSender",&dbv)) - _tcsncpy_s(settingFilterSender, SIZEOF(settingFilterSender), dbv.ptszVal, SIZEOF(settingFilterSender)); + _tcsncpy_s(settingFilterSender, dbv.ptszVal, _TRUNCATE); db_free(&dbv); if(!db_get_ts(NULL, PLUGINNAME, "LNFilterSubject",&dbv)) - _tcsncpy_s(settingFilterSubject, SIZEOF(settingFilterSubject), dbv.ptszVal, SIZEOF(settingFilterSubject)); + _tcsncpy_s(settingFilterSubject, dbv.ptszVal, _TRUNCATE); db_free(&dbv); if(!db_get_ts(NULL, PLUGINNAME, "LNFilterTo",&dbv)) - _tcsncpy_s(settingFilterTo ,SIZEOF(settingFilterTo), dbv.ptszVal, SIZEOF(settingFilterTo)); + _tcsncpy_s(settingFilterTo, dbv.ptszVal, _TRUNCATE); db_free(&dbv); settingOnceOnly = db_get_b (NULL, PLUGINNAME, "LNOnceOnly",0); @@ -1105,28 +1102,28 @@ INT_PTR CALLBACK DlgProcLotusNotifyOpts(HWND hwndDlg, UINT msg, WPARAM wParam, L TCHAR buff[512]; TCHAR* strptr; - _tcsncpy_s(buff, SIZEOF(buff), settingFilterSender, SIZEOF(buff)); + _tcsncpy_s(buff, settingFilterSender, _TRUNCATE); while(strptr = _tcschr(buff, TEXT(';'))) { TCHAR tmp[512] = TEXT(""); - _tcsncpy_s(tmp, SIZEOF(tmp), buff, (strptr-buff)); + _tcsncpy_s(tmp, buff, (strptr-buff)); SendDlgItemMessage(hwndDlg, IDC_FILTER_SENDER , CB_ADDSTRING, 0, (LPARAM)tmp); - _tcsncpy_s(buff, SIZEOF(buff), strptr + 1, SIZEOF(buff)); + _tcsncpy_s(buff, strptr + 1, _TRUNCATE); } - _tcsncpy_s(buff, SIZEOF(buff), settingFilterSubject, SIZEOF(buff) ); + _tcsncpy_s(buff, settingFilterSubject, _TRUNCATE); while(strptr = _tcschr(buff, TEXT(';'))) { TCHAR tmp[512] = TEXT(""); - _tcsncpy_s(tmp, SIZEOF(tmp), buff, (strptr-buff)); + _tcsncpy_s(tmp, buff, (strptr-buff)); SendDlgItemMessage(hwndDlg, IDC_FILTER_SUBJECT , CB_ADDSTRING, 0, (LPARAM)tmp); - _tcsncpy_s(buff, SIZEOF(buff), strptr + 1, SIZEOF(buff)); + _tcsncpy_s(buff, strptr + 1, _TRUNCATE); } - _tcsncpy_s(buff, SIZEOF(buff), settingFilterTo, SIZEOF(buff) ); + _tcsncpy_s(buff, settingFilterTo, _TRUNCATE); while(strptr = _tcschr(buff, TEXT(';'))) { TCHAR tmp[512] = TEXT(""); - _tcsncpy_s(tmp, SIZEOF(tmp), buff, (strptr-buff)); + _tcsncpy_s(tmp, buff, (strptr-buff)); SendDlgItemMessage(hwndDlg, IDC_FILTER_TO , CB_ADDSTRING, 0, (LPARAM)tmp); - _tcsncpy_s(buff, SIZEOF(buff), strptr + 1, SIZEOF(buff)); + _tcsncpy_s(buff, strptr + 1, _TRUNCATE); } break; @@ -1292,7 +1289,7 @@ INT_PTR CALLBACK DlgProcLotusNotifyOpts(HWND hwndDlg, UINT msg, WPARAM wParam, L db_set_b(0, PLUGINNAME, buff, settingStatus[i] ? 1 : 0); } - _tcsncpy_s(settingFilterSender, SIZEOF(settingFilterSender), TEXT(""), SIZEOF(settingFilterSender)); + settingFilterSender[0] = 0; for(i=0; i