TCHAR szDir[_MAX_DIR] = {'\0'};\r
\r
if (GetModuleFileName(NULL, szModuleFileName, sizeof(szModuleFileName))) {\r
- _tsplitpath(szModuleFileName, szDrive, szDir, NULL, NULL);\r
+ _tsplitpath_s(szModuleFileName, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, NULL, 0, NULL, 0);\r
}\r
\r
TCHAR szOldPath[MAX_PATH] = {'\0'}; // This path is used by XKeymacs 3.22 and earlier\r
- _tmakepath(szOldPath, szDrive, szDir, lpszFileName, m_szExt);\r
+ _tmakepath_s(szOldPath, szDrive, szDir, lpszFileName, m_szExt);\r
\r
PathAppend(szDir, _T("etc"));\r
TCHAR szEtc[MAX_PATH] = {'\0'};\r
- _tmakepath(szEtc, szDrive, szDir, NULL, NULL);\r
+ _tmakepath_s(szEtc, szDrive, szDir, NULL, NULL);\r
(void)_tmkdir(szEtc); // make etc directory if needed\r
\r
TCHAR szPath[MAX_PATH] = {'\0'};\r
- _tmakepath(szPath, szDrive, szDir, lpszFileName, m_szExt);\r
+ _tmakepath_s(szPath, szDrive, szDir, lpszFileName, m_szExt);\r
\r
if (_trename(szOldPath, szPath)) { // try to move old file as backup when rename returns an error because files exist in both directorys\r
TCHAR szBackupPath[MAX_PATH] = {'\0'};\r
TCHAR szBackupFlag[_MAX_FNAME] = _T("~");\r
- _tmakepath(szBackupPath, szDrive, szDir, _tcscat(szBackupFlag, lpszFileName), m_szExt);\r
+ _tcscat_s(szBackupFlag, lpszFileName);\r
+ _tmakepath_s(szBackupPath, szDrive, szDir, szBackupFlag, m_szExt);\r
(void)_trename(szOldPath, szBackupPath); // do nothing when a backup file has existed already\r
}\r
\r
{\r
TCHAR szPath[MAX_PATH] = {'\0'};\r
if (SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, TRUE)) {\r
- _tmakepath(szPath, NULL, szPath, lpszFileName, m_szExt);\r
+ _tmakepath_s(szPath, NULL, szPath, lpszFileName, m_szExt);\r
Load(szPath);\r
}\r
}\r
LPCTSTR szLanguage = _T("unknown");\r
\r
TCHAR lptstrFilename[MAX_PATH] = {'\0'};\r
- _tmakepath(lptstrFilename, NULL, _tgetenv(_T("windir")), _T("explorer"), _T("exe"));\r
+ TCHAR windir[MAX_PATH] = "";\r
+ size_t len;\r
+ _tgetenv_s(&len, windir, _T("windir"));\r
+ _tmakepath_s(lptstrFilename, NULL, windir, _T("explorer"), _T("exe"));\r
DWORD dwLen = GetFileVersionInfoSize(lptstrFilename, NULL);\r
\r
if (dwLen) {\r
}\r
\r
if (*szWindowText == '"' && _tcschr(szWindowText+1, _T('"'))) { // "foo bar" -> foo bar\r
- int nApplicationName = _tcschr(szWindowText+1, _T('"')) - szWindowText - 1; // length of "foo bar"\r
- _tcsncpy(szWindowText, szWindowText + 1, nApplicationName);\r
- memset(szWindowText + nApplicationName, 0, WINDOW_TEXT_LENGTH - nApplicationName);\r
+ int len = _tcschr(szWindowText+1, _T('"')) - szWindowText - 1; // length of "foo bar"\r
+ memmove(szWindowText, szWindowText + 1, len);\r
+ memset(szWindowText + len, 0, WINDOW_TEXT_LENGTH - len);\r
} else if (_tcschr(szWindowText, _T(' '))) { // foo bar -> foo\r
- LPTSTR pFirstSpace = _tcschr(szWindowText, _T(' '));\r
- memset(pFirstSpace, 0, WINDOW_TEXT_LENGTH - (pFirstSpace - szWindowText));\r
+ LPTSTR p = _tcschr(szWindowText, _T(' '));\r
+ memset(p, 0, WINDOW_TEXT_LENGTH - (p - szWindowText));\r
}\r
\r
memset(szApplicationName, 0, MAX_PATH);\r
- _stprintf(szApplicationName, _T("%s"), szWindowText);\r
+ _stprintf_s(szApplicationName, MAX_PATH, _T("%s"), szWindowText);\r
\r
static LPCTSTR const szExe = _T(".exe");\r
if (_tcsnicmp(szApplicationName + _tcslen(szApplicationName) - _tcslen(szExe), szExe, _tcslen(szExe))) {\r
- _tcscat(szApplicationName, szExe);\r
+ _tcscat_s(szApplicationName, MAX_PATH, szExe);\r
}\r
}\r
\r
}\r
\r
TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};\r
- _stprintf(sz, _T("%s%s"), szPromptName[i], szSeparator);\r
+ _stprintf_s(sz, _T("%s%s"), szPromptName[i], szSeparator);\r
\r
if (!_tcsnicmp(szWindowText, sz, _tcslen(sz))) { // "Command Promp - foo"\r
- _tcscpy(szWindowText, szWindowText + _tcslen(sz));\r
+ _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, szWindowText + _tcslen(sz));\r
FairConsoleApplicationName(szApplicationName, szWindowText);\r
return;\r
}\r
}\r
\r
for (i = 0; i < sizeof(szPromptPath) / sizeof(szPromptPath[0]); ++i) {\r
- TCHAR szWindowTextLower[WINDOW_TEXT_LENGTH] = {'\0'};\r
- _tcscpy(szWindowTextLower, szWindowText);\r
- _tcslwr(szWindowTextLower);\r
+ TCHAR lower[WINDOW_TEXT_LENGTH] = {'\0'};\r
+ _tcscpy_s(lower, szWindowText);\r
+ _tcslwr_s(lower);\r
\r
- if (_tcsstr(szWindowTextLower, szPromptPath[i])) {\r
+ if (_tcsstr(lower, szPromptPath[i])) {\r
TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};\r
- _stprintf(sz, _T("%s%s"), szPromptPath[i], szSeparator);\r
+ _stprintf_s(sz, _T("%s%s"), szPromptPath[i], szSeparator);\r
\r
- if (_tcsstr(szWindowTextLower, sz)) { // "X:\WINNT\system32\cmd.exe - foo"\r
- _tcscpy(szWindowText, _tcsstr(szWindowTextLower, sz) + _tcslen(sz));\r
+ if (_tcsstr(lower, sz)) { // "X:\WINNT\system32\cmd.exe - foo"\r
+ _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, _tcsstr(lower, sz) + _tcslen(sz));\r
FairConsoleApplicationName(szApplicationName, szWindowText);\r
return;\r
} else { // "X:\WINNT\system32\cmd.exe"\r
}\r
\r
LPTSTR newName = NULL, newText = NULL;\r
- if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))\r
+ if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))\r
|| (*szWindowText == _T('~'))\r
|| (*szWindowText == _T('/'))) { // Bash\r
newName = _T("bash.exe");\r
}\r
if (newName) {\r
memset(szApplicationName, 0, MAX_PATH);\r
- _stprintf(szApplicationName, newName);\r
+ _tcscpy_s(szApplicationName, MAX_PATH, newName);\r
memset(szWindowText, 0, WINDOW_TEXT_LENGTH);\r
- _stprintf(szWindowText, newText);\r
+ _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, newText);\r
}\r
} else if (IsJavaW(szApplicationName)) {\r
LPTSTR newName = NULL;\r
}\r
if (newName) {\r
memset(szApplicationName, 0, MAX_PATH);\r
- _stprintf(szApplicationName, newName);\r
+ _tcscpy_s(szApplicationName, MAX_PATH, newName);\r
}\r
}\r
return;\r
HKL hKL = GetKeyboardLayout(0);\r
if (ImmIsIME(hKL)) {\r
if (!ImmGetIMEFileName(hKL, m_szIMEName, sizeof(m_szIMEName))) {\r
- _tcsncpy(m_szIMEName, _T("IME"), sizeof(m_szIMEName)); // IDS_IME_FILE_NAME\r
+ _tcsncpy_s(m_szIMEName, _T("IME"), _TRUNCATE); // IDS_IME_FILE_NAME\r
}\r
// CUtils::Log(_T("SetApplicationName: m_szIMEName == %s"), m_szIMEName);\r
}\r
HKL hKL = GetKeyboardLayout(0);\r
if (ImmIsIME(hKL)) {\r
if (!ImmGetIMEFileName(hKL, m_szApplicationName, sizeof(m_szApplicationName))) {\r
- _tcsncpy(m_szApplicationName, m_szIMEName, sizeof(m_szApplicationName));\r
+ _tcsncpy_s(m_szApplicationName, m_szIMEName, _TRUNCATE);\r
}\r
- _tcsncpy(m_szIMEName, m_szApplicationName, sizeof(m_szIMEName));\r
+ _tcsncpy_s(m_szIMEName, m_szApplicationName, sizeof(m_szIMEName));\r
} else {\r
// ImmIsIME return 0 on Word2002, Excel2002, etc. with IME2002, so...\r
// _tcsncpy(m_szApplicationName, _T("imjp81.ime"), sizeof(m_szApplicationName));\r
- _tcsncpy(m_szApplicationName, m_szIMEName, sizeof(m_szApplicationName));\r
+ _tcsncpy_s(m_szApplicationName, m_szIMEName, _TRUNCATE);\r
}\r
} else {\r
// CUtils::Log(_T("SetApplicationName: appication (%s)"), m_szApplicationName);\r
CString szFn(m_szApplicationName);\r
szFn.Delete(0, szFn.ReverseFind(_T('\\')) + 1);\r
ZeroMemory(m_szApplicationName, sizeof(m_szApplicationName));\r
- _tcsncpy(m_szApplicationName, szFn, szFn.GetLength());\r
+ _tcscpy_s(m_szApplicationName, szFn);\r
\r
// CUtils::Log(_T("SetApplicationName: appication [%s]"), m_szApplicationName);\r
\r
// CUtils::Log(_T("SetApplicationName: console"));\r
\r
memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
- _tcscpy(m_szApplicationName, _T("CMD.exe"));\r
+ _tcscpy_s(m_szApplicationName, _T("CMD.exe"));\r
TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
SetCorrectApplicationName(m_szApplicationName, szWindowText);\r
// CUtils::Log(_T("SetApplicationName: cygwin"));\r
\r
memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
- _tcscpy(m_szApplicationName, _T("bash.exe"));\r
+ _tcscpy_s(m_szApplicationName, _T("bash.exe"));\r
}\r
// CUtils::Log(_T("name: %s"), m_szApplicationName);\r
}\r
\r
BOOL CUtils::IsConsole(LPCTSTR szApplicationName)\r
{\r
- return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), MAX_PATH)\r
- || !_tcsnicmp(szApplicationName, _T("CMD.exe"), MAX_PATH);\r
+ return !_tcsicmp(szApplicationName, _T("WINOA386.MOD"))\r
+ || !_tcsicmp(szApplicationName, _T("CMD.exe"));\r
}\r
\r
BOOL CUtils::IsJavaW(LPCTSTR szApplicationName)\r
{\r
- return !_tcsnicmp(szApplicationName, _T("javaw.exe"), MAX_PATH);\r
+ return !_tcsicmp(szApplicationName, _T("javaw.exe"));\r
}\r
\r
BOOL CUtils::IsSleipnir()\r
\r
for (unsigned int nIndex = 0; nIndex < _tcslen(fmt); ) {\r
LPTSTR pNextString = fmt + nIndex;\r
- LPTSTR pLogEnd = szLog + _tcslen(szLog);\r
+ int len = _tcslen(szLog);\r
+ LPTSTR pLogEnd = szLog + len;\r
\r
if (*pNextString == _T('%')) {\r
TCHAR szFormatTag[LOG_MAX] = {'0'};\r
- _tcscpy(szFormatTag, pNextString);\r
+ _tcscpy_s(szFormatTag, pNextString);\r
\r
switch (GetFormatTag(szFormatTag)) {\r
case _T('d'):\r
case _T('X'):\r
case _T('u'):\r
case _T('c'):\r
- _stprintf(pLogEnd, szFormatTag, va_arg(ap, int));\r
+ _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, int));\r
break;\r
case _T('s'):\r
- _stprintf(pLogEnd, szFormatTag, va_arg(ap, LPTSTR));\r
+ _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, LPTSTR));\r
break;\r
case _T('f'):\r
case _T('e'):\r
case _T('E'):\r
case _T('g'):\r
case _T('G'):\r
- _stprintf(pLogEnd, szFormatTag, va_arg(ap, double));\r
+ _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, double));\r
break;\r
case _T('p'):\r
- _stprintf(pLogEnd, szFormatTag, va_arg(ap, void *));\r
+ _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, void *));\r
break;\r
case _T('n'):\r
- _stprintf(pLogEnd, szFormatTag, va_arg(ap, int *));\r
+ _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, int *));\r
break;\r
case _T('%'):\r
default:\r
- _stprintf(pLogEnd, _T("%s"), szFormatTag);\r
+ _stprintf_s(pLogEnd, LOG_MAX - len, _T("%s"), szFormatTag);\r
break;\r
}\r
\r
nIndex += _tcslen(szFormatTag);\r
} else {\r
TCHAR szString[LOG_MAX] = {'0'};\r
- _tcscpy(szString, pNextString);\r
- LPTSTR pString = _tcstok(szString, _T("%"));\r
- _stprintf(pLogEnd, _T("%s"), pString);\r
+ _tcscpy_s(szString, pNextString);\r
+ LPTSTR c;\r
+ LPTSTR pString = _tcstok_s(szString, _T("%"), &c);\r
+ _stprintf_s(pLogEnd, LOG_MAX - len, _T("%s"), pString);\r
\r
nIndex += _tcslen(pString);\r
}\r
TCHAR szPath[MAX_PATH] = {'\0'};\r
if (GetTempPath(MAX_PATH, szPath)) {\r
#ifndef _WIN64\r
- _tmakepath(szPath, NULL, szPath, _T("xkeylog"), _T("txt"));\r
+ _tmakepath_s(szPath, NULL, szPath, _T("xkeylog"), _T("txt"));\r
#else\r
- _tmakepath(szPath, NULL, szPath, _T("xkeylog64"), _T("txt"));\r
+ _tmakepath_s(szPath, NULL, szPath, _T("xkeylog64"), _T("txt"));\r
#endif\r
} else {\r
- _tcscpy(szPath, _T("c:\\xkeylog.txt"));\r
+ _tcscpy_s(szPath, _T("c:\\xkeylog.txt"));\r
}\r
- FILE *fp = _tfopen(szPath, _T("a"));\r
+ FILE *fp;\r
+ _tfopen_s(&fp, szPath, _T("a"));\r
_ftprintf(fp, _T("%8d: %s %s\n"), n++, m_szApplicationName, szLog);\r
fflush(fp);\r
fclose(fp);\r