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/Msg_Export/src/FileViewer.cpp | 12 ++++++------ plugins/Msg_Export/src/options.cpp | 32 ++++++++++++++++---------------- plugins/Msg_Export/src/utils.cpp | 16 ++++++++-------- 3 files changed, 30 insertions(+), 30 deletions(-) (limited to 'plugins/Msg_Export/src') diff --git a/plugins/Msg_Export/src/FileViewer.cpp b/plugins/Msg_Export/src/FileViewer.cpp index e76ac7a885..87a4b04606 100755 --- a/plugins/Msg_Export/src/FileViewer.cpp +++ b/plugins/Msg_Export/src/FileViewer.cpp @@ -198,7 +198,7 @@ int CLStreamRTFInfo::nWriteHeader(char *pszTarget, int nLen) */ char szRtfHeader[400]; - int nSrcLen = mir_snprintf(szRtfHeader, SIZEOF(szRtfHeader), + int nSrcLen = mir_snprintf(szRtfHeader, _countof(szRtfHeader), "{\\rtf1\\ansi\r\n" "{\\colortbl ;\\red%d\\green%d\\blue%d;\\red%d\\green%d\\blue%d;}\r\n" "\\viewkind4\\uc1\\pard\\cf2 ", @@ -625,9 +625,9 @@ bool bLoadFile(HWND hwndDlg, CLHistoryDlg * pclDlg) TCHAR szTmp[1500]; if (nDBCount == -1) - mir_sntprintf(szTmp, SIZEOF(szTmp), TranslateT("Failed to open file\r\n%s\r\n\r\nContact handle is invalid"), pclDlg->sPath.c_str()); + mir_sntprintf(szTmp, _countof(szTmp), TranslateT("Failed to open file\r\n%s\r\n\r\nContact handle is invalid"), pclDlg->sPath.c_str()); else - mir_sntprintf(szTmp, SIZEOF(szTmp), TranslateT("Failed to open file\r\n%s\r\n\r\nMiranda database contains %d events"), pclDlg->sPath.c_str(), nDBCount); + mir_sntprintf(szTmp, _countof(szTmp), TranslateT("Failed to open file\r\n%s\r\n\r\nMiranda database contains %d events"), pclDlg->sPath.c_str(), nDBCount); SETTEXTEX stText = { 0 }; stText.codepage = 1200; @@ -674,7 +674,7 @@ bool bLoadFile(HWND hwndDlg, CLHistoryDlg * pclDlg) CloseHandle(hFile); TCHAR szTmp[100]; - mir_sntprintf(szTmp, SIZEOF(szTmp), _T("File open time %d\n"), GetTickCount() - dwStart); + mir_sntprintf(szTmp, _countof(szTmp), _T("File open time %d\n"), GetTickCount() - dwStart); OutputDebugString(szTmp); GETTEXTLENGTHEX sData = { 0 }; @@ -686,7 +686,7 @@ bool bLoadFile(HWND hwndDlg, CLHistoryDlg * pclDlg) if (!bScrollToBottom) SendMessage(hRichEdit, EM_SETSCROLLPOS, 0, (LPARAM)&ptOldPos); - mir_sntprintf(szTmp, SIZEOF(szTmp), TranslateT("With scroll to bottom %d\n"), GetTickCount() - dwStart); + mir_sntprintf(szTmp, _countof(szTmp), TranslateT("With scroll to bottom %d\n"), GetTickCount() - dwStart); OutputDebugString(szTmp); return true; } @@ -985,7 +985,7 @@ static INT_PTR CALLBACK DlgProcFileViewer(HWND hwndDlg, UINT msg, WPARAM wParam, TCHAR szFormat[200]; TCHAR szTitle[200]; - if (GetWindowText(hwndDlg, szFormat, SIZEOF(szFormat))) { + if (GetWindowText(hwndDlg, szFormat, _countof(szFormat))) { const TCHAR *pszNick = NickFromHandle(pclDlg->hContact); tstring sPath = pclDlg->sPath; string::size_type n = sPath.find_last_of('\\'); diff --git a/plugins/Msg_Export/src/options.cpp b/plugins/Msg_Export/src/options.cpp index d458e782da..dd6ebaae35 100755 --- a/plugins/Msg_Export/src/options.cpp +++ b/plugins/Msg_Export/src/options.cpp @@ -297,7 +297,7 @@ void SetToDefault(HWND hParent) } TCHAR szTemp[500]; - if (!GetDlgItemText(hParent, IDC_DEFAULT_FILE, szTemp, SIZEOF(szTemp))) + if (!GetDlgItemText(hParent, IDC_DEFAULT_FILE, szTemp, _countof(szTemp))) return; LVITEM sItem = { 0 }; @@ -359,16 +359,16 @@ BOOL bApplyChanges(HWND hwndDlg) nMaxLineWidth = nTmp; } - GetDlgItemText(hwndDlg, IDC_EXPORT_TIMEFORMAT, szTemp, SIZEOF(szTemp)); + GetDlgItemText(hwndDlg, IDC_EXPORT_TIMEFORMAT, szTemp, _countof(szTemp)); sTimeFormat = szTemp; - GetDlgItemText(hwndDlg, IDC_EXPORT_DIR, szTemp, SIZEOF(szTemp)); + GetDlgItemText(hwndDlg, IDC_EXPORT_DIR, szTemp, _countof(szTemp)); sExportDir = szTemp; - GetDlgItemText(hwndDlg, IDC_DEFAULT_FILE, szTemp, SIZEOF(szTemp)); + GetDlgItemText(hwndDlg, IDC_DEFAULT_FILE, szTemp, _countof(szTemp)); sDefaultFile = szTemp; - GetDlgItemText(hwndDlg, IDC_FILE_VIEWER, szTemp, SIZEOF(szTemp)); + GetDlgItemText(hwndDlg, IDC_FILE_VIEWER, szTemp, _countof(szTemp)); sFileViewerPrg = szTemp; bUseInternalViewer(IsDlgButtonChecked(hwndDlg, IDC_USE_INTERNAL_VIEWER) == BST_CHECKED); @@ -394,7 +394,7 @@ BOOL bApplyChanges(HWND hwndDlg) sItem.iItem = nCur; sItem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; sItem.pszText = szTemp; - sItem.cchTextMax = SIZEOF(szTemp); + sItem.cchTextMax = _countof(szTemp); if (ListView_GetItem(hMapUser, &sItem)) { @@ -469,7 +469,7 @@ void AutoFindeFileNames(HWND hwndDlg) { TCHAR szDefaultFile[500]; - GetDlgItemText(hwndDlg, IDC_DEFAULT_FILE, szDefaultFile, SIZEOF(szDefaultFile)); + GetDlgItemText(hwndDlg, IDC_DEFAULT_FILE, szDefaultFile, _countof(szDefaultFile)); LVITEM sItem = { 0 }; @@ -483,7 +483,7 @@ void AutoFindeFileNames(HWND hwndDlg) sItem.iItem = nCur; sItem.iSubItem = 1; sItem.pszText = szSearch; - sItem.cchTextMax = SIZEOF(szSearch); + sItem.cchTextMax = _countof(szSearch); if (!ListView_GetItem(hMapUser, &sItem)) { @@ -502,7 +502,7 @@ void AutoFindeFileNames(HWND hwndDlg) sItem.iItem = nSubCur; sItem.iSubItem = 1; sItem.pszText = szSubCur; - sItem.cchTextMax = SIZEOF(szSubCur); + sItem.cchTextMax = _countof(szSubCur); if (ListView_GetItem(hMapUser, &sItem)) { size_t nLen = mir_tstrlen(szSubCur); @@ -521,13 +521,13 @@ void AutoFindeFileNames(HWND hwndDlg) { tstring sFileName; szSearch[0] = 0; - ListView_GetItemText(hMapUser, nCur, 0, szSearch, SIZEOF(szSearch)); + ListView_GetItemText(hMapUser, nCur, 0, szSearch, _countof(szSearch)); bool bPriHasFileName = szSearch[0] != 0; if (bPriHasFileName) sFileName = szSearch; szSearch[0] = 0; - ListView_GetItemText(hMapUser, nStortestIndex, 0, szSearch, SIZEOF(szSearch)); + ListView_GetItemText(hMapUser, nStortestIndex, 0, szSearch, _countof(szSearch)); bool bSubHasFileName = szSearch[0] != 0; if (bSubHasFileName) sFileName = szSearch; @@ -571,7 +571,7 @@ void AutoFindeFileNames(HWND hwndDlg) void OpenHelp(HWND hwndDlg) { TCHAR szPath[MAX_PATH]; - if (GetModuleFileName(hInstance, szPath, SIZEOF(szPath))) + if (GetModuleFileName(hInstance, szPath, _countof(szPath))) { size_t nLen = mir_tstrlen(szPath); if (nLen > 3) @@ -706,7 +706,7 @@ static INT_PTR CALLBACK DlgProcMsgExportOpts(HWND hwndDlg, UINT msg, WPARAM wPar DWORD dwUIN = db_get_dw(hContact, sTmpA.c_str(), "UIN", 0); TCHAR szTmp[50]; - mir_sntprintf(szTmp, SIZEOF(szTmp), _T("%d"), dwUIN); + mir_sntprintf(szTmp, _countof(szTmp), _T("%d"), dwUIN); sItem.iSubItem = 3; sItem.pszText = szTmp; ListView_SetItem(hMapUser, &sItem); @@ -892,13 +892,13 @@ static INT_PTR CALLBACK DlgProcMsgExportOpts(HWND hwndDlg, UINT msg, WPARAM wPar TCHAR szFile[260]; // buffer for file name TCHAR buf[MAX_PATH]; - GetDlgItemText(hwndDlg, IDC_FILE_VIEWER, szFile, SIZEOF(szFile)); + GetDlgItemText(hwndDlg, IDC_FILE_VIEWER, szFile, _countof(szFile)); // Initialize OPENFILENAME memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwndDlg; ofn.lpstrFile = szFile; - ofn.nMaxFile = SIZEOF(szFile); + ofn.nMaxFile = _countof(szFile); mir_sntprintf(buf, _T("%s (*.exe;*.com;*.bat;*.cmd)%c*.exe;*.com;*.bat;*.cmd%c%s (*.*)%c*.*%c%c"), TranslateT("Executable files"), 0, 0, TranslateT("All files"), 0, 0, 0); ofn.lpstrFilter = buf; ofn.nFilterIndex = 1; @@ -1186,7 +1186,7 @@ BOOL bApplyChanges2(HWND hwndDlg) sItem.iItem = nCur; sItem.mask = LVIF_TEXT | LVIF_IMAGE; sItem.pszText = &szTemp[12]; - sItem.cchTextMax = (SIZEOF(szTemp) - 15); + sItem.cchTextMax = (_countof(szTemp) - 15); if (::SendMessage(hMapUser, LVM_GETITEMA, 0, (LPARAM)&sItem)) { if (sItem.iImage) diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index 023c90a90b..a50cb84626 100755 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -518,7 +518,7 @@ bool bWriteHexToFile(HANDLE hFile, void * pData, int nSize) BYTE * p = (BYTE*)pData; for (int n = 0; n < nSize; n++) { - mir_snprintf(cBuf, SIZEOF(cBuf), "%.2X ", p[n]); + mir_snprintf(cBuf, _countof(cBuf), "%.2X ", p[n]); if (!bWriteToFile(hFile, cBuf, 3)) return false; } @@ -774,7 +774,7 @@ void ReplaceDefines(MCONTACT hContact, tstring & sTarget) if (dwUIN) { TCHAR sTmp[20]; - mir_sntprintf(sTmp, SIZEOF(sTmp), _T("%d"), dwUIN); + mir_sntprintf(sTmp, _countof(sTmp), _T("%d"), dwUIN); sReplaceUin = sTmp; } else @@ -871,11 +871,11 @@ void ReplaceTimeVariables(tstring &sRet) GetLocalTime(&stTime); TCHAR sTmp[20]; - mir_sntprintf(sTmp, SIZEOF(sTmp), _T("%d"), stTime.wYear); + mir_sntprintf(sTmp, _countof(sTmp), _T("%d"), stTime.wYear); ReplaceAll(sRet, _T("%year%"), sTmp); - mir_sntprintf(sTmp, SIZEOF(sTmp), _T("%.2d"), stTime.wMonth); + mir_sntprintf(sTmp, _countof(sTmp), _T("%.2d"), stTime.wMonth); ReplaceAll(sRet, _T("%month%"), sTmp); - mir_sntprintf(sTmp, SIZEOF(sTmp), _T("%.2d"), stTime.wDay); + mir_sntprintf(sTmp, _countof(sTmp), _T("%.2d"), stTime.wDay); ReplaceAll(sRet, _T("%day%"), sTmp); } } @@ -941,7 +941,7 @@ void DisplayErrorDialog(const TCHAR *pszError, tstring& sFilePath, DBEVENTINFO * ofn.lStructSize = sizeof(OPENFILENAME); //ofn.hwndOwner = NULL; ofn.lpstrFile = szFile; - ofn.nMaxFile = SIZEOF(szFile); + ofn.nMaxFile = _countof(szFile); ofn.lpstrFilter = TranslateT("All\0*.*\0Text\0*.TXT\0\0"); ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; @@ -1132,7 +1132,7 @@ void ExportDBEventInfo(MCONTACT hContact, DBEVENTINFO &dbei) nFirstColumnWidth, dbei.flags & DBEF_SENT ? sLocalUser.c_str() : sRemoteUser.c_str()); - TimeZone_ToStringT(dbei.timestamp, sTimeFormat.c_str(), &szTemp[nIndent], SIZEOF(szTemp) - nIndent - 2); + TimeZone_ToStringT(dbei.timestamp, sTimeFormat.c_str(), &szTemp[nIndent], _countof(szTemp) - nIndent - 2); nIndent = (int)mir_tstrlen(szTemp); szTemp[nIndent++] = ' '; @@ -1460,7 +1460,7 @@ bool bWriteIndentedToFile(HANDLE hFile, int nIndent, const TCHAR *pszSrc, bool b // then we will look for a ? and so on. const TCHAR ac[] = { _T(' '), _T('?'), _T('-'), _T('.'), _T(',') }; - for (int y = 0; y < SIZEOF(ac); y++) + for (int y = 0; y < _countof(ac); y++) { for (int n = nLineLen; n > 0; n--) { -- cgit v1.2.3