diff options
author | George Hazan <george.hazan@gmail.com> | 2015-06-19 19:35:42 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-06-19 19:35:42 +0000 |
commit | 4c814798c7bc7f6a0f92c21b027b26290622aa2f (patch) | |
tree | 9bbfb38bd639f352300aa16ff7c45f5a9b2dba6d /src/mir_core | |
parent | f0f0cd088f1ec3a85abee825ddbc214f3f6b92c3 (diff) |
SIZEOF replaced with more secure analog - _countof
git-svn-id: http://svn.miranda-ng.org/main/trunk@14270 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/mir_core')
-rw-r--r-- | src/mir_core/src/langpack.cpp | 22 | ||||
-rw-r--r-- | src/mir_core/src/path.cpp | 10 | ||||
-rw-r--r-- | src/mir_core/src/timezones.cpp | 16 | ||||
-rw-r--r-- | src/mir_core/src/ui_utils.cpp | 6 | ||||
-rw-r--r-- | src/mir_core/src/winutil.cpp | 16 | ||||
-rw-r--r-- | src/mir_core/src/winver.cpp | 4 |
6 files changed, 37 insertions, 37 deletions
diff --git a/src/mir_core/src/langpack.cpp b/src/mir_core/src/langpack.cpp index cfc656afd2..9f048b21ec 100644 --- a/src/mir_core/src/langpack.cpp +++ b/src/mir_core/src/langpack.cpp @@ -219,7 +219,7 @@ static void LoadLangPackFile(FILE *fp, char *line) TCHAR *p = _tcsrchr(langPack.tszFullPath, '\\');
if (p)
*p = 0;
- mir_sntprintf(tszFileName, SIZEOF(tszFileName), _T("%s\\%S"), langPack.tszFullPath, ltrim(line + 9));
+ mir_sntprintf(tszFileName, _countof(tszFileName), _T("%s\\%S"), langPack.tszFullPath, ltrim(line + 9));
if (p)
*p = '\\';
@@ -361,9 +361,9 @@ static int LoadLangDescr(LANGPACK_INFO &lpinfo, FILE *fp, char *line, int &start lpinfo.szAuthors = szAuthors;
- MultiByteToWideChar(lpinfo.codepage, 0, szLanguage, -1, lpinfo.tszLanguage, SIZEOF(lpinfo.tszLanguage));
+ MultiByteToWideChar(lpinfo.codepage, 0, szLanguage, -1, lpinfo.tszLanguage, _countof(lpinfo.tszLanguage));
- if (!lpinfo.tszLanguage[0] && (lpinfo.Locale == 0) || !GetLocaleInfo(lpinfo.Locale, LOCALE_SENGLANGUAGE, lpinfo.tszLanguage, SIZEOF(lpinfo.tszLanguage))) {
+ if (!lpinfo.tszLanguage[0] && (lpinfo.Locale == 0) || !GetLocaleInfo(lpinfo.Locale, LOCALE_SENGLANGUAGE, lpinfo.tszLanguage, _countof(lpinfo.tszLanguage))) {
TCHAR *p = _tcschr(lpinfo.tszFileName, '_');
_tcsncpy_s(lpinfo.tszLanguage, ((p != NULL) ? (p + 1) : lpinfo.tszFileName), _TRUNCATE);
p = _tcsrchr(lpinfo.tszLanguage, _T('.'));
@@ -380,7 +380,7 @@ MIR_CORE_DLL(int) LoadLangPack(const TCHAR *ptszLangPack) // ensure that a lang's name is a full file name
TCHAR tszFullPath[MAX_PATH];
if (!PathIsAbsoluteT(ptszLangPack))
- mir_sntprintf(tszFullPath, SIZEOF(tszFullPath), _T("%s\\%s"), g_tszRoot, ptszLangPack);
+ mir_sntprintf(tszFullPath, _countof(tszFullPath), _T("%s\\%s"), g_tszRoot, ptszLangPack);
else
_tcsncpy_s(tszFullPath, ptszLangPack, _TRUNCATE);
@@ -527,7 +527,7 @@ MIR_CORE_DLL(void) TranslateMenu_LP(HMENU hMenu, int hLangpack) TCHAR str[256];
mii.fMask = MIIM_TYPE | MIIM_SUBMENU;
mii.dwTypeData = (TCHAR*)str;
- mii.cch = SIZEOF(str);
+ mii.cch = _countof(str);
GetMenuItemInfo(hMenu, i, TRUE, &mii);
if (mii.cch && mii.dwTypeData) {
@@ -547,7 +547,7 @@ MIR_CORE_DLL(void) TranslateMenu_LP(HMENU hMenu, int hLangpack) static void TranslateWindow(MUUID *pUuid, HWND hwnd)
{
TCHAR title[2048];
- GetWindowText(hwnd, title, SIZEOF(title));
+ GetWindowText(hwnd, title, _countof(title));
TCHAR *result = (TCHAR*)LangPackTranslateString(pUuid, (const char*)title, TRUE);
if (result != title)
@@ -566,7 +566,7 @@ static BOOL CALLBACK TranslateDialogEnumProc(HWND hwnd, LPARAM lParam) MUUID *uuid = Langpack_LookupUuid(hLangpack);
TCHAR szClass[32];
- GetClassName(hwnd, szClass, SIZEOF(szClass));
+ GetClassName(hwnd, szClass, _countof(szClass));
if (!mir_tstrcmpi(szClass, _T("static")) || !mir_tstrcmpi(szClass, _T("hyperlink")) || !mir_tstrcmpi(szClass, _T("button")) || !mir_tstrcmpi(szClass, _T("MButtonClass")) || !mir_tstrcmpi(szClass, _T("MHeaderbarCtrl")))
TranslateWindow(uuid, hwnd);
else if (!mir_tstrcmpi(szClass, _T("edit"))) {
@@ -643,7 +643,7 @@ void GetDefaultLang() // look into mirandaboot.ini
TCHAR tszPath[MAX_PATH], tszLangName[256];
PathToAbsoluteT(_T("\\mirandaboot.ini"), tszPath);
- GetPrivateProfileString(_T("Language"), _T("DefaultLanguage"), _T(""), tszLangName, SIZEOF(tszLangName), tszPath);
+ GetPrivateProfileString(_T("Language"), _T("DefaultLanguage"), _T(""), tszLangName, _countof(tszLangName), tszPath);
if (tszLangName[0]) {
if (!mir_tstrcmpi(tszLangName, _T("default"))) {
db_set_ts(NULL, "Langpack", "Current", _T("default"));
@@ -656,8 +656,8 @@ void GetDefaultLang() }
// try to load langpack that matches UserDefaultUILanguage
- if (GetLocaleInfo(MAKELCID(GetUserDefaultUILanguage(), SORT_DEFAULT), LOCALE_SENGLANGUAGE, tszLangName, SIZEOF(tszLangName))) {
- mir_sntprintf(tszPath, SIZEOF(tszPath), _T("langpack_%s.txt"), _tcslwr(tszLangName));
+ if (GetLocaleInfo(MAKELCID(GetUserDefaultUILanguage(), SORT_DEFAULT), LOCALE_SENGLANGUAGE, tszLangName, _countof(tszLangName))) {
+ mir_sntprintf(tszPath, _countof(tszPath), _T("langpack_%s.txt"), _tcslwr(tszLangName));
if (!LoadLangPack(tszPath)) {
db_set_ts(NULL, "Langpack", "Current", tszPath);
return;
@@ -665,7 +665,7 @@ void GetDefaultLang() }
// finally try to load first file
- mir_sntprintf(tszPath, SIZEOF(tszPath), _T("%s\\langpack_*.txt"), g_tszRoot);
+ mir_sntprintf(tszPath, _countof(tszPath), _T("%s\\langpack_*.txt"), g_tszRoot);
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(tszPath, &fd);
diff --git a/src/mir_core/src/path.cpp b/src/mir_core/src/path.cpp index e9fb81c672..051295984b 100644 --- a/src/mir_core/src/path.cpp +++ b/src/mir_core/src/path.cpp @@ -78,7 +78,7 @@ MIR_CORE_DLL(int) PathToAbsolute(const char *pSrc, char *pOut, const char *base) if (pSrc[0] == '\\')
pSrc++;
mir_snprintf(buf, "%s%s", base, pSrc);
- return GetFullPathNameA(buf, SIZEOF(buf), pOut, NULL);
+ return GetFullPathNameA(buf, _countof(buf), pOut, NULL);
}
MIR_CORE_DLL(void) CreatePathToFile(char *szFilePath)
@@ -101,7 +101,7 @@ MIR_CORE_DLL(int) CreateDirectoryTree(const char *szDir) return 1;
char szTestDir[MAX_PATH];
- mir_strncpy(szTestDir, szDir, SIZEOF(szTestDir));
+ mir_strncpy(szTestDir, szDir, _countof(szTestDir));
DWORD dwAttributes = GetFileAttributesA(szTestDir);
if (dwAttributes != INVALID_FILE_ATTRIBUTES && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
@@ -191,7 +191,7 @@ MIR_CORE_DLL(int) CreateDirectoryTreeW(const WCHAR *szDir) return 1;
WCHAR szTestDir[MAX_PATH];
- mir_wstrncpy(szTestDir, szDir, SIZEOF(szTestDir));
+ mir_wstrncpy(szTestDir, szDir, _countof(szTestDir));
DWORD dwAttributes = GetFileAttributesW(szTestDir);
if (dwAttributes != INVALID_FILE_ATTRIBUTES && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
@@ -209,12 +209,12 @@ MIR_CORE_DLL(int) CreateDirectoryTreeW(const WCHAR *szDir) int InitPathUtils(void)
{
- GetModuleFileNameA(NULL, szMirandaPath, SIZEOF(szMirandaPath));
+ GetModuleFileNameA(NULL, szMirandaPath, _countof(szMirandaPath));
char *p = strrchr(szMirandaPath, '\\');
if (p)
p[1] = 0;
- GetModuleFileNameW(NULL, szMirandaPathW, SIZEOF(szMirandaPathW));
+ GetModuleFileNameW(NULL, szMirandaPathW, _countof(szMirandaPathW));
WCHAR *tp = wcsrchr(szMirandaPathW, '\\');
if (tp)
tp[1] = 0;
diff --git a/src/mir_core/src/timezones.cpp b/src/mir_core/src/timezones.cpp index b9510f2a71..df5958fe7b 100644 --- a/src/mir_core/src/timezones.cpp +++ b/src/mir_core/src/timezones.cpp @@ -130,11 +130,11 @@ void FormatTime(const SYSTEMTIME *st, const TCHAR *szFormat, TCHAR *szDest, size if (iso)
tszTemp.AppendFormat(_T("%d-%02d-%02dT%02d:%02d:%02dZ"), st->wYear, st->wMonth, st->wDay, st->wHour, st->wMinute, st->wSecond);
else if (date) {
- GetDateFormat(LOCALE_USER_DEFAULT, fmt, st, NULL, dateTimeStr, SIZEOF(dateTimeStr));
+ GetDateFormat(LOCALE_USER_DEFAULT, fmt, st, NULL, dateTimeStr, _countof(dateTimeStr));
tszTemp.Append(dateTimeStr);
}
else {
- GetTimeFormat(LOCALE_USER_DEFAULT, fmt, st, NULL, dateTimeStr, SIZEOF(dateTimeStr));
+ GetTimeFormat(LOCALE_USER_DEFAULT, fmt, st, NULL, dateTimeStr, _countof(dateTimeStr));
tszTemp.Append(dateTimeStr);
}
}
@@ -382,7 +382,7 @@ static const ListMessages* GetListMessages(HWND hWnd, DWORD dwFlags) if (!(dwFlags & (TZF_PLF_CB | TZF_PLF_LB))) {
TCHAR tszClassName[128];
- GetClassName(hWnd, tszClassName, SIZEOF(tszClassName));
+ GetClassName(hWnd, tszClassName, _countof(tszClassName));
if (!mir_tstrcmpi(tszClassName, _T("COMBOBOX")))
dwFlags |= TZF_PLF_CB;
else if (!mir_tstrcmpi(tszClassName, _T("LISTBOX")))
@@ -548,7 +548,7 @@ void InitTimeZones(void) HKEY hSubKey;
TCHAR tszName[MIM_TZ_NAMELEN];
- DWORD dwSize = SIZEOF(tszName);
+ DWORD dwSize = _countof(tszName);
while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx(hKey, dwIndex++, tszName, &dwSize, NULL, NULL, 0, NULL)) {
if (ERROR_SUCCESS == RegOpenKeyEx(hKey, tszName, 0, KEY_QUERY_VALUE, &hSubKey)) {
dwSize = sizeof(tszName);
@@ -569,16 +569,16 @@ void InitTimeZones(void) tz->hash = mir_hashstrT(tszName);
tz->offset = INT_MIN;
- GetLocalizedString(hSubKey, _T("Display"), tz->szDisplay, SIZEOF(tz->szDisplay));
- GetLocalizedString(hSubKey, _T("Std"), tz->tzi.StandardName, SIZEOF(tz->tzi.StandardName));
- GetLocalizedString(hSubKey, _T("Dlt"), tz->tzi.DaylightName, SIZEOF(tz->tzi.DaylightName));
+ GetLocalizedString(hSubKey, _T("Display"), tz->szDisplay, _countof(tz->szDisplay));
+ GetLocalizedString(hSubKey, _T("Std"), tz->tzi.StandardName, _countof(tz->tzi.StandardName));
+ GetLocalizedString(hSubKey, _T("Dlt"), tz->tzi.DaylightName, _countof(tz->tzi.DaylightName));
g_timezones.insert(tz);
g_timezonesBias.insert(tz);
RegCloseKey(hSubKey);
}
- dwSize = SIZEOF(tszName);
+ dwSize = _countof(tszName);
}
RegCloseKey(hKey);
}
diff --git a/src/mir_core/src/ui_utils.cpp b/src/mir_core/src/ui_utils.cpp index be5e6df89d..f786afe73a 100644 --- a/src/mir_core/src/ui_utils.cpp +++ b/src/mir_core/src/ui_utils.cpp @@ -1403,7 +1403,7 @@ HTREEITEM CCtrlTreeView::MoveItemAbove(HTREEITEM hItem, HTREEITEM hInsertAfter) TVINSERTSTRUCT tvis = { 0 };
tvis.itemex.mask = (UINT)-1;
tvis.itemex.pszText = name;
- tvis.itemex.cchTextMax = SIZEOF(name);
+ tvis.itemex.cchTextMax = _countof(name);
tvis.itemex.hItem = hItem;
if (!GetItem(&tvis.itemex))
return NULL;
@@ -1628,7 +1628,7 @@ void CCtrlTreeView::TranslateItem(HTREEITEM hItem) {
TVITEMEX tvi;
TCHAR buf[128];
- GetItem(hItem, &tvi, buf, SIZEOF(buf));
+ GetItem(hItem, &tvi, buf, _countof(buf));
tvi.pszText = TranslateTS(tvi.pszText);
SetItem(&tvi);
}
@@ -1672,7 +1672,7 @@ HTREEITEM CCtrlTreeView::FindNamedItem(HTREEITEM hItem, const TCHAR *name) tvi.mask = TVIF_TEXT;
tvi.pszText = str;
- tvi.cchTextMax = SIZEOF(str);
+ tvi.cchTextMax = _countof(str);
while (tvi.hItem) {
GetItem(&tvi);
diff --git a/src/mir_core/src/winutil.cpp b/src/mir_core/src/winutil.cpp index 0dd0a2e897..e0aeb7c803 100644 --- a/src/mir_core/src/winutil.cpp +++ b/src/mir_core/src/winutil.cpp @@ -31,16 +31,16 @@ MIR_CORE_DLL(int) Utils_SaveWindowPosition(HWND hwnd, MCONTACT hContact, const c GetWindowPlacement(hwnd, &wp);
char szSettingName[64];
- mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sx", szNamePrefix);
+ mir_snprintf(szSettingName, _countof(szSettingName), "%sx", szNamePrefix);
db_set_dw(hContact, szModule, szSettingName, wp.rcNormalPosition.left);
- mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sy", szNamePrefix);
+ mir_snprintf(szSettingName, _countof(szSettingName), "%sy", szNamePrefix);
db_set_dw(hContact, szModule, szSettingName, wp.rcNormalPosition.top);
- mir_snprintf(szSettingName, SIZEOF(szSettingName), "%swidth", szNamePrefix);
+ mir_snprintf(szSettingName, _countof(szSettingName), "%swidth", szNamePrefix);
db_set_dw(hContact, szModule, szSettingName, wp.rcNormalPosition.right-wp.rcNormalPosition.left);
- mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sheight", szNamePrefix);
+ mir_snprintf(szSettingName, _countof(szSettingName), "%sheight", szNamePrefix);
db_set_dw(hContact, szModule, szSettingName, wp.rcNormalPosition.bottom-wp.rcNormalPosition.top);
return 0;
}
@@ -54,12 +54,12 @@ EXTERN_C MIR_CORE_DLL(int) Utils_RestoreWindowPosition(HWND hwnd, MCONTACT hCont GetWindowPlacement(hwnd, &wp);
char szSettingName[64];
- mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sx", szNamePrefix);
+ mir_snprintf(szSettingName, _countof(szSettingName), "%sx", szNamePrefix);
int x = db_get_dw(hContact, szModule, szSettingName, -1);
if (x == -1)
return 1;
- mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sy", szNamePrefix);
+ mir_snprintf(szSettingName, _countof(szSettingName), "%sy", szNamePrefix);
int y = (int)db_get_dw(hContact, szModule, szSettingName, -1);
if (flags & RWPF_NOSIZE)
@@ -68,10 +68,10 @@ EXTERN_C MIR_CORE_DLL(int) Utils_RestoreWindowPosition(HWND hwnd, MCONTACT hCont wp.rcNormalPosition.left = x;
wp.rcNormalPosition.top = y;
- mir_snprintf(szSettingName, SIZEOF(szSettingName), "%swidth", szNamePrefix);
+ mir_snprintf(szSettingName, _countof(szSettingName), "%swidth", szNamePrefix);
wp.rcNormalPosition.right = wp.rcNormalPosition.left+db_get_dw(hContact, szModule, szSettingName, -1);
- mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sheight", szNamePrefix);
+ mir_snprintf(szSettingName, _countof(szSettingName), "%sheight", szNamePrefix);
wp.rcNormalPosition.bottom = wp.rcNormalPosition.top+db_get_dw(hContact, szModule, szSettingName, -1);
}
wp.flags = 0;
diff --git a/src/mir_core/src/winver.cpp b/src/mir_core/src/winver.cpp index ffe68b114c..bf40d2a2fa 100644 --- a/src/mir_core/src/winver.cpp +++ b/src/mir_core/src/winver.cpp @@ -55,7 +55,7 @@ MIR_CORE_DLL(BOOL) IsFullScreen() HWND hWnd = GetForegroundWindow();
if (hWnd && hWnd != hWndDesktop && hWnd != hWndShell) {
TCHAR tszClassName[128] = _T("");
- GetClassName(hWnd, tszClassName, SIZEOF(tszClassName));
+ GetClassName(hWnd, tszClassName, _countof(tszClassName));
if (_tcscmp(tszClassName, _T("WorkerW"))) {
RECT rect, rectw, recti;
GetWindowRect(hWnd, &rectw);
@@ -80,7 +80,7 @@ MIR_CORE_DLL(BOOL) IsWorkstationLocked(void) TCHAR tszName[100];
DWORD cbName;
- BOOL bLocked = (!GetUserObjectInformation(hDesk, UOI_NAME, tszName, SIZEOF(tszName), &cbName) || mir_tstrcmpi(tszName, _T("default")) != 0);
+ BOOL bLocked = (!GetUserObjectInformation(hDesk, UOI_NAME, tszName, _countof(tszName), &cbName) || mir_tstrcmpi(tszName, _T("default")) != 0);
CloseDesktop(hDesk);
return bLocked;
}
|