@@ -38,10 +38,14 @@ STGMEDIUM medium;
3838HRESULT hres = 0 ;
3939UINT cbFiles = 0 ;
4040
41+ /* The buffers size used to be MAX_PATH (256 bytes), but that's not always
42+ * enough */
43+ #define BUFSIZE 1100
44+
4145//
4246// Get the name of the Gvim executable to use, with the path.
4347// When "runtime" is non-zero, we were called to find the runtime directory.
44- // Returns the path in name[MAX_PATH ]. It's empty when it fails.
48+ // Returns the path in name[BUFSIZE ]. It's empty when it fails.
4549//
4650 static void
4751getGvimName (char *name, int runtime)
@@ -54,7 +58,7 @@ getGvimName(char *name, int runtime)
5458 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, " Software\\ Vim\\ Gvim" , 0 ,
5559 KEY_READ, &keyhandle) == ERROR_SUCCESS)
5660 {
57- hlen = MAX_PATH ;
61+ hlen = BUFSIZE ;
5862 if (RegQueryValueEx (keyhandle, " path" , 0 , NULL , (BYTE *)name, &hlen)
5963 != ERROR_SUCCESS)
6064 name[0 ] = 0 ;
@@ -82,7 +86,7 @@ getGvimName(char *name, int runtime)
8286}
8387
8488//
85- // Get the Vim runtime directory into buf[MAX_PATH ].
89+ // Get the Vim runtime directory into buf[BUFSIZE ].
8690// The result is empty when it failed.
8791// When it works, the path ends in a slash or backslash.
8892//
@@ -218,8 +222,8 @@ null_libintl_textdomain(const char* domainname)
218222 static void
219223dyn_gettext_load (void )
220224{
221- char szBuff[MAX_PATH ];
222- char szLang[MAX_PATH ];
225+ char szBuff[BUFSIZE ];
226+ char szLang[BUFSIZE ];
223227 DWORD len;
224228 HKEY keyhandle;
225229 int gotlang = 0 ;
@@ -231,7 +235,7 @@ dyn_gettext_load(void)
231235 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, " Software\\ Vim\\ Gvim" , 0 ,
232236 KEY_READ, &keyhandle) == ERROR_SUCCESS)
233237 {
234- len = MAX_PATH ;
238+ len = BUFSIZE ;
235239 if (RegQueryValueEx (keyhandle, " lang" , 0 , NULL , (BYTE*)szBuff, &len)
236240 == ERROR_SUCCESS)
237241 {
@@ -249,7 +253,7 @@ dyn_gettext_load(void)
249253 // LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
250254 // only the first two.
251255 len = GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
252- (LPTSTR)szBuff, MAX_PATH );
256+ (LPTSTR)szBuff, BUFSIZE );
253257 if (len >= 2 && _strnicmp (szBuff, " en" , 2 ) != 0 )
254258 {
255259 // There are a few exceptions (probably more)
@@ -615,11 +619,11 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
615619 // Now display all the vim instances
616620 for (int i = 0 ; i < m_cntOfHWnd; i++)
617621 {
618- char title[MAX_PATH ];
619- char temp[MAX_PATH ];
622+ char title[BUFSIZE ];
623+ char temp[BUFSIZE ];
620624
621625 // Obtain window title, continue if can not
622- if (GetWindowText (m_hWnd[i], title, MAX_PATH - 1 ) == 0 )
626+ if (GetWindowText (m_hWnd[i], title, BUFSIZE - 1 ) == 0 )
623627 continue ;
624628 // Truncate the title before the path, keep the file name
625629 char *pos = strchr (title, ' (' );
@@ -630,8 +634,8 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
630634 *pos = 0 ;
631635 }
632636 // Now concatenate
633- strncpy (temp, _ (" Edit with existing Vim - " ), MAX_PATH - 1 );
634- strncat (temp, title, MAX_PATH - 1 );
637+ strncpy (temp, _ (" Edit with existing Vim - " ), BUFSIZE - 1 );
638+ strncat (temp, title, BUFSIZE - 1 );
635639 InsertMenu (hMenu,
636640 indexMenu++,
637641 MF_STRING|MF_BYPOSITION,
@@ -750,7 +754,7 @@ STDMETHODIMP CShellExt::GetCommandString(UINT idCmd,
750754
751755BOOL CALLBACK CShellExt::EnumWindowsProc (HWND hWnd, LPARAM lParam)
752756{
753- char temp[MAX_PATH ];
757+ char temp[BUFSIZE ];
754758
755759 // First do a bunch of check
756760 // No invisible window
@@ -807,21 +811,21 @@ PlatformId(void)
807811 static char *
808812searchpath (char *name)
809813{
810- static char widename[2 * MAX_PATH ];
811- static char location[2 * MAX_PATH + 2 ];
814+ static char widename[2 * BUFSIZE ];
815+ static char location[2 * BUFSIZE + 2 ];
812816
813817 // There appears to be a bug in FindExecutableA() on Windows NT.
814818 // Use FindExecutableW() instead...
815819 PlatformId ();
816820 if (g_PlatformId == VER_PLATFORM_WIN32_NT)
817821 {
818822 MultiByteToWideChar (CP_ACP, 0 , (LPCTSTR)name, -1 ,
819- (LPWSTR)widename, MAX_PATH );
823+ (LPWSTR)widename, BUFSIZE );
820824 if (FindExecutableW ((LPCWSTR)widename, (LPCWSTR)" " ,
821825 (LPWSTR)location) > (HINSTANCE)32 )
822826 {
823827 WideCharToMultiByte (CP_ACP, 0 , (LPWSTR)location, -1 ,
824- (LPSTR)widename, 2 * MAX_PATH , NULL , NULL );
828+ (LPSTR)widename, 2 * BUFSIZE , NULL , NULL );
825829 return widename;
826830 }
827831 }
@@ -842,8 +846,8 @@ STDMETHODIMP CShellExt::InvokeGvim(HWND hParent,
842846 LPCSTR pszParam,
843847 int iShowCmd)
844848{
845- char m_szFileUserClickedOn[MAX_PATH ];
846- char cmdStr[MAX_PATH ];
849+ char m_szFileUserClickedOn[BUFSIZE ];
850+ char cmdStr[BUFSIZE ];
847851 UINT i;
848852
849853 for (i = 0 ; i < cbFiles; i++)
@@ -856,7 +860,7 @@ STDMETHODIMP CShellExt::InvokeGvim(HWND hParent,
856860 getGvimName (cmdStr, 0 );
857861 strcat (cmdStr, " \" " );
858862
859- if ((strlen (cmdStr) + strlen (m_szFileUserClickedOn) + 2 ) < MAX_PATH )
863+ if ((strlen (cmdStr) + strlen (m_szFileUserClickedOn) + 2 ) < BUFSIZE )
860864 {
861865 strcat (cmdStr, m_szFileUserClickedOn);
862866 strcat (cmdStr, " \" " );
@@ -913,13 +917,13 @@ STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent,
913917 int iShowCmd,
914918 int useDiff)
915919{
916- char m_szFileUserClickedOn[MAX_PATH ];
920+ char m_szFileUserClickedOn[BUFSIZE ];
917921 char *cmdStr;
918922 size_t cmdlen;
919923 size_t len;
920924 UINT i;
921925
922- cmdlen = MAX_PATH ;
926+ cmdlen = BUFSIZE ;
923927 cmdStr = (char *)malloc (cmdlen);
924928 getGvimName (cmdStr, 0 );
925929 if (useDiff)
@@ -934,7 +938,7 @@ STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent,
934938 len = strlen (cmdStr) + strlen (m_szFileUserClickedOn) + 4 ;
935939 if (len > cmdlen)
936940 {
937- cmdlen = len + MAX_PATH ;
941+ cmdlen = len + BUFSIZE ;
938942 cmdStr = (char *)realloc (cmdStr, cmdlen);
939943 }
940944 strcat (cmdStr, " \" " );
0 commit comments