OSDN Git Service

Cleanup: Eliminate _CRT_xxx deprecation situations
authorGreyMerlin <GreyMerlin7@gmail.com>
Mon, 25 Sep 2017 05:01:38 +0000 (22:01 -0700)
committerGreyMerlin <GreyMerlin7@gmail.com>
Wed, 4 Oct 2017 23:39:02 +0000 (16:39 -0700)
* The VC compiler began emitting Warnings for various deprecated CRT and
POSIX function names beginning with VS2005.  It was convenient to
ignore these warnings by defining the following preprocessor symbols in
the *.vcxproj files ...
_CRT_SECURE_NO_WARNINGS
_CRT_NONSTDC_NO_WARNINGS
_CRT_SECURE_NO_DEPRECATE

 * This change eliminates those symbol definitions, and appropriately
upgrades the code to properly use the modern, security enhanced,
functions.
 * Most of the existing code properly uses TCHAR, however some areas
explicitly use 'wchar_t' and some areas still use the old 'char' type.
 * The areas that still use 'char' need further investigation and
possible repair as the rest of the program completely uses Unicode.

18 files changed:
Externals/crystaledit/editlib/batch.cpp
Externals/crystaledit/editlib/ccrystaleditview.cpp
Externals/crystaledit/editlib/cs2cs.cpp
Externals/crystaledit/editlib/memcombo.cpp
Externals/crystaledit/editlib/statbar.cpp
Src/Common/BCMenu.cpp
Src/Common/CMoveConstraint.cpp
Src/Common/ClipBoard.cpp
Src/Common/LanguageSelect.cpp
Src/LineFiltersList.cpp
Src/PatchHTML.cpp
Src/VSSHelper.cpp
Src/VSSHelper.h
Src/codepage_detect.cpp
Src/diffutils/src/analyze.c
Src/diffutils/src/context.c
Src/diffutils/src/util.c
Src/paths.cpp

index c7348c2..00d7e53 100644 (file)
@@ -654,7 +654,8 @@ IsBatKeyword (LPCTSTR pszChars, int nLength)
 static bool
 IsUser1Keyword (LPCTSTR pszChars, int nLength)
 {
-  TCHAR buffer[13];
+  const int bufsiz = 13;
+  TCHAR buffer[bufsiz];
 
   if (nLength < 4 || pszChars[nLength - 4] != '.')
     {
@@ -664,13 +665,13 @@ IsUser1Keyword (LPCTSTR pszChars, int nLength)
     {
       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;
index 393826b..aa1b581 100644 (file)
@@ -1667,7 +1667,7 @@ ReplaceSelection (LPCTSTR pszNewText, int cchNewText, DWORD dwFlags)
           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
@@ -1869,7 +1869,7 @@ OnEditOperation (int nAction, LPCTSTR pszText, int cchText)
           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;
@@ -1899,22 +1899,24 @@ OnEditOperation (int nAction, LPCTSTR pszText, int cchText)
                         }
                     }
                 }
-              //  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 (' ');
@@ -1923,8 +1925,9 @@ OnEditOperation (int nAction, LPCTSTR pszText, int cchText)
                 }
               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;
 
@@ -1941,7 +1944,7 @@ OnEditOperation (int nAction, LPCTSTR pszText, int cchText)
             }
           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;
@@ -2003,7 +2006,7 @@ OnEditOperation (int nAction, LPCTSTR pszText, int cchText)
           //  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;
@@ -2048,7 +2051,7 @@ OnEditOperation (int nAction, LPCTSTR pszText, int cchText)
           //  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;
@@ -2104,7 +2107,7 @@ OnEditAutoComplete ()
       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;
@@ -2166,7 +2169,7 @@ OnEditAutoExpand ()
       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;
@@ -2656,7 +2659,7 @@ int CCrystalEditView::SpellGetLine (struct SpellData_t *pdata)
       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');
@@ -2744,7 +2747,7 @@ bool CCrystalEditView::LoadSpellDll (bool bAlert /*= true*/)
       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;
     }
index 90e6319..09ea86c 100644 (file)
@@ -231,11 +231,12 @@ iconvert (LPTSTR string, int source_coding, int destination_coding, bool alphabe
 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)
           {
index 1083ddf..1ae4945 100644 (file)
@@ -87,7 +87,7 @@ void SetComboBoxWidth(CComboBox &Control, LPCTSTR lpszText = NULL)
   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) {
index dc08f38..0eac266 100644 (file)
@@ -44,7 +44,7 @@ SetPaneFormattedText (int nIndex, BOOL bUpdate, LPCTSTR lpszFmt,...)
   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 ();
index cc9dfcc..8633aaa 100644 (file)
@@ -193,9 +193,10 @@ void BCMenuData::SetWideString(const wchar_t *szWideString)
        
        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
@@ -1367,8 +1368,9 @@ BOOL BCMenu::LoadMenu(LPCTSTR lpszResourceName)
                
                // 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....
index b40ff41..82cd535 100644 (file)
@@ -698,7 +698,7 @@ CMoveConstraint::Persist(bool saving, bool position)
                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)
index 54b52f7..9bd1dc1 100644 (file)
@@ -21,12 +21,13 @@ bool PutToClipboard(const String & text, HWND currentWindowHandle)
        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();
index 363b4aa..6392ea6 100644 (file)
@@ -409,24 +409,27 @@ LANGID LangFileInfo::LangId(const char *lang, const char *sublang)
 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"))
@@ -660,8 +663,8 @@ BOOL CLanguageSelect::LoadLanguageFile(LANGID wLangId, BOOL bShowError)
                        }
                }
        }
-       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;
@@ -944,7 +947,7 @@ void CLanguageSelect::TranslateMenu(HMENU h) const
                        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());
@@ -954,7 +957,7 @@ void CLanguageSelect::TranslateMenu(HMENU h) const
                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());
@@ -970,7 +973,7 @@ void CLanguageSelect::TranslateDialog(HWND h) const
                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());
@@ -987,7 +990,7 @@ String CLanguageSelect::LoadString(UINT id) const
                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;
        }
@@ -1017,7 +1020,7 @@ std::wstring CLanguageSelect::LoadDialogCaption(LPCTSTR lpDialogTemplateID) cons
                                        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;
                        }
@@ -1067,7 +1070,7 @@ static WORD GetLangFromLocale(LCID lcid)
        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;
 }
 
index 081fe3e..b0dda5c 100644 (file)
@@ -226,15 +226,16 @@ void LineFiltersList::Import(const String& filters)
 {
        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();
        }
index d299428..5e64e2d 100644 (file)
@@ -155,10 +155,14 @@ print_html_diff_header (struct file_data inf[])
   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");
 }
index 8ba3dc6..d0eb208 100644 (file)
@@ -140,7 +140,7 @@ bool VSSHelper::ReLinkVCProj(const String& strSavePath, String& sError)
                                //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)
@@ -370,7 +370,7 @@ bool VSSHelper::GetVCProjName(HANDLE hFile, HANDLE tFile) const
        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;
@@ -390,7 +390,7 @@ bool VSSHelper::GetSLNProjUniqueName(HANDLE hFile, HANDLE tFile, TCHAR * buf) co
        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;
index 0069f76..453eca5 100644 (file)
@@ -41,7 +41,7 @@ protected:
        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:
index a47decf..58491e4 100644 (file)
@@ -180,7 +180,7 @@ static unsigned demoGuessEncoding_rc(const char *src, size_t len, int defcodepag
                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;
 }
 
index 4dd08e4..58de7a9 100644 (file)
@@ -880,9 +880,9 @@ struct change * diff_2_files (struct file_data filevec[], int depth, int * bin_s
                                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)
index 54fafa4..02f5d8e 100644 (file)
@@ -45,9 +45,12 @@ print_context_label (mark, inf, label)
   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.  */
index d74410f..fe741ea 100644 (file)
@@ -171,21 +171,22 @@ begin_output ()
     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
@@ -888,7 +889,7 @@ concat (s1, s2, s3)
 {
   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;
 }
 
index 37f11c4..88189cd 100644 (file)
@@ -427,7 +427,7 @@ bool IsShortcut(const String& inPath)
 {
        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