#ifdef FEAT_GUI_MSWIN
static int s_dont_use_vimrun = TRUE;
static int need_vimrun_warning = FALSE;
-static char *vimrun_path = "vimrun ";
+static string_T vimrun_path = {(char_u *)"vimrun ", 7};
+static int vimrun_path_allocated = FALSE;
#endif
static int win32_getattrs(char_u *name);
Rows = 25;
Columns = 80;
- // Look for 'vimrun'
+ // Look for 'vimrun'.
{
- char_u vimrun_location[_MAX_PATH + 4];
+ char_u vimrun_location[_MAX_PATH + 4];
+ size_t exe_pathlen = (size_t)(gettail(exe_name) - exe_name);
- // First try in same directory as gvim.exe
- STRCPY(vimrun_location, exe_name);
- STRCPY(gettail(vimrun_location), "vimrun.exe");
- if (mch_getperm(vimrun_location) >= 0)
+ // Note: 10 is length of 'vimrun.exe'.
+ if (exe_pathlen + 10 >= sizeof(vimrun_location))
{
- char *p;
+ if (executable_exists("vimrun.exe", NULL, TRUE, FALSE))
+ s_dont_use_vimrun = FALSE;
+ }
+ else
+ {
+ // First try in same directory as gvim.exe.
+ if (exe_pathlen > 0)
+ vim_strncpy(vimrun_location, exe_name, exe_pathlen);
+ STRCPY(vimrun_location + exe_pathlen, "vimrun.exe");
- if (*skiptowhite(vimrun_location) != NUL)
+ if (mch_getperm(vimrun_location) >= 0)
{
- // Enclose path with white space in double quotes.
- mch_memmove(vimrun_location + 1, vimrun_location,
- STRLEN(vimrun_location) + 1);
- *vimrun_location = '"';
- STRCPY(gettail(vimrun_location), "vimrun\" ");
- }
- else
- STRCPY(gettail(vimrun_location), "vimrun ");
+ char_u *p;
+ size_t plen;
- p = (char *)vim_strsave(vimrun_location);
- if (p != NULL)
- {
- vimrun_path = p;
- s_dont_use_vimrun = FALSE;
+ if (exe_pathlen > 0 && *skiptowhite(vimrun_location) != NUL)
+ {
+ // Enclose path with white space in double quotes.
+ plen = vim_snprintf_safelen(
+ (char *)vimrun_location,
+ sizeof(vimrun_location),
+ "\"%.*svimrun\" ",
+ (int)exe_pathlen, exe_name);
+ }
+ else
+ {
+ // Remove the suffix ('.exe').
+ vimrun_location[exe_pathlen + 6] = ' ';
+ vimrun_location[exe_pathlen + 7] = NUL;
+ plen = exe_pathlen + 7;
+ }
+
+ p = vim_strnsave(vimrun_location, plen);
+ if (p != NULL)
+ {
+ vimrun_path.string = p;
+ vimrun_path.length = plen;
+ vimrun_path_allocated = TRUE;
+ s_dont_use_vimrun = FALSE;
+ }
}
+ else if (executable_exists("vimrun.exe", NULL, TRUE, FALSE))
+ s_dont_use_vimrun = FALSE;
}
- else if (executable_exists("vimrun.exe", NULL, TRUE, FALSE))
- s_dont_use_vimrun = FALSE;
// Don't give the warning for a missing vimrun.exe right now, but only
// when vimrun was supposed to be used. Don't bother people that do
}
/*
- * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'.
+ * If "findstr.exe" doesn't exist, use "grep -n" for 'grepprg'.
* Otherwise the default "findstr /n" is used.
*/
if (!executable_exists("findstr.exe", NULL, TRUE, FALSE))
#endif
#ifdef VIMDLL
+ if (vimrun_path_allocated)
+ vim_free(vimrun_path.string);
+
if (gui.in_use || gui.starting)
mch_exit_g(r);
else
mch_exit_c(r);
#elif defined(FEAT_GUI_MSWIN)
+ if (vimrun_path_allocated)
+ vim_free(vimrun_path.string);
mch_exit_g(r);
#else
mch_exit_c(r);
char_u *name,
int len)
{
- int flen;
WCHAR *p;
WCHAR buf[_MAX_PATH + 1];
- flen = (int)STRLEN(name);
- if (flen == 0)
+ if (*name == NUL)
return;
slash_adjust(name);
if (q != NULL)
{
- if (len > 0 || flen >= (int)STRLEN(q))
- vim_strncpy(name, q, (len > 0) ? len - 1 : flen);
+ if (len > 0)
+ vim_strncpy(name, q, len - 1);
+ else
+ {
+ size_t namelen = STRLEN(name);
+ if (namelen >= STRLEN(q))
+ vim_strncpy(name, q, namelen);
+ }
+
vim_free(q);
}
}
#ifdef FEAT_GUI_MSWIN
((gui.in_use || gui.starting) ?
(!s_dont_use_vimrun && p_stmp ?
- STRLEN(vimrun_path) : STRLEN(p_sh) + STRLEN(p_shcf))
+ vimrun_path.length : STRLEN(p_sh) + STRLEN(p_shcf))
: 0) +
#endif
STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10;
// Use vimrun to execute the command. It opens a console
// window, which can be closed without killing Vim.
vim_snprintf((char *)newcmd, cmdlen, "%s%s%s %s %s",
- vimrun_path,
+ vimrun_path.string,
(msg_silent != 0 || (options & SHELL_DOOUT))
? "-s " : "",
p_sh, p_shcf, cmd);
if (fromf == NULL || tof == NULL)
goto theend;
STRCPY(fromf, "\\??\\");
- STRCAT(fromf, from);
+ STRCPY(fromf + STRLEN_LITERAL("\\??\\"), from);
STRCPY(tof, "\\??\\");
- STRCAT(tof, to);
+ STRCPY(tof + STRLEN_LITERAL("\\??\\"), to);
// Convert the names to wide characters.
fromw = enc_to_utf16(fromf, NULL);