static bool
IsUser1Keyword (LPCTSTR pszChars, int nLength)
{
- TCHAR buffer[13];
+ const int bufsiz = 13;
+ TCHAR buffer[bufsiz];
if (nLength < 4 || pszChars[nLength - 4] != '.')
{
{
for (int L = 0; L < sizeof(s_apszUser1KeywordList)/sizeof(TCHAR *); L++)
{
- _tcscpy (buffer, s_apszUser1KeywordList[L]);
- _tcscat (buffer, _T (".COM"));
+ _tcscpy_s (buffer, bufsiz, s_apszUser1KeywordList[L]);
+ _tcscat_s (buffer, bufsiz, _T (".COM"));
if (_tcsnicmp (buffer, pszChars, nLength) == 0
&& buffer[nLength] == 0)
return true;
- _tcscpy (buffer, s_apszUser1KeywordList[L]);
- _tcscat (buffer, _T (".EXE"));
+ _tcscpy_s (buffer, bufsiz, s_apszUser1KeywordList[L]);
+ _tcscat_s (buffer ,bufsiz, _T (".EXE"));
if (_tcsnicmp (buffer, pszChars, nLength) == 0
&& buffer[nLength] == 0)
return true;
if (lpszNewStr && m_nLastReplaceLen > 0)
{
LPTSTR buf = text.GetBuffer (m_nLastReplaceLen + 1);
- _tcsncpy (buf, lpszNewStr, m_nLastReplaceLen);
+ _tcsncpy_s (buf, m_nLastReplaceLen+1, lpszNewStr, m_nLastReplaceLen);
text.ReleaseBuffer (m_nLastReplaceLen);
}
else
CPoint ptCursorPos = GetCursorPos ();
ASSERT (ptCursorPos.y > 0);
- // Take indentation from the previos line
+ // Take indentation from the previous line
int nLength = m_pTextBuffer->GetLineLength (ptCursorPos.y - 1);
LPCTSTR pszLineChars = m_pTextBuffer->GetLineChars (ptCursorPos.y - 1);
int nPos = 0;
}
}
}
- // Insert part of the previos line
+ // Insert part of the previous line
TCHAR *pszInsertStr;
if ((GetFlags () & (SRCOPT_BRACEGNU|SRCOPT_BRACEANSI)) && isopenbrace (pszLineChars[nLength - 1]))
{
if (m_pTextBuffer->GetInsertTabs())
{
- pszInsertStr = (TCHAR *) _alloca (sizeof (TCHAR) * (nPos + 2));
- _tcsncpy (pszInsertStr, pszLineChars, nPos);
+ const size_t InsertSiz = (nPos + 2);
+ pszInsertStr = static_cast<TCHAR *> (_alloca (sizeof(TCHAR) * InsertSiz));
+ _tcsncpy_s (pszInsertStr, InsertSiz, pszLineChars, nPos);
pszInsertStr[nPos++] = _T ('\t');
}
else
{
int nTabSize = GetTabSize ();
int nChars = nTabSize - nPos % nTabSize;
- pszInsertStr = (TCHAR *) _alloca (sizeof (TCHAR) * (nPos + nChars + 1));
- _tcsncpy (pszInsertStr, pszLineChars, nPos);
+ const size_t InsertSiz = (nPos + nChars + 1);
+ pszInsertStr = static_cast<TCHAR *> (_alloca (sizeof (TCHAR) * InsertSiz));
+ _tcsncpy_s (pszInsertStr, InsertSiz, pszLineChars, nPos);
while (nChars--)
{
pszInsertStr[nPos++] = _T (' ');
}
else
{
- pszInsertStr = (TCHAR *) _alloca (sizeof (TCHAR) * (nPos + 1));
- _tcsncpy (pszInsertStr, pszLineChars, nPos);
+ const size_t InsertSiz = (nPos + 1);
+ pszInsertStr = static_cast<TCHAR *> (_alloca (sizeof (TCHAR) * InsertSiz));
+ _tcsncpy_s (pszInsertStr, InsertSiz, pszLineChars, nPos);
}
pszInsertStr[nPos] = 0;
}
else
{
- // Insert part of the previos line
+ // Insert part of the previous line
if ((GetFlags () & (SRCOPT_BRACEGNU|SRCOPT_BRACEANSI)) && isopenbrace (pszLineChars[nLength - 1]))
{
TCHAR *pszInsertStr;
// Enter stroke!
CPoint ptCursorPos = GetCursorPos ();
- // Take indentation from the previos line
+ // Take indentation from the previous line
int nLength = m_pTextBuffer->GetLineLength (ptCursorPos.y);
LPCTSTR pszLineChars = m_pTextBuffer->GetLineChars (ptCursorPos.y );
int nPos = 0;
// Enter stroke!
CPoint ptCursorPos = GetCursorPos ();
- // Take indentation from the previos line
+ // Take indentation from the previous line
int nLength = m_pTextBuffer->GetLineLength (ptCursorPos.y);
LPCTSTR pszLineChars = m_pTextBuffer->GetLineChars (ptCursorPos.y );
int nPos = 0;
CString sText;
LPTSTR pszBuffer = sText.GetBuffer (nLength + 2);
*pszBuffer = _T('<');
- _tcsncpy (pszBuffer + 1, pszBegin, nLength);
+ _tcsncpy_s (pszBuffer + 1, nLength - 1, pszBegin, nLength);
sText.ReleaseBuffer (nLength + 1);
CPoint ptTextPos;
ptCursorPos.x -= nLength;
nLength = pszEnd - pszBegin;
CString sText, sExpand;
LPTSTR pszBuffer = sText.GetBuffer (nLength + 1);
- _tcsncpy (pszBuffer, pszBegin, nLength);
+ _tcsncpy_s (pszBuffer, nLength + 1, pszBegin, nLength);
sText.ReleaseBuffer (nLength);
CPoint ptTextPos;
ptCursorPos.x -= nLength;
pdata->pszBuffer = szBuffer;
*pdata->pszBuffer = _T ('^');
if (nCount > 1)
- _tcscpy (pdata->pszBuffer + 1, pView->GetLineChars (pdata->nRow));
+ _tcscpy_s (pdata->pszBuffer + 1, sizeof(szBuffer)-1, pView->GetLineChars (pdata->nRow));
else
pdata->pszBuffer[nCount++] = _T (' ');
pdata->pszBuffer[nCount++] = _T ('\n');
SpellConfig = (int (*) (SpellData*)) GetProcAddress (hSpellDll, "SpellConfig");
if (SpellInit)
SpellInit (&spellData);
- _tcscpy (spellData.szIspell, szWIspellPath);
+ _tcscpy_s (spellData.szIspell, szWIspellPath);
spellData.GetLine = SpellGetLine;
spellData.Notify = SpellNotify;
}
int
iconvert_new (LPCTSTR source, LPTSTR *destination, int source_coding, int destination_coding, bool alphabet_only)
{
- LPTSTR dest = (LPTSTR) malloc (_tcslen (source) + 1 + 10); /* reserved for MYCHARSET= replacement */
+ const size_t destSiz = _tcslen(source) + 1 + 10;
+ LPTSTR dest = static_cast<LPTSTR> (malloc (sizeof(TCHAR) * destSiz)); /* reserved for MYCHARSET= replacement */
int result = -3;
if (dest)
{
- _tcscpy (dest, source);
+ _tcscpy_s (dest, destSiz, source);
result = iconvert (dest, source_coding, destination_coding, alphabet_only);
if (!result)
{
info.lfMenuFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
info.lfMenuFont.lfQuality = DEFAULT_QUALITY;
info.lfMenuFont.lfPitchAndFamily = FF_SWISS;
- _tcscpy(info.lfMenuFont.lfFaceName, _T("MS Sans Serif"));
+ _tcscpy_s(info.lfMenuFont.lfFaceName, _T("MS Sans Serif"));
oFont.CreateFontIndirect(&info.lfMenuFont);
oldFont = dc.SelectObject(&oFont);
if(lpszText && *lpszText) {
TCHAR buffer[256];
va_list argptr;
va_start (argptr, lpszFmt);
- _vsntprintf (buffer, sizeof(buffer)/sizeof(buffer[0]), lpszFmt, argptr);
+ _vsntprintf_s (buffer, sizeof(buffer), _TRUNCATE, lpszFmt, argptr);
va_end (argptr);
BOOL bResult = SetPaneText (nIndex, buffer, bUpdate);
UpdateWindow ();
if (szWideString)
{
- m_szMenuText = new wchar_t[sizeof(wchar_t)*(wcslen(szWideString)+1)];
+ const size_t MenuSiz = wcslen(szWideString) + 1;
+ m_szMenuText = new wchar_t[MenuSiz];
if (m_szMenuText)
- wcscpy(m_szMenuText,szWideString);
+ wcscpy_s(m_szMenuText, MenuSiz, szWideString);
}
else
m_szMenuText=NULL;//set to NULL so we need not bother about dangling non-NULL Ptrs
// Obtain Caption (and length)
- wchar_t *szCaption=new wchar_t[wcslen((wchar_t *)pTp)+1];
- wcscpy(szCaption,(wchar_t *)pTp);
+ const size_t CaptionSiz = wcslen((wchar_t *)pTp)+1;
+ wchar_t *szCaption=new wchar_t[CaptionSiz];
+ wcscpy_s(szCaption, CaptionSiz, reinterpret_cast<wchar_t *>(pTp));
pTp=&pTp[(wcslen((wchar_t *)pTp)+1)*sizeof(wchar_t)];//modified SK
// Handle popup menus first....
if (m_pFormView)
CWnd::FromHandle(m_hwndDlg)->GetParent()->ScreenToClient(&wprc);
CRect rc;
- int ct=_stscanf(str, _T("%d,%d,%d,%d"), &rc.left, &rc.top, &rc.right, &rc.bottom);
+ int ct=_stscanf_s(str, _T("%d,%d,%d,%d"), &rc.left, &rc.top, &rc.right, &rc.bottom);
if (ct==4)
{
if (position)
if (OpenClipboard(currentWindowHandle))
{
EmptyClipboard();
- HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (text.length()+1) * sizeof(TCHAR));
+ const size_t dataSiz = text.length() + 1;
+ HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, dataSiz * sizeof(TCHAR));
if (hData != NULL)
{
if (LPTSTR pszData = static_cast<LPTSTR>(::GlobalLock(hData)))
{
- _tcscpy(pszData, text.c_str());
+ _tcscpy_s(pszData, dataSiz, text.c_str());
GlobalUnlock(hData);
}
UINT fmt = GetClipTcharTextFormat();
LangFileInfo::LangFileInfo(LPCTSTR path)
: id(0)
{
- if (FILE *f = _tfopen(path, _T("r")))
+ FILE *f;
+ if (_tfopen_s(&f, path, _T("r")) == 0)
{
char buf[1024 + 1];
while (fgets(buf, sizeof buf - 1, f))
{
int i = 0;
- strcat(buf, "1");
- sscanf(buf, "msgid \" LANG_ENGLISH , SUBLANG_ENGLISH_US \" %d", &i);
+ strcat_s(buf, "1");
+ sscanf_s(buf, "msgid \" LANG_ENGLISH , SUBLANG_ENGLISH_US \" %d", &i);
if (i)
{
if (fgets(buf, sizeof buf, f))
{
char *lang = strstr(buf, "LANG_");
char *sublang = strstr(buf, "SUBLANG_");
+ char *langNext = nullptr;
+ char *sublangNext = nullptr;
if (lang && sublang)
{
- strtok(lang, ",\" \t\r\n");
- strtok(sublang, ",\" \t\r\n");
+ strtok_s(lang, ",\" \t\r\n", &langNext);
+ strtok_s(sublang, ",\" \t\r\n", &sublangNext);
lang += sizeof "LANG";
sublang += sizeof "SUBLANG";
if (0 != strcmp(sublang, "DEFAULT"))
}
}
}
- FILE *f = _tfopen(strPath.c_str(), _T("r"));
- if (f == 0)
+ FILE *f;
+ if (_tfopen_s(&f, strPath.c_str(), _T("r")) != 0)
{
FreeLibrary(m_hCurrentDll);
m_hCurrentDll = 0;
if (LPCWSTR text = pItemData->GetWideString())
{
unsigned uid = 0;
- swscanf(text, L"Merge.rc:%x", &uid);
+ swscanf_s(text, L"Merge.rc:%x", &uid);
std::wstring s;
if (TranslateString(uid, s))
pItemData->SetWideString(s.c_str());
if (::GetMenuString(h, i, text, countof(text), MF_BYPOSITION))
{
unsigned uid = 0;
- _stscanf(text, _T("Merge.rc:%x"), &uid);
+ _stscanf_s(text, _T("Merge.rc:%x"), &uid);
String s;
if (TranslateString(uid, s))
::ModifyMenu(h, i, mii.fState | MF_BYPOSITION, mii.wID, s.c_str());
TCHAR text[80];
::GetWindowText(h, text, countof(text));
unsigned uid = 0;
- _stscanf(text, _T("Merge.rc:%x"), &uid);
+ _stscanf_s(text, _T("Merge.rc:%x"), &uid);
String s;
if (TranslateString(uid, s))
::SetWindowText(h, s.c_str());
TCHAR text[1024];
AfxLoadString(id, text, countof(text));
unsigned uid = 0;
- _stscanf(text, _T("Merge.rc:%x"), &uid);
+ _stscanf_s(text, _T("Merge.rc:%x"), &uid);
if (!TranslateString(uid, s))
s = text;
}
while (*text++);
// Caption string is ahead
unsigned uid = 0;
- swscanf(text, L"Merge.rc:%x", &uid);
+ swscanf_s(text, L"Merge.rc:%x", &uid);
if (!TranslateString(uid, s))
s = text;
}
TCHAR buff[8] = {0};
WORD langID = 0;
if (GetLocaleInfo(lcid, LOCALE_IDEFAULTLANGUAGE, buff, countof(buff)))
- _stscanf(buff, _T("%4hx"), &langID);
+ _stscanf_s(buff, _T("%4hx"), &langID);
return langID;
}
{
const TCHAR sep[] = _T("\r\n");
TCHAR *p_filters = (TCHAR *)&filters[0];
+ TCHAR *pfilterNext = nullptr;
if (!filters.empty())
{
// find each regular expression and add to list
- TCHAR *token = _tcstok(p_filters, sep);
+ TCHAR *token = _tcstok_s(p_filters, sep, &pfilterNext);
while (token)
{
AddFilter(token, true);
- token = _tcstok(NULL, sep);
+ token = _tcstok_s(NULL, sep, &pfilterNext);
}
SaveFilters();
}
fprintf (outfile,
"<table cellspacing=\"0\" cellpadding=\"0\">\n"
" <tr class=\"vc_diff_header\">\n");
+
+ char ctimeBuffer[26];
+ ctime_s(ctimeBuffer, sizeof(ctimeBuffer), &inf[0].stat.st_mtime);
fprintf (outfile,
- " <th style=\"width:50%%; vertical-align:top;\">Left: %s</th>\n", ctime (&inf[0].stat.st_mtime));
+ " <th style=\"width:50%%; vertical-align:top;\">Left: %s</th>\n", ctimeBuffer);
+ ctime_s(ctimeBuffer, sizeof(ctimeBuffer), &inf[1].stat.st_mtime);
fprintf (outfile,
- " <th style=\"width:50%%; vertical-align:top;\">Right: %s</th>\n", ctime (&inf[1].stat.st_mtime));
+ " <th style=\"width:50%%; vertical-align:top;\">Right: %s</th>\n", ctimeBuffer);
fprintf (outfile,
" </tr>\n");
}
//find sccprojectname inside this string
if (_tcsstr(buffer, _T("SccProjectUniqueName")) == buffer)
{
- if (!GetSLNProjUniqueName(hfile, tfile, buffer))
+ if (!GetSLNProjUniqueName(hfile, tfile, buffer, nBufferSize))
succeed = false;
}
else if (_tcsstr(buffer, _T("SccProjectName")) == buffer)
return true;
}
-bool VSSHelper::GetSLNProjUniqueName(HANDLE hFile, HANDLE tFile, TCHAR * buf) const
+bool VSSHelper::GetSLNProjUniqueName(HANDLE hFile, HANDLE tFile, TCHAR * buf, size_t nBufSize) const
{
TCHAR buffer[1024] = {0};
DWORD dwNumWritten = 0;
while (!_tcsstr(buffer, _T(".")))
{
if (buffer[0] != '\\')
- _tcsncat(buf, buffer, _tcslen(buffer));
+ _tcsncat_s(buf, nBufSize, buffer, _tcslen(buffer));
if (!WriteFile(tFile, buffer, lstrlen(buffer), &dwNumWritten, NULL))
return false;
int GetWordFromBuffer(const TCHAR * inBuffer, DWORD dwInBufferSize,
TCHAR * outBuffer, DWORD dwOutBufferSize, const TCHAR * charset = NULL) const;
bool GetVCProjName(HANDLE hFile, HANDLE tFile) const;
- bool GetSLNProjUniqueName(HANDLE hFile, HANDLE tFile, TCHAR * buf) const;
+ bool GetSLNProjUniqueName(HANDLE hFile, HANDLE tFile, TCHAR * buf, size_t nBufSize) const;
bool GetSLNProjName(HANDLE hFile, HANDLE tFile, TCHAR * buf) const;
private:
size_t n = len < sizeof line - 1 ? len : sizeof line - 1;
memcpy(line, base, n);
line[n] = 0;
- } while (len && sscanf(line, "#pragma code_page(%5u)", &cp) != 1);
+ } while (len && sscanf_s(line, "#pragma code_page(%5u)", &cp) != 1);
return cp;
}
for (i = 0; i < 2; i++)
while (filevec[i].buffered_chars < buffer_size)
{
- int r = read (filevec[i].desc,
- filevec[i].buffer + filevec[i].buffered_chars,
- (int)(buffer_size - filevec[i].buffered_chars));
+ int r = _read (filevec[i].desc,
+ filevec[i].buffer + filevec[i].buffered_chars,
+ (int)(buffer_size - filevec[i].buffered_chars));
if (r == 0)
break;
if (r < 0)
if (label)
fprintf (outfile, "%s %s\n", mark, label);
else
+ {
/* See Posix.2 section 4.17.6.1.4 for this format. */
- fprintf (outfile, "%s %s\t%s",
- mark, inf->name, ctime (&inf->stat.st_mtime));
+ char ctimeBuffer[26];
+ ctime_s(ctimeBuffer, sizeof(ctimeBuffer), &inf->stat.st_mtime);
+ fprintf (outfile, "%s %s\t%s", mark, inf->name, ctimeBuffer);
+ }
}
/* Print a header for a context diff, with the file names and dates. */
return;
/* Construct the header of this piece of diff. */
- name = xmalloc (strlen (current_name0) + strlen (current_name1)
- + strlen (switch_string) + 7);
+ const size_t nameSiz = strlen(current_name0) + strlen(current_name1)
+ + strlen(switch_string) + 7;
+ name = xmalloc (nameSiz);
/* Posix.2 section 4.17.6.1.1 specifies this format. But there are some
bugs in the first printing (IEEE Std 1003.2-1992 p 251 l 3304):
it says that we must print only the last component of the pathnames,
and it requires two spaces after "diff" if there are no options.
These requirements are silly and do not match historical practice. */
- sprintf (name, "diff%s %s %s", switch_string, current_name0, current_name1);
+ sprintf_s (name, nameSiz, "diff%s %s %s", switch_string, current_name0, current_name1);
if (paginate_flag)
{
#if defined(__MSDOS__) || defined(__NT__) || defined(WIN32)
char command[120];
- sprintf(command, "%s -f -h \"%s\"", PR_FILE_NAME, name);
+ sprintf_s(command, sizeof(command), "%s -f -h \"%s\"", PR_FILE_NAME, name);
if ((outfile = popen(command, "w")) == NULL)
pfatal_with_name ("popen");
#else
{
size_t len = strlen (s1) + strlen (s2) + strlen (s3);
char *new = xmalloc (len + 1);
- sprintf (new, "%s%s%s", s1, s2, s3);
+ sprintf_s (new, len+1, "%s%s%s", s1, s2, s3);
return new;
}
{
const TCHAR ShortcutExt[] = _T(".lnk");
TCHAR ext[_MAX_EXT] = {0};
- _tsplitpath(inPath.c_str(), NULL, NULL, NULL, ext);
+ _tsplitpath_s(inPath.c_str(), NULL, 0, NULL, 0, NULL, 0, ext, _MAX_EXT);
if (_tcsicmp(ext, ShortcutExt) == 0)
return true;
else