#include <windows.h>
#include <cassert>
#include <algorithm>
+#include <strsafe.h>
#include "UnicodeString.h"
#include "coretypes.h"
LONG ret = RegQueryValueEx (m_hKey, (LPTSTR) pszKey, NULL,
&dwType, (LPBYTE)pData, &len);
if (ret != ERROR_SUCCESS)
- {
- _tcsncpy(pData, defval, std::min((DWORD)_tcslen(defval), dwLen));
- pData[std::min((DWORD)_tcslen(defval), dwLen-1)] = _T('\0');
- }
+ StringCchCopy(pData, dwLen, defval);
}
#pragma once
#include "UnicodeString.h"
+#include <strsafe.h>
void replace_char(TCHAR *s, int target, int repl);
size_t linelen(const char *string, size_t maxlen);
+
+template <typename T, size_t N>
+T *_tcscpy_safe(T(&dst)[N], const T *src)
+{
+ StringCchCopy(reinterpret_cast<T *>(&dst), N, src);
+ return reinterpret_cast<T *>(&dst);
+}
#include <shlwapi.h>
#include <tchar.h>
#include <stdarg.h>
+#include <strsafe.h>
#include "lwdisp.h"
#include "dllproxy.h"
static void mycpyt2w(LPCTSTR tsz, wchar_t * wdest, size_t limit)
{
#ifdef _UNICODE
- wcsncpy(wdest, tsz, limit);
+ StringCchCopyW(wdest, limit, tsz);
#else
MultiByteToWideChar(CP_ACP, 0, tsz, -1, wdest, (int)limit);
-#endif
// always terminate the string
wdest[limit-1] = 0;
+#endif
}
static void mycpyt2a(LPCTSTR tsz, char * adest, size_t limit)
{
#ifdef _UNICODE
WideCharToMultiByte(CP_ACP, 0, tsz, -1, adest, (int)limit, 0, 0);
-#else
- strncpy(adest, tsz, limit);
-#endif
// always terminate the string
adest[limit-1] = 0;
+#else
+ StringCchCopyA(adest, list, tsz);
+#endif
}
#ifdef _WIN64
#include <cstdio>
#include <tchar.h>
#include <assert.h>
+#include <strsafe.h>
#include "coretypes.h"
#include "UnicodeString.h"
if (m_strFileName.empty())
GetModuleFileName(NULL, szFileName, MAX_PATH);
else
- _tcsncpy(szFileName, m_strFileName.c_str(), MAX_PATH - 1);
+ StringCchCopy(szFileName, MAX_PATH, m_strFileName.c_str());
DWORD dwVerInfoSize = GetFileVersionInfoSize(szFileName, &dwVerHnd);
if (dwVerInfoSize)
#include <cstdio>
#include <windows.h>
#include <tchar.h>
+#include <strsafe.h>
#endif
{
static TCHAR message[512];
_sntprintf(message, sizeof(message)/sizeof(message[0]), _T("Exception %s (0x%.8x)"), getSeMessage(), getSeNumber());
- _tcsncpy(lpszError, message, nMaxError-1);
- lpszError[nMaxError-1] = 0;
+ StringCchCopy(lpszError, nMaxError, message);
return true;
}
#else
#include "paths.h"
#include "Environment.h"
#include "FileFilter.h"
+#include "coretools.h"
using std::vector;
using Poco::RegularExpression;
// structured exception are catched here thanks to class SE_Exception
if (!(e.GetErrorMessage(errorText, 500, NULL)))
// don't localize this as we do not localize the known exceptions
- _tcscpy(errorText, _T("Unknown CException"));
+ _tcscpy_safe(errorText, _T("Unknown CException"));
bExceptionCatched = true;
}
catch(...)
{
// don't localize this as we do not localize the known exceptions
- _tcscpy(errorText, _T("Unknown C++ exception"));
+ _tcscpy_safe(errorText, _T("Unknown C++ exception"));
bExceptionCatched = true;
}
// structured exception are catched here thanks to class SE_Exception
if (!(e.GetErrorMessage(errorText, 500, NULL)))
// don't localize this as we do not localize the known exceptions
- _tcscpy(errorText, _T("Unknown CException"));
+ _tcscpy_safe(errorText, _T("Unknown CException"));
bExceptionCatched = true;
}
catch(...)
{
// don't localize this as we do not localize the known exceptions
- _tcscpy(errorText, _T("Unknown C++ exception"));
+ _tcscpy_safe(errorText, _T("Unknown C++ exception"));
bExceptionCatched = true;
}
#include "ssapi.h" // BSP - Includes for Visual Source Safe COM interface
#include "CCPromptDlg.h"
#include "VSSHelper.h"
+#include "coretools.h"
using Poco::format;
using Poco::Process;
static TCHAR buffer1[nBufferSize];
static TCHAR buffer2[nBufferSize];
- _tcscpy(buffer1, strSavePath.c_str());
- _tcscpy(buffer2, m_pVssHelper->GetProjectBase().c_str());
+ _tcscpy_safe(buffer1, strSavePath.c_str());
+ _tcscpy_safe(buffer2, m_pVssHelper->GetProjectBase().c_str());
_tcslwr(buffer1);
_tcslwr(buffer2);
{
int index = (int)(pdest - buffer1 + 1);
- _tcscpy(buffer, buffer1);
+ _tcscpy_safe(buffer, buffer1);
TCHAR * fp = &buffer[int(index + _tcslen(pbuf2))];
sname = fp;
if (sname[0] == ':')
{
- _tcscpy(buffer2, sname);
- _tcscpy(buffer, (TCHAR*)&buffer2[2]);
+ _tcscpy_safe(buffer2, (LPCTSTR)sname);
+ _tcscpy_safe(buffer, (TCHAR*)&buffer2[2]);
sname = buffer;
}
}