diff --git a/src/Dialogs.c b/src/Dialogs.c index 8f437b7e7..31efa1496 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -78,12 +78,12 @@ int MsgBox(int iType,UINT uIdMsg,...) 0, NULL); StrTrim(lpMsgBuf,L" \a\b\f\n\r\t\v"); - StrCatBuff(szText,L"\n",COUNTOF(szText)); - StrCatBuff(szText,lpMsgBuf,COUNTOF(szText)); + StringCchCat(szText,COUNTOF(szText),L"\n"); + StringCchCat(szText,COUNTOF(szText),lpMsgBuf); LocalFree(lpMsgBuf); wcht = *CharPrev(szText,StrEnd(szText)); if (IsCharAlphaNumeric(wcht) || wcht == '"' || wcht == '\'') - StrCatBuff(szText,L".",COUNTOF(szText)); + StringCchCat(szText,COUNTOF(szText),L"."); } GetString(IDS_APPTITLE,szTitle,COUNTOF(szTitle)); diff --git a/src/Edit.c b/src/Edit.c index a3d3014ba..fec5f6f72 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -34,6 +34,10 @@ #include "helpers.h" #include "edit.h" +#ifndef LCMAP_TITLECASE +#define LCMAP_TITLECASE 0x00000300 // Title Case Letters bit mask +#endif + extern UINT16 g_uWinVer; extern HWND hwndMain; extern HWND hwndEdit; @@ -701,7 +705,8 @@ void Encoding_GetLabel(int iEncoding) { } if (!pwsz) pwsz = wch; - StrCpyN(mEncoding[iEncoding].wchLabel,pwsz,COUNTOF(mEncoding[iEncoding].wchLabel)); + StringCchCopyN(mEncoding[iEncoding].wchLabel,COUNTOF(mEncoding[iEncoding].wchLabel), + pwsz,COUNTOF(mEncoding[iEncoding].wchLabel)); } } @@ -792,13 +797,13 @@ void Encoding_AddToListView(HWND hwnd,int idSel,BOOL bRecodeOnly) WCHAR *pwsz = StrChr(pEE[i].wch, L';'); if (pwsz) { - StrCpyN(wchBuf,CharNext(pwsz),COUNTOF(wchBuf)); + StringCchCopyN(wchBuf,COUNTOF(wchBuf),CharNext(pwsz),COUNTOF(wchBuf)); pwsz = StrChr(wchBuf, L';'); if (pwsz) *pwsz = 0; } else - StrCpyN(wchBuf,pEE[i].wch,COUNTOF(wchBuf)); + StringCchCopyN(wchBuf,COUNTOF(wchBuf),pEE[i].wch,COUNTOF(wchBuf)); if (Encoding_IsANSI(id)) StringCchCatN(wchBuf,COUNTOF(wchBuf),wchANSI,COUNTOF(wchANSI)); @@ -885,13 +890,13 @@ void Encoding_AddToComboboxEx(HWND hwnd,int idSel,BOOL bRecodeOnly) WCHAR *pwsz = StrChr(pEE[i].wch, L';'); if (pwsz) { - StrCpyN(wchBuf,CharNext(pwsz),COUNTOF(wchBuf)); + StringCchCopyN(wchBuf,COUNTOF(wchBuf),CharNext(pwsz),COUNTOF(wchBuf)); pwsz = StrChr(wchBuf, L';'); if (pwsz) *pwsz = 0; } else - StrCpyN(wchBuf,pEE[i].wch,COUNTOF(wchBuf)); + StringCchCopyN(wchBuf,COUNTOF(wchBuf),pEE[i].wch,COUNTOF(wchBuf)); if (Encoding_IsANSI(id)) StringCchCatN(wchBuf,COUNTOF(wchBuf),wchANSI,COUNTOF(wchANSI)); @@ -1759,17 +1764,15 @@ void EditTitleCase(HWND hwnd) cpEdit = (UINT)SendMessage(hwnd,SCI_GETCODEPAGE,0,0); - cchTextW = MultiByteToWideChar(cpEdit,0,pszText,iSelLength,pszTextW,(int)GlobalSize(pszTextW)/sizeof(WCHAR)); + cchTextW = MultiByteToWideChar(cpEdit,0,pszText,iSelLength,pszTextW,iSelLength); if (IsW7()) { - LPWSTR pszMappedW = LocalAlloc(LPTR,LocalSize(pszTextW)); + LPWSTR pszMappedW = LocalAlloc(LPTR,GlobalSize(pszTextW)); - if (LCMapString( - LOCALE_SYSTEM_DEFAULT,LCMAP_LINGUISTIC_CASING|/*LCMAP_TITLECASE*/0x00000300, - pszTextW,cchTextW,pszMappedW,(int)(LocalSize(pszMappedW)/sizeof(WCHAR)))) { - - StrCpyN(pszTextW,pszMappedW,(int)(GlobalSize(pszTextW)/sizeof(WCHAR))); + if (LCMapString(LOCALE_SYSTEM_DEFAULT,LCMAP_LINGUISTIC_CASING|LCMAP_TITLECASE, + pszTextW,cchTextW,pszMappedW,iSelLength)) { + StringCchCopyN(pszTextW,iSelLength,pszMappedW,iSelLength); bChanged = TRUE; } else @@ -4539,8 +4542,9 @@ void EditSortLines(HWND hwnd,int iSortFlags) qsort(pLines,iLineCount,sizeof(SORTLINE),CmpStd); } - pmszResult = LocalAlloc(LPTR,cchTotal + 2*iLineCount +1); - pmszBuf = LocalAlloc(LPTR,ichlMax +1); + int lenRes = cchTotal + 2 * iLineCount + 1; + pmszResult = LocalAlloc(LPTR,lenRes); + pmszBuf = LocalAlloc(LPTR,ichlMax+1); for (i = 0; i < iLineCount; i++) { BOOL bDropLine = FALSE; @@ -4565,8 +4569,8 @@ void EditSortLines(HWND hwnd,int iSortFlags) } if (!bDropLine) { WideCharToMultiByte(uCodePage,0,pLines[i].pwszLine,-1,pmszBuf,(int)LocalSize(pmszBuf),NULL,NULL); - StrCatBuffA(pmszResult,pmszBuf,(int)LocalSize(pmszResult)); - StrCatBuffA(pmszResult,mszEOL,(int)LocalSize(pmszResult)); + StringCchCatA(pmszResult,lenRes,pmszBuf); + StringCchCatA(pmszResult,lenRes,mszEOL); } } } @@ -4807,7 +4811,7 @@ void EditGetExcerpt(HWND hwnd,LPWSTR lpszExcerpt,DWORD cchExcerpt) tch[cchExcerpt-3] = L'.'; tch[cchExcerpt-4] = L'.'; } - StrCpyN(lpszExcerpt,tch,cchExcerpt); + StringCchCopyN(lpszExcerpt,cchExcerpt,tch,cchExcerpt); if (pszText) LocalFree(pszText); diff --git a/src/Helpers.c b/src/Helpers.c index 9059932d4..05c85fdf6 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -384,13 +384,13 @@ BOOL SetWindowTitle(HWND hwnd,UINT uIDAppName,BOOL bIsElevated,UINT uIDUntitled, UINT uIDReadOnly,BOOL bReadOnly,LPCWSTR lpszExcerpt) { - WCHAR szUntitled[256] = { L'\0' }; - WCHAR szExcrptQuot[256] = { L'\0' }; + WCHAR szUntitled[MIDSZ_BUFFER] = { L'\0' }; + WCHAR szExcrptQuot[MIDSZ_BUFFER] = { L'\0' }; WCHAR szExcrptFmt[32] = { L'\0' }; - WCHAR szAppName[256] = { L'\0' }; - WCHAR szElevatedAppName[256] = { L'\0' }; + WCHAR szAppName[MIDSZ_BUFFER] = { L'\0' }; + WCHAR szElevatedAppName[MIDSZ_BUFFER] = { L'\0' }; WCHAR szReadOnly[32] = { L'\0' }; - WCHAR szTitle[512] = { L'\0' }; + WCHAR szTitle[LARGE_BUFFER] = { L'\0' }; static WCHAR szCachedFile[MAX_PATH] = { L'\0' }; static WCHAR szCachedDisplayName[MAX_PATH] = { L'\0' }; static const WCHAR *pszSep = L" - "; @@ -405,7 +405,7 @@ BOOL SetWindowTitle(HWND hwnd,UINT uIDAppName,BOOL bIsElevated,UINT uIDUntitled, if (bIsElevated) { FormatString(szElevatedAppName,COUNTOF(szElevatedAppName),IDS_APPTITLE_ELEVATED,szAppName); - StrCpyN(szAppName,szElevatedAppName,COUNTOF(szAppName)); + StringCchCopyN(szAppName,COUNTOF(szAppName),szElevatedAppName,COUNTOF(szElevatedAppName)); } if (bModified) @@ -434,7 +434,7 @@ BOOL SetWindowTitle(HWND hwnd,UINT uIDAppName,BOOL bIsElevated,UINT uIDUntitled, StringCchCat(szTitle,COUNTOF(szTitle),szCachedDisplayName); if (iFormat == 1) { WCHAR tchPath[MAX_PATH] = { L'\0' }; - StrCpyN(tchPath,lpszFile,COUNTOF(tchPath)); + StringCchCopyN(tchPath,COUNTOF(tchPath),lpszFile,lstrlen(lpszFile)); PathRemoveFileSpec(tchPath); StringCchCat(szTitle,COUNTOF(szTitle),L" ["); StringCchCat(szTitle,COUNTOF(szTitle),tchPath); @@ -1491,12 +1491,12 @@ void ExpandEnvironmentStringsEx(LPWSTR lpSrc,DWORD dwSrc) // PathCanonicalizeEx() // // -void PathCanonicalizeEx(LPWSTR lpSrc,int len) +void PathCanonicalizeEx(LPWSTR lpszPath,int len) { - WCHAR szDst[MAX_PATH] = { L'\0' }; + WCHAR szDst[FILE_ARG_BUF] = { L'\0' }; - if (PathCanonicalize(szDst,lpSrc)) - StringCchCopy(lpSrc,len,szDst); + if (PathCanonicalize(szDst,lpszPath)) + StringCchCopy(lpszPath,len,szDst); } @@ -1517,6 +1517,19 @@ DWORD GetLongPathNameEx(LPWSTR lpszPath,DWORD cchBuffer) } +//============================================================================= +// +// NormalizePathEx() +// +// +DWORD NormalizePathEx(LPWSTR lpszPath,int len) +{ + PathCanonicalizeEx(lpszPath,len); + return GetLongPathNameEx(lpszPath,len); +} + + + //============================================================================= // // SHGetFileInfo2() @@ -1532,14 +1545,14 @@ DWORD_PTR SHGetFileInfo2(LPCWSTR pszPath,DWORD dwFileAttributes, DWORD_PTR dw = SHGetFileInfo(pszPath,dwFileAttributes,psfi,cbFileInfo,uFlags); if (lstrlen(psfi->szDisplayName) < lstrlen(PathFindFileName(pszPath))) - StrCatBuff(psfi->szDisplayName,PathFindExtension(pszPath),COUNTOF(psfi->szDisplayName)); + StringCchCat(psfi->szDisplayName,COUNTOF(psfi->szDisplayName),PathFindExtension(pszPath)); return(dw); } else { DWORD_PTR dw = SHGetFileInfo(pszPath,FILE_ATTRIBUTE_NORMAL,psfi,cbFileInfo,uFlags|SHGFI_USEFILEATTRIBUTES); if (lstrlen(psfi->szDisplayName) < lstrlen(PathFindFileName(pszPath))) - StrCatBuff(psfi->szDisplayName,PathFindExtension(pszPath),COUNTOF(psfi->szDisplayName)); + StringCchCat(psfi->szDisplayName,COUNTOF(psfi->szDisplayName),PathFindExtension(pszPath)); return(dw); } @@ -1906,7 +1919,7 @@ BOOL GetThemedDialogFont(LPWSTR lpFaceName,WORD* wSize) *wSize = (WORD)MulDiv(lf.lfHeight,72,iLogPixelsY); if (*wSize == 0) *wSize = 8; - StrCpyN(lpFaceName,lf.lfFaceName,LF_FACESIZE); + StringCchCopyN(lpFaceName,LF_FACESIZE,lf.lfFaceName,LF_FACESIZE); bSucceed = TRUE; } (GetProcAddress(hLocalModUxTheme,"CloseThemeData"))(hTheme); @@ -1924,7 +1937,7 @@ BOOL GetThemedDialogFont(LPWSTR lpFaceName,WORD* wSize) *wSize = (WORD)MulDiv(ncm.lfMessageFont.lfHeight,72,iLogPixelsY); if (*wSize == 0) *wSize = 8; - StrCpyN(lpFaceName,ncm.lfMessageFont.lfFaceName,LF_FACESIZE); + StringCchCopyN(lpFaceName,LF_FACESIZE,ncm.lfMessageFont.lfFaceName,LF_FACESIZE); }*/ return(bSucceed); diff --git a/src/Helpers.h b/src/Helpers.h index 2bb36a973..0cd82a9e6 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -21,19 +21,11 @@ #undef STRSAFE_NO_DEPRECATE #include - -#define SMALL_BUFFER 128 -#define MIDSZ_BUFFER 256 -#define LARGE_BUFFER 512 -#define HUGE_BUFFER 1024 - - #define UNUSED(expr) (void)(expr) #define SIZEOF(ar) sizeof(ar) #define COUNTOF(ar) ARRAYSIZE(ar) //#define COUNTOF(ar) (sizeof(ar)/sizeof(ar[0])) #define CSTRLEN(s) (COUNTOF(s)-1) - extern WCHAR szIniFile[MAX_PATH]; #define IniGetString(lpSection,lpName,lpDefault,lpReturnedStr,nSize) \ @@ -70,6 +62,15 @@ __inline BOOL IniSectionSetInt(LPWSTR lpCachedIniSection,LPCWSTR lpName,int i) { #define IsVista() (g_uWinVer >= 0x0600) #define IsW7() (g_uWinVer >= 0x0601) +enum BufferSizes { + MICRO_BUFFER = 32, + MINI_BUFFER = 64, + SMALL_BUFFER = 128, + MIDSZ_BUFFER = 256, + LARGE_BUFFER = 512, + HUGE_BUFFER = 1024, + FILE_ARG_BUF = MAX_PATH+4 +}; BOOL PrivateIsAppThemed(); HRESULT PrivateSetCurrentProcessExplicitAppUserModelID(PCWSTR); @@ -150,6 +151,7 @@ void PathFixBackslashes(LPWSTR); void ExpandEnvironmentStringsEx(LPWSTR,DWORD); void PathCanonicalizeEx(LPWSTR,int); DWORD GetLongPathNameEx(LPWSTR,DWORD); +DWORD NormalizePathEx(LPWSTR,int); DWORD_PTR SHGetFileInfo2(LPCWSTR,DWORD,SHFILEINFO*,UINT,UINT); diff --git a/src/Notepad3.c b/src/Notepad3.c index 8c1455023..caa206079 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -225,20 +225,20 @@ int cyFavoritesDlg; int xFindReplaceDlg; int yFindReplaceDlg; -LPWSTR lpFileList[32] = { L'\0' }; -int cFileList = 0; -int cchiFileList = 0; -LPWSTR lpFileArg = NULL; -LPWSTR lpSchemeArg = NULL; -LPWSTR lpMatchArg = NULL; -LPWSTR lpEncodingArg = NULL; -LPMRULIST pFileMRU; -LPMRULIST mruFind; -LPMRULIST mruReplace; +LPWSTR lpFileList[32] = { NULL }; +int cFileList = 0; +int cchiFileList = 0; +LPWSTR lpFileArg = NULL; +LPWSTR lpSchemeArg = NULL; +LPWSTR lpMatchArg = NULL; +LPWSTR lpEncodingArg = NULL; +LPMRULIST pFileMRU; +LPMRULIST mruFind; +LPMRULIST mruReplace; DWORD dwLastIOError; -WCHAR szCurFile[MAX_PATH+40] = { L'\0' }; -FILEVARS fvCurFile; +WCHAR szCurFile[FILE_ARG_BUF] = { L'\0' }; +FILEVARS fvCurFile; BOOL bModified; BOOL bReadOnly = FALSE; int iEncoding; @@ -257,7 +257,7 @@ BOOL bLastCopyFromMe = FALSE; DWORD dwLastCopyTime; UINT uidsAppTitle = IDS_APPTITLE; -WCHAR szTitleExcerpt[256] = { L'\0' }; +WCHAR szTitleExcerpt[MIDSZ_BUFFER] = { L'\0' }; int fKeepTitleExcerpt = 0; HANDLE hChangeHandle = NULL; @@ -915,7 +915,7 @@ HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow) } } } - GlobalFree(lpFileArg); + GlobalFree(lpFileArg); lpFileArg = NULL; if (bOpened) { if (flagChangeNotify == 1) { @@ -2510,12 +2510,12 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) } if (lstrlen(tchParam) && lstrlen(szCurFile)) - StrCatBuff(tchParam,L" ",COUNTOF(tchParam)); + StringCchCat(tchParam,COUNTOF(tchParam),L" "); if (lstrlen(szCurFile)) { StringCchCopy(tchTemp,COUNTOF(tchTemp),szCurFile); PathQuoteSpaces(tchTemp); - StrCatBuff(tchParam,tchTemp,COUNTOF(tchParam)); + StringCchCat(tchParam,COUNTOF(tchParam),tchTemp); } SHELLEXECUTEINFO sei = { 0 }; @@ -4947,9 +4947,10 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) HANDLE hData; WCHAR *pData; EmptyClipboard(); - hData = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,sizeof(WCHAR) * (lstrlen(pszCopy) + 1)); + int len = lstrlen(pszCopy); + hData = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,sizeof(WCHAR) * (len+1)); pData = GlobalLock(hData); - StrCpyN(pData,pszCopy,(int)GlobalSize(hData) / sizeof(WCHAR)); + StringCchCopyN(pData,(len+1),pszCopy,len); GlobalUnlock(hData); SetClipboardData(CF_UNICODETEXT,hData); CloseClipboard(); @@ -4979,9 +4980,10 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) HANDLE hData; WCHAR *pData; EmptyClipboard(); - hData = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,sizeof(WCHAR) * (lstrlen(wszWinPos) + 1)); + int len = lstrlen(wszWinPos); + hData = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,sizeof(WCHAR) * (len+1)); pData = GlobalLock(hData); - StrCpyN(pData,wszWinPos,(int)GlobalSize(hData) / sizeof(WCHAR)); + StringCchCopyN(pData,(len+1),wszWinPos,len); GlobalUnlock(hData); SetClipboardData(CF_UNICODETEXT,hData); CloseClipboard(); @@ -6217,14 +6219,15 @@ void ParseCommandLine() // Shell integration else if (StrCmpNI(lp1,L"appid=",CSTRLEN(L"appid=")) == 0) { - StrCpyN(g_wchAppUserModelID,lp1+CSTRLEN(L"appid="),COUNTOF(g_wchAppUserModelID)); + StringCchCopyN(g_wchAppUserModelID,COUNTOF(g_wchAppUserModelID), + lp1 + CSTRLEN(L"appid="),len - CSTRLEN(L"appid=")); StrTrim(g_wchAppUserModelID,L" "); if (lstrlen(g_wchAppUserModelID) == 0) StringCchCopy(g_wchAppUserModelID,COUNTOF(g_wchAppUserModelID),L"Notepad3"); } else if (StrCmpNI(lp1,L"sysmru=",CSTRLEN(L"sysmru=")) == 0) { - WCHAR wch[8]; - StrCpyN(wch,lp1+CSTRLEN(L"sysmru="),COUNTOF(wch)); + WCHAR wch[16]; + StringCchCopyN(wch,COUNTOF(wch),lp1 + CSTRLEN(L"sysmru="),COUNTOF(wch)); StrTrim(wch,L" "); if (*wch == L'1') flagUseSystemMRU = 2; @@ -6257,7 +6260,7 @@ void ParseCommandLine() if (*(lp1+1) == L'0' || *CharUpper(lp1+1) == L'O') StringCchCopy(szIniFile,COUNTOF(szIniFile),L"*?"); else if (ExtractFirstArgument(lp2,lp1,lp2,len)) { - StrCpyN(szIniFile,lp1,COUNTOF(szIniFile)); + StringCchCopyN(szIniFile,COUNTOF(szIniFile),lp1,len); TrimString(szIniFile); PathUnquoteSpaces(szIniFile); } @@ -6348,7 +6351,7 @@ void ParseCommandLine() case L'T': if (ExtractFirstArgument(lp2,lp1,lp2,len)) { - StrCpyN(szTitleExcerpt,lp1,COUNTOF(szTitleExcerpt)); + StringCchCopyN(szTitleExcerpt,COUNTOF(szTitleExcerpt),lp1,len); fKeepTitleExcerpt = 1; } break; @@ -6497,20 +6500,20 @@ void ParseCommandLine() if (lpFileArg) GlobalFree(lpFileArg); - - lpFileArg = GlobalAlloc(GPTR,sizeof(WCHAR)*(MAX_PATH+2)); // changed for ActivatePrevInst() needs - StrCpyN(lpFileArg,lp3,MAX_PATH); + + lpFileArg = GlobalAlloc(GPTR,sizeof(WCHAR)*FILE_ARG_BUF); // changed for ActivatePrevInst() needs + StringCchCopy(lpFileArg,FILE_ARG_BUF,lp3); PathFixBackslashes(lpFileArg); if (!PathIsRelative(lpFileArg) && !PathIsUNC(lpFileArg) && PathGetDriveNumber(lpFileArg) == -1 /*&& PathGetDriveNumber(g_wchWorkingDirectory) != -1*/) { - WCHAR wchPath[MAX_PATH] = { L'\0' }; + WCHAR wchPath[FILE_ARG_BUF] = { L'\0' }; StringCchCopy(wchPath,COUNTOF(wchPath),g_wchWorkingDirectory); PathStripToRoot(wchPath); PathAppend(wchPath,lpFileArg); - StringCchCopy(lpFileArg,COUNTOF(lpFileArg),wchPath); + StringCchCopy(lpFileArg,FILE_ARG_BUF,wchPath); } StrTrim(lpFileArg,L" \""); @@ -6712,10 +6715,8 @@ int FindIniFile() { } } - // normalize path - PathCanonicalizeEx(szIniFile,COUNTOF(szIniFile)); - GetLongPathNameEx(szIniFile,COUNTOF(szIniFile)); - + NormalizePathEx(szIniFile,COUNTOF(szIniFile)); + return(1); } @@ -7211,7 +7212,7 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp ExpandEnvironmentStringsEx(tch,COUNTOF(tch)); if (PathIsRelative(tch)) { - StrCpyN(szFileName,g_wchWorkingDirectory,COUNTOF(szFileName)); + StringCchCopyN(szFileName,COUNTOF(szFileName),g_wchWorkingDirectory,COUNTOF(g_wchWorkingDirectory)); PathAppend(szFileName,tch); if (!PathFileExists(szFileName)) { WCHAR wchFullPath[MAX_PATH] = { L'\0' }; @@ -7223,8 +7224,7 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp else StringCchCopy(szFileName,COUNTOF(szFileName),tch); - PathCanonicalizeEx(szFileName,COUNTOF(szFileName)); - GetLongPathNameEx(szFileName,COUNTOF(szFileName)); + NormalizePathEx(szFileName,COUNTOF(szFileName)); if (PathIsLnkFile(szFileName)) PathGetLnkPath(szFileName,szFileName,COUNTOF(szFileName)); @@ -7641,31 +7641,31 @@ BOOL ActivatePrevInst() if (flagSingleFileInstance && lpFileArg) { // Search working directory from second instance, first! - // lpFileArg is at least MAX_PATH+2 bytes - WCHAR tchTmp[MAX_PATH] = { L'\0' }; + // lpFileArg is at least MAX_PATH+4 WCHARS + WCHAR tchTmp[FILE_ARG_BUF] = { L'\0' }; ExpandEnvironmentStringsEx(lpFileArg,(DWORD)GlobalSize(lpFileArg)/sizeof(WCHAR)); if (PathIsRelative(lpFileArg)) { - StrCpyN(tchTmp,g_wchWorkingDirectory,COUNTOF(tchTmp)); + StringCchCopyN(tchTmp,COUNTOF(tchTmp),g_wchWorkingDirectory,COUNTOF(g_wchWorkingDirectory)); PathAppend(tchTmp,lpFileArg); if (PathFileExists(tchTmp)) - StringCchCopy(lpFileArg,COUNTOF(lpFileArg),tchTmp); + StringCchCopy(lpFileArg,FILE_ARG_BUF,tchTmp); else { if (SearchPath(NULL,lpFileArg,NULL,COUNTOF(tchTmp),tchTmp,NULL)) - StringCchCopy(lpFileArg,COUNTOF(lpFileArg),tchTmp); + StringCchCopy(lpFileArg,FILE_ARG_BUF,tchTmp); else { - StrCpyN(tchTmp,g_wchWorkingDirectory,COUNTOF(tchTmp)); + StringCchCopyN(tchTmp,COUNTOF(tchTmp),g_wchWorkingDirectory,COUNTOF(g_wchWorkingDirectory)); PathAppend(tchTmp,lpFileArg); - StringCchCopy(lpFileArg,COUNTOF(lpFileArg),tchTmp); + StringCchCopy(lpFileArg,FILE_ARG_BUF,tchTmp); } } } else if (SearchPath(NULL,lpFileArg,NULL,COUNTOF(tchTmp),tchTmp,NULL)) - StringCchCopy(lpFileArg,COUNTOF(lpFileArg),tchTmp); + StringCchCopy(lpFileArg,FILE_ARG_BUF,tchTmp); - GetLongPathNameEx(lpFileArg,MAX_PATH); + NormalizePathEx(lpFileArg,FILE_ARG_BUF); EnumWindows(EnumWndProc2,(LPARAM)&hwnd); @@ -7762,8 +7762,8 @@ BOOL ActivatePrevInst() if (lpFileArg) { // Search working directory from second instance, first! - // lpFileArg is at least MAX_PATH+2 bytes - WCHAR tchTmp[MAX_PATH] = { L'\0' }; + // lpFileArg is at least MAX_PATH+4 WCHAR + WCHAR tchTmp[FILE_ARG_BUF] = { L'\0' }; LPnp3params params; DWORD cb = sizeof(np3params); int cchTitleExcerpt; @@ -7771,18 +7771,18 @@ BOOL ActivatePrevInst() ExpandEnvironmentStringsEx(lpFileArg,(DWORD)GlobalSize(lpFileArg)/sizeof(WCHAR)); if (PathIsRelative(lpFileArg)) { - StrCpyN(tchTmp,g_wchWorkingDirectory,COUNTOF(tchTmp)); + StringCchCopyN(tchTmp,COUNTOF(tchTmp),g_wchWorkingDirectory,COUNTOF(g_wchWorkingDirectory)); PathAppend(tchTmp,lpFileArg); if (PathFileExists(tchTmp)) - StringCchCopy(lpFileArg,COUNTOF(lpFileArg),tchTmp); + StringCchCopy(lpFileArg,FILE_ARG_BUF,tchTmp); else { if (SearchPath(NULL,lpFileArg,NULL,COUNTOF(tchTmp),tchTmp,NULL)) - StringCchCopy(lpFileArg,COUNTOF(lpFileArg),tchTmp); + StringCchCopy(lpFileArg,FILE_ARG_BUF,tchTmp); } } else if (SearchPath(NULL,lpFileArg,NULL,COUNTOF(tchTmp),tchTmp,NULL)) - StringCchCopy(lpFileArg,COUNTOF(lpFileArg),tchTmp); + StringCchCopy(lpFileArg,FILE_ARG_BUF,tchTmp); cb += (lstrlen(lpFileArg) + 1) * sizeof(WCHAR); @@ -7825,8 +7825,8 @@ BOOL ActivatePrevInst() cds.lpData = params; SendMessage(hwnd,WM_COPYDATA,(WPARAM)NULL,(LPARAM)&cds); - GlobalFree(params); - GlobalFree(lpFileArg); + GlobalFree(params); params = NULL; + GlobalFree(lpFileArg); lpFileArg = NULL; } return(TRUE); } @@ -7890,7 +7890,7 @@ BOOL RelaunchMultiInst() { LocalFree(lpCmdLineNew); LocalFree(lp1); LocalFree(lp2); - GlobalFree(lpFileArg); + GlobalFree(lpFileArg); lpFileArg = NULL; return TRUE; }